Archived

This topic is now archived and is closed to further replies.

tieTYT

Translating the scene changes collision detection

Recommended Posts

Ok, i''m using the 3DMath.cpp file from the www.gametutorials.com website. The link is here http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg3.htm and the tutorial is called Line Segment and Polygon Collision. I need this question answered or else it will be really hard to debug my program: Do the 3DMath.cpp functions make any types of assumptions about the world such that if i were to translate my world before using them, they would not work as expected? The symptoms of my problem are after i translate, collision detection seems to move off the actual object.

Share this post


Link to post
Share on other sites
If you translate the entire world it should be fine, however if you translate different objects different amounts using the glTranslate function then it will go wrong.

Share this post


Link to post
Share on other sites
quote:
Original post by Monder
If you translate the entire world it should be fine, however if you translate different objects different amounts using the glTranslate function then it will go wrong.


are you sure, because that''s exactly what i already do (without translating the world) and it works perfectly for me. But when i add translating the entire world along with this, i get the problems i mentioned above.

Would you mind explaining why it is that "If ... you translate different objects different amounts using the glTranslate function then it will go wrong"?

Share this post


Link to post
Share on other sites
If you translate them different amounts then they''ll be in different positions relative to each other and the collision code will not know this (unless you alter the data you give the collision functions to account for the translation).

When you translate the entire world at what point are you doing the translation? You should call glTranslate before you do any drawing and if you want to do futher things that alter the modelview matrix such as glRotate and glTranslate then call glPush before them, draw whatever stuff you want to draw that you want the transform to affect and then call glPop.

Share this post


Link to post
Share on other sites
quote:
Original post by Monder
If you translate them different amounts then they'll be in different positions relative to each other and the collision code will not know this (unless you alter the data you give the collision functions to account for the translation).

When you translate the entire world at what point are you doing the translation? You should call glTranslate before you do any drawing and if you want to do futher things that alter the modelview matrix such as glRotate and glTranslate then call glPush before them, draw whatever stuff you want to draw that you want the transform to affect and then call glPop.


I use 3DMath.cpp to calculate if i have clicked on an object or not. This is all i use it for. Each object knows where it is translated and each object pushes the matrix without calling loadidentity, draws itself, then pops it. After it draws itself but before it pops the matrix, i go through a for loop that goes through an array of vertices and multiplies the current MV matrix by these vertices. These vertices have no affect on drawing and have no affect on the shape but are used to pass into the 3DMath.cpp functions as the poly[] param so the functions know where each shape "really" is in space instead of where it's drawn at the origin.

Now everything that i've just mentioned works perfectly for me. You can have 3 cubes next to each other at a depth of -500 and it is easy to pick between them. BUT, if i put the line glTranslatef(-4, 0, 0); right before i draw anything, it places every object to the left but it only thinks i've clicked on an object when i click somewhere to the left of the object. Any explanation why that would happen?

PS: should i post my code?

[edited by - tieTYT on March 21, 2004 3:02:43 PM]

Share this post


Link to post
Share on other sites
Ahhh if you're using the libary for detecting where you click on things then translating the world will make a difference How exactly do you work out what you've clicked on from the mouse coordinates you get?

[edit]Posting your code may be a good idea

[edited by - Monder on March 21, 2004 4:09:36 PM]

Share this post


Link to post
Share on other sites
oh, i figured it out. I wasn''t popping/loadingidentity at the end of my display function. This fixed the problem and i think i know why, thanks a lot.

Share this post


Link to post
Share on other sites