How can I get the current object position

Can someone help me,

I have a problem when I try to get the origin of an object in world space coordinates.

For example I have a sphere wich moves along Y axis, parallel to it (x = 0, z = 0, Z means UP, Y means DEPTH)

The projection is perspective :
gluPerspective(70.0, (float)w / (float) h, 0.08, 4.0);

Camera position is defined as follows:
gluLookAt(0.0, -0.2, 0.25, 0.0, 0.3, 0.0, 0.0, 0.0, 1.0);

I get the sphere’s center location using the following code :
glGetDoublev (GL_MODELVIEW_MATRIX, modelviewMatrix);

x = modelviewMatrix[12];
y = modelviewMatrix[13];
z = modelviewMatrix[14];

When the sphere’s center Y value becomes less then 0, Z value of the sphere’s center starts to decrease. Nevertheless the sphere continues to move parallel to the Y axis.

The problem is why Z value changes ?

Another point is when I change the position of the camera (Z value) I receive different values for x,y and z, despite the object location is the same.

Regards!

Originally posted by <himchev>:
[b]
x = modelviewMatrix[12];
y = modelviewMatrix[13];
z = modelviewMatrix[14];

When the sphere’s center Y value becomes less then 0, Z value of the sphere’s center starts to decrease. Nevertheless the sphere continues to move parallel to the Y axis.

The problem is why Z value changes ?
[/b]/quote]

Well, I am not sure but I think that you are simply taking wrong elements of modelviewMatrix. Check it out. If that doesn’t help, try to use ortographic projection and see if Z keeps changing.

[quote]
Another point is when I change the position of the camera (Z value) I receive different values for x,y and z, despite the object location is the same.
The modelview matrix represent your ‘camera’ not the object’s coordinates (IMHO, of course).

See ya’

NOTE : the layout of the previous post has been accidentally screwd up. :stuck_out_tongue:

The modelview represents the concatenation of both the camera and the object matrices. The translation triplet from the modelview will produce the eyespace coordinate of the object space origin. There is no independent view & model matrix stored by OpenGL, conceptually the view matrix exists on the modelview matrix when the model matrix is identity. If the view matrix were identity then the model matrix would exist on the modelview stack. If you want the model matrix from the modelview you’d have to multiply it by the inverse view matrix.

Thanks a lot dorbie,

I think I’ve got it.
It’s still called ‘MODELVIEW’ matrix and I should get only the ‘MODEL’ part from it.
I’ve missed out on this.