Retrieving new object coordinates after translation/rotation

Apprentice
Posts: 7
Joined: 2008.04
Post: #1
Hello!

I have a plane loaded in from 3ds max, i have performed many translations / rotations on it. However i'm now adding collision detection and having great difficulty getting the exact coordinates of the plane.

I've tried keeping track using an x,y and z variable however it doesn't seem work 100% after a rotation.

I remember having a lecture at uni on this problem; but i appear to have lost my notes Cry

Hopefully someone reading will have a suggestion..

Thanks for reading!

Chris
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
What probably would most convenient is to keep track of your object's position and orientation with a vector and a quaternion. Given how you phrased "performed many translations / rotations on it", it sounds like you're just letting transforms accumulate in the modelview matrix across frames. Instead, what you'll probably want is to call glLoadIdintity and do your transformations from scratch for each object every time you draw. Then, when you want to get information about current position and orientation in your code, you can simply multiply by the orientation quaternion and add the position vector.

If you need more information about quaternions, look here: http://www.sacredsoftware.net/tutorials/...ions.xhtml
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2008.04
Post: #3
Thanks alot, i never used quaternions before but will look into it Smile

I'm using push and pop around the movements of the plane, sorry i should have mentioned that before.

I did find something on this problem, not sure exactly how to implement it but it might be useful:

9.120 How do I find the coordinates of a vertex transformed only by the ModelView matrix?

It's often useful to obtain the eye coordinate space value of a vertex (i.e., the object space vertex transformed by the ModelView matrix). You can obtain this by retrieving the current ModelView matrix and performing simple vector / matrix multiplication.

Thanks again,
Chris
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
That's another way to do it. You can retrieve the modelview matrix with glGetFloatv(GL_MODELVIEW), and multiply a vector by it as demonstrated here (see "Multiplying Vectors"): http://www.sacredsoftware.net/tutorials/...ices.xhtml
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2008.04
Post: #5
Thankyou so much for that! i really do appreciate it!

It's now working Grin I did look at that quaternion idea however i would have had to change alot of my code so i implemented a method using that Matrices tutorial, which i have to say was better than i found.

Ive included a screenshot, which shows a wireframe sphere for my bounding sphere collision detection (i displayed the sphere so i can see where the point is) and thanks to you, the sphere stays with the plane lol.

To view the image copy and paste the link, it doesnt like hotlinking Sad
[Image: screenshot.jpg]

Thanks again Smile

Chris
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  openal coordinates vs. opengl coordinates gerald 1 6,202 Feb 3, 2011 10:04 PM
Last Post: OneSadCookie
  OpenGl rotation/translation problems? wyrmmage 2 4,513 Jan 6, 2008 01:58 PM
Last Post: wyrmmage
  Getting Current Translation And Rotation In OpenGL Nick 3 3,689 Jul 26, 2006 11:16 AM
Last Post: kelvin
  Object position after rotation charon 11 6,888 Mar 2, 2005 11:33 AM
Last Post: hangt5
  Quaternion rotation -> OpenGL rotation matrix? DJBlufire 3 3,976 Sep 6, 2003 08:34 PM
Last Post: MattDiamond