Advertisement

Finding a position

Started by February 09, 2005 04:34 PM
5 comments, last by leggyguy 19 years, 7 months ago
Hi. Is there any way to find the world coordinates of an item which is being position through push and pop matrixes? Here is my problem: I have a ship, which is controllable by the player. The ship has a position (3 x floats), and is rotated around as required:

glpushmatrix ()

gltranslate (shippos.x, shippos.y, shippos.z)
glrotate (shiprotation, 0, 1, 0);
glrotate (shipsroll, 1, 0, 0);  //the ship tilts as it turns
Drawship ();  //draw a 3d model in place

glpushmatrix ();
gltranslate (10.0f, 0.0f, 4.0f); //move to where the gun is on the ship body
                                 //I need to find this point in world space
DrawGun ();  //draw a gun
glpopmatrix ();

glpopmatrix();
Anyone know if there is a way for me to find this gun's position in world coordinates? I can find it in a complicated way, but I am wondering if their is a simple way that I have overlooked? Thanks for any help.
You need object transformation matrix and extract position from there. You either have to grab that matrix from opengl or build it yourself (I sugest this).
You should never let your fears become the boundaries of your dreams.
Advertisement
I don't suppose anyone would know a link to a tut on this subjext would they, or any relevant documents that would help.

I have not used object transformation matrix, and have no idea how to extract the position from it.
Matrix FAQ should be helpful.
You should never let your fears become the boundaries of your dreams.
Thanks for that.

I know how to to matrix sums, but what sums do I need to do to turn the matrix that is held for the objects translation and rotations into world coordinates.

And how do I do that using OPenGL.

You would actually use matrix multiplication, to get the world coordinates of something you would multiply the object's coordinates by the model's transformation matrix.

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
Advertisement
Could you give me an example in code of how I would do what you suggest?

I have tried it, but so far not got it to work.

I know it is asking you to put some time in, and that isn't really fair, but I am completely lost with this.

This topic is closed to new replies.

Advertisement