Translating the scene changes collision detection

Started by
5 comments, last by tieTYT 20 years ago
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.
Advertisement
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.
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"?
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.
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]
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]
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.

This topic is closed to new replies.

Advertisement