|
From: Damian M. <da...@es...> - 2002-04-12 07:14:39
|
We are trying to use OpenGL to do some crude Collision Detection.
This might be such a good idea but hear me out ...
The idea is that when we attempt to move in a direction, we want
to pick those polygons under the cursor position. As long as we
collide with anything on this movement, we retain where the first
polygon where we will have an impact. The next time we move, as
long as we haven't changed direction by changing the viewport or
moving off course, or probably a few other conditions, we don't
need to check for collision.
GLint selectBuf[SOMELARGESIZE];
glLoadName(name); = { glPopName(); glPushName(name); }
glSelectBuffer(BUFSIZE, selectBuf)
glRenderMode(GL_SELECT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glGetIntergerv(GL_VIEWPORT, viewport);
// use a 5 by 5 box (say)
pickX = pickY = 5;
gluPickMatrix(cursorX, viewport[3]-cursorY, pickX, pickY, viewport);
// Do we need to reset the perspective here
glMatrixMode(GL_MODELVIEW);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
hits = glRenderMode(GL_RENDER);
if (hits != 0)
{
// go through the selectBuf
// and find polygon with nearest Z
// Now this will return us the name of the hit objects
// how do we go from the name of the hit object to
// to the actual VRML structure so we can find out
// its actual position is space
}
Alternatively, what rudiments of Collision detection are available in the
existing code and has anybody got any notes/ideas on the directions we
should go to implement a first-attempt home-grown solution.
Thanks - Damian
Pacific Engineering Systems International, 22/8 Campbell St, Artarmon NSW 2064
Ph:+61-2-99063377 .. Fx:+61-2-99063468 | unsolicited email not wanted here !
Views and opinions here are mine and not those of any past or present employer
|