Sign in to follow this  
leggyguy

Finding a position

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this