# Finding a position

This topic is 4900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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).

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631707
• Total Posts
3001836
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!