Hierarchy, gluProject and collision detection

Post: #1
I'm starting a new job in January, and I am working on a project to pass the time. I've been teaching myself how to use OpenGL with some success, but I've come against a wall.

I am trying to simulate a particle-based deformable object. The deformation itself is working as expected, but I am having some trouble with collision detection of the deformed object against solid objects (a cube for now). I know that the source of the problem lies in the fact that the objects that are colliding are hierarchically modeled, so they use different transformation matrices. I tried to get around that by calling gluProject against a particle that I know is colliding with the solid cube, but gluProject gave me nonsensical window coordinates.

Here is the code that I use to call gluProject. coords is a 2D array containing 3D coordinates for each particle.
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLdouble winX, winY, winZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );

After this call, I output the result. The window coordinates that this provides are always off, sometimes by several hundred pixels.

So I have two questions. First, why is gluProject not giving me what I think it should (correct window coordinates)? Second, is there a better way of comparing the two coordinate systems?
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #2
I guess I'm not sure what you are trying to accomplish. If you have one 3D object(the cube) and another 3D object (the deformable mesh), and you want to find out where they collide, why do you need window coordinates?
Quote this message in a reply
Post: #3
Sorry, I skipped a step in my explanation. The idea is to project the particle to the window, then the window to the cube. I don't know the proper method for converting the coordinates of one object to the coordinate system of the other when both are in arbitrary positions on a hierarchical model.
Quote this message in a reply
Post: #4
After looking at this for a while, I think I have found a better solution to my original problem. I think I should be able to use the projection matrix to convert between two projections. (I probably should have thought of that first, but I'm still acquainting myself with OpenGL's matrices.)

I am still curious about the reason for gluProject's inaccuracy. gluUnproject works fine for me, so I can't imagine what I could have done wrong for such a similar function.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Two gluProject points? mikey 5 7,916 Jan 5, 2012 01:03 PM
Last Post: mikey
  Image Hierarchy in Interface Builder sritchie09 2 4,309 Jul 8, 2009 05:22 PM
Last Post: sritchie09
  2D Pixel Collision Detection using OCCLUSION Elphaba 0 4,295 Jun 8, 2009 06:30 AM
Last Post: Elphaba
  the best way to do collision detection ghettotek 26 17,096 Jun 4, 2009 02:30 PM
Last Post: AnotherJake
  gluProject <-> gluUnproject help please szgezu 9 11,476 Feb 26, 2006 11:50 AM
Last Post: szgezu