Regarding concave collision detection (Chap 10 RTCD)[SOLVED]

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
mobeen
Posts: 122
Joined: Thu May 05, 2011 11:47 am

Regarding concave collision detection (Chap 10 RTCD)[SOLVED]

Post by mobeen »

Hi all,

I am reading chapter 10 of book (realtime collision detection by Christer Ericson). The GPU collision chapter first gives Convex collision detection code snippet. I implemented it in OpenGL as given in Table 10.1 and it works as advertised. I then followed suit with the concave collision detection based on the information given on page 422 in Table 10.2. But since the information about hardware occlusion query is not detailed enough, I could not get it to work. So far I have implemented it as follows.

Code: Select all

...check the reply below
I colour my objects green on collision to see if it works. for this demo, as soon as the two objects collide, i get flickering since we might have even and odd number of occlusion samples. My question is has anybody implemented this code snippet as given in Table 10.2 before?

Please don't suggest me to look out for alternative solutions (I know there are better solutions) rather than trying this. I am really surprised at why the book does not include workable demos. It only contains code snippets which one can easily copy from the book.

Thanks,
Mobeen
Last edited by mobeen on Tue Aug 12, 2014 11:33 am, edited 2 times in total.
mobeen
Posts: 122
Joined: Thu May 05, 2011 11:47 am

Re: Regarding concave collision detection (Chap 10 RTCD)

Post by mobeen »

OK guys as usual. After posting question on the forum I get an answer. The following code works for me and I get the correct results now.

Code: Select all

bool ConcaveCollision() {

	//clear depth and stencil buffers
	glClearDepth(1.0f);
	glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	//disable color writes
	glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); 

	//enable depth buffer writes and set depth test to always pass
	glDepthFunc(GL_ALWAYS);
	glDepthMask(GL_TRUE);

	//render the first object edges
	glDisable(GL_STENCIL_TEST);
	 
	//draw edges of object B
	glDisable(GL_CULL_FACE);
	glPushAttrib(GL_POLYGON_BIT);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	 	DrawObjectB(false); 
	glPopAttrib();

	//set the depth function to less and disable depth buffer writes
	glDepthFunc(GL_LESS);
	glDepthMask(GL_FALSE);
	  
	glEnable(GL_STENCIL_TEST);
	glEnable(GL_CULL_FACE); 	 	 
	
	//set stencil test to increment the value and cull the back faces to render front faces only
	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 

	glCullFace(GL_BACK);

		//draw object A
		DrawObjectA(false);
	
	//set stencil test to decrement the value and cull the front faces to render back faces only
	glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
	glCullFace(GL_FRONT); 
	  
	glDepthFunc(GL_GREATER);

	//issue a hardware query to see how many samples passed
	glBeginQuery(GL_SAMPLES_PASSED, query);

		//draw object A
		DrawObjectA(false);

	glEndQuery(GL_SAMPLES_PASSED);  
	glGetQueryObjectuiv(query,  GL_QUERY_RESULT, &numSamplesRendered);

	s.str("");
	s << "Samples occluding: " << numSamplesRendered ;
	
	if(numSamplesRendered==0 )
		return false; 

	return true;
}
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Re: Regarding concave collision detection (Chap 10 RTCD)[SOL

Post by DevO »

"Real-Time Collision Detection" is one of my favorite books in this field.
Do some one know other books like this one ?
Post Reply