Finding point after glTranslated and rotated


I am using glTranslated and glRotated to modify the position of my objects, example below.

//camera location angle
glRotated(m_angle.x, 1.0, 0.0, 0.0);
glRotated(m_angle.y, 0.0, 1.0, 0.0);
glRotated(m_angle.z, 0.0, 0.0, 1.0);
glTranslated(m_trans.x, m_trans.y, m_trans.z);

	loop for all objects


		glRotated(object.angle.x, 1.0, 0.0, 0.0);
		glRotated(object.angle.y, 0.0, 1.0, 0.0);
		glRotated(object.angle.z, 0.0, 0.0, 1.0);
		glTranslated(object.position.x, object.position.y, object.position.z);


I use this method instead of calculating all the point locations myself which looks like a nightmare.

Now I want to find the proper locations of my points after the rotation and translations so I can collision test the points.
Can I get the positions out of the matrix and use that to calculate the points or do I have to make some complicated formulas to work these out.

Hope this makes sense.


Retrieve the current transform matrix and multiply it by your points original position.

Thanks gavin

I’m slowly getting there.

I have just read something similar for frustum culling.

I found

float proj[16];
float modl[16];
float clip[16]

/* Get the current PROJECTION matrix from OpenGL */
glGetFloatv( GL_PROJECTION_MATRIX, proj );

/* Get the current MODELVIEW matrix from OpenGL */
glGetFloatv( GL_MODELVIEW_MATRIX, modl );

Do I have to multiply the two matrices i.e.
clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];

and then times the result by my points to get the real position or can I ignore the clip bit?

The matrices contain 16 values! How do I use my points against these 16 values to get the position?

Thanks in advance.

[This message has been edited by Pops (edited 06-11-2002).]

" Retrieve the current transform matrix and multiply it by your points original position. "

how can you Retrieve modified matrix of an Object after you performed glTranslate(), glRotate on it ???

Also I did not work with this yet too much, but Every time I used glRotate() on my object, it rotated with respect to Global Axis, and not its own… This is what I did


Before in one of the topics someone stated to Rotate the world around you object, but I don’t like the idea…

I believe the order in which you make the transformation determines the axis it rotates around.
If you rotate then translate it will rotate around its own axis.
If you translate then rotate it will rotate around the position before the translation.
(Could be the other way round!!!)

I believe you can get the matrix after the rotation and translation by doing what I have above i.e. glGetFloatv(matrix_name, where_you_want_to_put_the_data);

I haven’t done collision detection but I can;t see why the projection matrix would be used, surely 2 points will collide in space wherever you are looking at them from?
Oh and about the global axis it depends on if youre object is cenered at the global centre and then translated/rotated it should do so about its axis. As opposed to drawing so its centre is not at the centre globally and then rotating.

I think you only have to use the projection matrix in my example above to find the viewing area boundaries (frustum I believe). I was interested in this because I wanted to do some frustum culling.
For collision detection I think I only need the model view matrix.
I still am not sure how you use the 16 values from the matrix to find the real position of the points. That’s the main thing I’m interested in.

should help with the matrix transformations stuff etc.

Thanks Gavin.

I had a look at the PDF’s on the link you sent, some pretty heavy maths and stuff there.

I didn’t get time to read the whole thing but couldn’t find GL_MODELVIEW_MATRIX specific stuff.
Lets just say that I’m not particularly ‘hot’ on maths and am looking for a very clear example on how to use the MODELVIEW MATRIX to find the correct location of any point of my object after translations. I have got most of the stuff I have learned from NeHe’s examples but cant find what I’m looking for there.

I started this discussion hoping someone was going to tell me I don’t have to worry about the complex math to work this stuff out. I got my hopes up when some said multiply my point by the matrix; sound so easy.

Heavy maths!? That paper shows what a transformation matrix is and what it does. That aint heavy and you really should know what one is if you are using opengl.

So wht don;t you multiply your point by the modelview matrix?

[x, y, z, 1] . a b c d
e f g h
i j k l
m n o p

xa+ye+iz+m bx+fy …
and so on…

Thats not quite how it should have turned out! a b c…p is the 4x4 matrix

You need to understand basic matrix transformations. Personally, I dont use glTranslate or glRotate at all. I make my own transformation matrix during the scene updates, then call glMultMatrixD when I’m ready to draw it. The advantage to this is that I always have the transformation matrix stored for each object in the scene. Then If I want to get the absolute position of a vertex, I can do vertex.Transform(&matrix).

There are also simpler ways to perform rotations and translations that dont involve matrices. To translate (or un-translate) a point, you just add the translation value to the point. Rotations are a little more complex, but if you look around on the net, its not that hard to figure out how to do it.

Get a good book that discusses 3D transformations, vectors, etc. You cant do 3D without knowing some of the math behind it.

I have some understanding of basic transformations and can use glTranslated and glRotated without many problems.
I have not really had to understand more than glTranslated(x, y, z) moves things by x, y, z and glRotated(ang1, 1,0,0) rotates things by ang1(degrees) about the x thingy.
I have so far managed to create a nice racetrack and car totalling about 10,000 polys that runs quite nicely.

I have been following HeHe’s tuts and I have not yet found stuff about getting values out of the matrixes and what all 16 relate to.

Quote “That aint heavy and you really should know what one is if you are using opengl”

That’s was kind of why I was asking……… because I don’t know it yet.

The PDF does not contain anything similar to the formula below.
[x, y, z, 1] . a b c d
e f g h
i j k l
m n o p
xa+ye+iz+m bx+fy …
and so on…

Any chance you can give me a bit more, or a link to an example (please, no more 117 page PDF including formula about Hybrid or Multi-Sensor Fusion or The Discrete Kalman Filter)

The x, y and z translations are not the problem. I have to un-translate these for my frustum culling that I have just implemented.

I still maintain there is some pretty heavy maths in the PDF. Any page after 22 looks a bit tricky to me (I cant paste the formula here as I cant find a font which can display it).

Pops, you need to do two things:
a) Get the modelview matrix
b) Multiply your original point by this matrix

/* retrieve the current modelview matrix. this is after you’ve applied all of the transforms */
float M[16];

/* multiply the original point by this matrix. assume the original point is a 4-element array of floats */
float newPt[4];
newPt[0] = M[0]*oldPt[0]+M[4]*oldPt[1]+M[8]*oldPt[2]+M[12]*oldPt[3];
newPt[1] = M[1]*oldPt[0]+M[5]*oldPt[1]+M[9]*oldPt[2]+M[13]*oldPt[3];
newPt[2] = M[2]*oldPt[0]+M[6]*oldPt[1]+M[10]*oldPt[2]+M[14]*oldPt[3];
newPt[3] = M[3]*oldPt[0]+M[7]*oldPt[1]+M[11]*oldPt[2]+M[15]*oldPt[3];

/* newPt is now the transformed point you’re looking for */

Quote> “should help with the matrix transformations stuff etc.” The PDF i linked to you is on of the best that I have seen for fully explaining transformation matricies. Sorry but it won’t get any simpler than that. Obviously I wasn;t trying to get you to understand the other stuff. If you don’t know what a transformation matrix is how are you going to retrieve the translations from this? This is all shown in the paper that I linked to.

Thanks Citizen.

Another question. I’m not sure why my point would be a 4-element array. My original point only has x, y and z values. A little more help on this and I will leave you all alone.

I’m sorry to everyone, I really must be being thick to not be getting this. This is the only subject I have had problems with so far.

Originally posted by Pops:
[b]Thanks Citizen.

Another question. I’m not sure why my point would be a 4-element array. My original point only has x, y and z values. A little more help on this and I will leave you all alone.

Because you want to multiply your point with a 4x4 matrix. The matrix multiplication is only defined for two matrices A (a MxN matrix) and B (a PxQ matrix) if N=P. So your Point (which is a 1x3 matrix) must be a 1x4 matrix in order to multiply it by the modelview matrix. I hope this is understandable.
And since you don’t seem to like math I don’t explain why, but tell you that the first 3 values are your x,y,z and the last value is 1.


Thanks satan