Advertisement

My cameras inverse matrix didn't do what I thought it should

Started by September 24, 2002 05:20 PM
2 comments, last by WhatEver 22 years, 4 months ago
I''ve been using my objects inverse matrices to convert world vertices to object space...so I thought you could do the same to bring the cameras rotation and position to world space. Not so. Translate works, but the rotation is messed up. Why? It doesn''t make sense at all. Even if I do it on paper it works out, but not when I actually do it. Here''s a sample of code that isn''t overwhelming: This is what push does...
  S3Dvoid s3d_camera::Push()
{
	S3Dmat16f	MatrixInverse;

	s3dMatCopy16f(MatrixInverse, CameraMatrix);
	s3dMatInvert16f(MatrixInverse);

	glPushMatrix();
	glMultMatrixf(MatrixInverse);
}  
This is where and how I use it...
  Camera.LoadIdentity();
	Camera.Translatef(0.0f, 0.0f, -160.0f);
	Camera.Rotatef(Pitch, 1.0f, 0.0f, 0.0f);
	Camera.Rotatef(Yaw, 0.0f, -1.0f, 0.0f);
	Camera.Push();  
What I''m doing is transforming a camera into world space, then inverting the camera to bring it to the world view. The odd thing is that it doesn''t work :/. The reason I want to do it this way is so I can use an entities pos and angle as a camera if I choose.
I don`t see how your algo will work.
Don`t you just want to grab the objects pos and view angle, then shove them them into your camera ?

I mean...

say you have a camera object with pos vector, plus view vector.
Right ?

Now your objects are going to have a pos vector, plus a view vector, right ?
Just copy them and change the camera to the new position/view ?

Am I right or wrong ? :-/

Note: Order of ops is correct, right ?

Bugle4d
~V'lionBugle4d
Advertisement
Your last statement helped me Vlion. Thanks .

I had the order wrong. It's suppose to be:

Camera.LoadIdentity();
Camera.Translatef(Pos[0], Pos[1], Pos[2]);
Camera.Rotatef(Yaw, 0.0f, -1.0f, 0.0f);
Camera.Rotatef(Pitch, 1.0f, 0.0f, 0.0f);
Camera.Push();

not:

Camera.LoadIdentity();
Camera.Translatef(Pos[0], Pos[1], Pos[2]);
Camera.Rotatef(Pitch, 1.0f, 0.0f, 0.0f);
Camera.Rotatef(Yaw, 0.0f, -1.0f, 0.0f);
Camera.Push();

I've been used to:

glPushMatrix();
glRotatef(Pitch, -1.0f, 0.0f, 0.0f);
glRotatef(Yaw, 0.0f, 1.0f, 0.0f);
glTranslatef(-Pos[0], -Pos[1], -Pos[2]);
glPopMatrix();

...which is just a manual way of trasforming an inverted matrix.

Now it makes sense .

[edited by - WhatEver on September 25, 2002 6:25:15 PM]
I...got something....right ?

Wow !

:-)


Bugle4d
~V'lionBugle4d

This topic is closed to new replies.

Advertisement