I need to rotate my camera (say viewplane) around arbitrary point in
space. Viewplane is rotated around local axes (not global ones!).
I have my viewplane stored as column-major 4x4 matrix (three vectors +
origin).
I have the 3x3 rotation matrix the does some rotation.
Given:
Matrix4d M; // vieplane matrix
Matrix4d R // rotational matrix only 3x3 part is used
Just to remind that:
M = M * R; rotation about global axes placed at (0,0,0)
M = R * M; rotation about local axes placed at local CS origin
So to do rotation about global axes placed at arbitrary point P I need
to move global CS to P, rotate and move it backwards:
M = M * (P); // translation
M = M * R // rotation
M = M * (-P) // back translation
So how do I rotate about local axes placed at arbitrary point P - do I
have to move local CS to point P, rotate and move it backwards?
> I need to rotate my camera (say viewplane) around arbitrary point in
> space. Viewplane is rotated around local axes (not global ones!).
> I have my viewplane stored as column-major 4x4 matrix (three vectors
I have a similar problem, rotating around local axes. I have a 3d object
which needs to rotate around its own axis. I can do it quite cheaply by
remebering the modelview matrix from the previous setting and applying only
relative movements. However, I need the actual coordinates of the object
for collision detection. I know this is a common problem. But I'm stumped.
Searches on google have yielded stuff about Euler angles but nothing solid.
Thanks
Sharanga
Simplest solution:
Translate the point of rotation to the origin, rotate and translate back.
--
+------------------------------------------------+
| +----------------+ WOLFGANG DRAXINGER |
| | ,-. DARKSTAR | lead programmer |
| |( ) +---------+ wdrax...@darkstargames.de |
| | `-' / GAMES / |
| +----+'''''''' http://www.darkstargames.de |
+------------------------------------------------+
Look at the bottom row of the matrix you're remembering.
--
<\___/>
/ O O \
\_____/ FTB.
> Simplest solution:
>
> Translate the point of rotation to the origin, rotate and translate back.
I'm already translating to the object's centre to perform the rotation. My
problem is that, I need to do two rotations about the object's z and y axes.
However, the first rotation rotates the object about the frames z axis (
i.e. up and down ) and the second rotation rotates it about the frames y
axis. When a rotation about the z-axis is performed, the object's y-axis
rotates. I want to rotate about this moving y-axis. Unfortunately I don't
seem to be able to perform this.
The bottom row is all zero.
The last column of the matrix contains the screen relative coordinates of
the origin of the object. Using gluUnProject to return absolute values
doesn't seem to be working.
...or column, depending on your "GetMatrix" code.
> the screen relative coordinates of the origin of the object.
> Using gluUnProject to return absolute values
> doesn't seem to be working.
>
I don't know the details of your program but the
last column should the object's position.
No matter what, you don't need gluUnproject().
If you want a rotation in object space then just
multiply the matrices the other way around.
> I don't know the details of your program but the
> last column should the object's position.
>
> No matter what, you don't need gluUnproject().
I'm talking about the modelview matrix.
I've messed around with the coordinates you mentioned to position sound
sources releative to the camera with OpenAL. Those three coordinates are
relative to the screen. (0, 0, 0 ) is relative to the centre of the screen,
at the near clip plane.
Suppose my far plane is 5000 units away from the near plane. An object which
is near the far clipping plane will have an z coordinate of ~ -4999.
I need world coordinates.
My code for moving my object in the direction it faces is as follows:
( helimatrix is the preserved modelview matrix I use for storing the
helicopter's translated and rotated position ).
X = -HELICOPTER_MOVE_INC;
Y = 0;
Z = 0;
//Pos = MatMul( HeliMatrix, Vector( X, Y, Z ) );
glPushMatrix();
glLoadMatrixd( HeliMatrix );
glTranslatef( X, Y, Z );
glGetDoublev( GL_MODELVIEW_MATRIX, TempMatrix );
X = TempMatrix[12];
Y = TempMatrix[13];
Z = TempMatrix[14];
/*GetOriginalCoordsCustom( TempMatrix, X, Y, Z, a, b, c );
//X = a;
Y = b;
Z = c;*/
cout << "Internal coords" << X << ", " << Y << ", " << Z << endl;
glPopMatrix();
I can use the above principle to move the object. However, I need to perform
collision detection.
Cheers
Sha
I hope not. It should be 0,0,0,1.
(Bottom row versus last column depends on how you
write out the matrix.)
> The last column of the matrix contains the screen relative coordinates of
> the origin of the object.
Assuming the matrix you are using is the model-view times the
projection, yes.
> Using gluUnProject to return absolute values
> doesn't seem to be working.
What are you using for screen z?
--
Andy V (OpenGL Alpha Geek)
"In order to make progress, one must leave the door to the unknown ajar."
Richard P. Feynman, quoted by Jagdish Mehra in _The Beat of a Different Drum_.
OpenGL Technical FAQ: http://www.opengl.org/developers/faqs/technical.html
> Assuming the matrix you are using is the model-view times the
> projection, yes.
>
> > Using gluUnProject to return absolute values
> > doesn't seem to be working.
>
> What are you using for screen z?
z = -z / (Far - Near);
Cheers
Sharanga
However, I use gluLookAt before. This should position the damn thing.