Skip to main content
gamedev.net
🔒 Locked

camera matrix

Started by ArnoAtWork Apr 29, 2004 at 11:04 AM 4 replies 400+ views
Original Post
ArnoAtWork
ArnoAtWork
I would like to rotate my camera from its local axis(Z:viewing axis. X,Y:screen axis). If I give a rotation matrix, I would like to convert this matrix into a camera matrix. So, to do that, I calculate a first matrix to change the set of axis: CMatrix axis (vx.x, vx.y, vx.z, 0, vy.x, vy.y, vy.z, 0, vz.x, vz.y, vz.z, 0, 0, 0, 0, 1); So in the function, I simply multiply axis with the global rotation matrix. But, as u can imagine, it''s not working... Do you know why?
Trienco
Trienco
in which way are you setting your "view matrix" (or modelview.. *sigh* why isnt the current forum displayed when writing a post).

if the matrix above is what you like the camera to be oriented like then i assume you didnt forget to invert that matrix first?
f@dzhttp://festini.device-zero.de
ArnoAtWork
ArnoAtWork
What I want is to be able to rotate the camera along its own axes. So, given a rotation matrix of absolute axis, I would like to convert it into local axis.

As I was not sure of how u set a matrix to convert a set of axis, I tried using the transposed of the matrix, but it was not working...

Trienco
Trienco
slightly confused you. a rotation matrix isnt really about local or absolute axes. its around x,y,z axes and if they are local or global only depends on the matrix you multiply it with. well, not quite true. in fact its more a question of either AxB or BxA deciding if the rotation is applied before or after (before usually being "global" and after being "local").
f@dzhttp://festini.device-zero.de
ArnoAtWork
ArnoAtWork
Obviously, rotation matrix is along axis which can be converted if u multiply a second matrix which converts into a new set of axis, I know that.

The problem is that it''s not currently working...and I would like to know why !



GameCat
GameCat
How exactly isn't it working? Things explode, tha camera deosn't rotate at all, what?

If you want to rotate around the camera's local axes you have to translate it first so that it is positioned on the origin. Here's a straight cut and paste from my code:


void SceneNode::rotateLocal(float degrees, const Vector3& axis){
Matrix3 rot;

rot.loadIdentity();
rot.rotate(degrees, axis);
Matrix4 t(1,0,0,-xForm[12],
0,1,0,-xForm[13],
0,0,1,-xForm[14],
0,0,0,1);

Matrix4 tInv(1,0,0,xForm[12],
0,1,0,xForm[13],
0,0,1,xForm[14],
0,0,0,1);

xForm=(tInv*Matrix4(rot)*t)*xForm;
}


xForm is the transform of the SceneNode and is a 4x4 matrix. xForm[12]-xForm[14] is the transforms position vector.

[edited by - GameCat on April 30, 2004 5:29:09 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.