• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualMartin Perry

Posted 01 July 2012 - 12:06 PM

I am solving my camera with its own coordinate system in camera space (similar to object space).

My camera has forward, up and right vectors. If I rotate camera, i rotate those 3 vectors around axis by angle.

For example, rotation around Y axis
MyMath::Matrix4x4 rotation = MyMath::Matrix4x4::Rotation(this->up, angle);
this->right = MyMath::Vector3::TransformNormal(this->right, rotation);
this->forward = MyMath::Vector3::TransformNormal(this->forward, rotation);

TransformNormal takes only 3x3 part of 4x4 matrix. No translation and homogenous part is involved.

Than if I build view matrix
this->lookAt = this->cameraPos + this->forward;
this->viewMatrix = MyMath::Matrix4x4::LookAtLH(this->cameraPos, this->lookAt, MyMath::Vector3::UnitY());


Final step is to update camera system from view matrix.
this->right.X = this->viewMatrix.M[0][0];
this->right.Y = this->viewMatrix.M[1][0];
this->right.Z = this->viewMatrix.M[2][0];
this->up.X = this->viewMatrix.M[0][1];
this->up.Y = this->viewMatrix.M[1][1];
this->up.Z = this->viewMatrix.M[2][1];
this->forward.X = this->viewMatrix.M[0][2];
this->forward.Y = this->viewMatrix.M[1][2];
this->forward.Z = this->viewMatrix.M[2][2];


And thats basicly my whole camera. Of course, I have some utils function around it, but idea is to have independent coordinate system and all transformation do on this system.
P.S: Used notification is DirectX (row-base), so for OpenGL matrices should be transposed (col-based)

### #1Martin Perry

Posted 01 July 2012 - 12:05 PM

I am solving my camera with its own coordinate system in camera space (similar to object space).

My camera has forward, up and right vectors. If I rotate camera, i rotate those 3 vectors around axis by angle.

For example, rotation around Y axis
MyMath::Matrix4x4 rotation = MyMath::Matrix4x4::Rotation(this->up, angle);
this->right = MyMath::Vector3::TransformNormal(this->right, rotation);
this->forward = MyMath::Vector3::TransformNormal(this->forward, rotation);


Than if I build view matrix
this->lookAt = this->cameraPos + this->forward;
this->viewMatrix = MyMath::Matrix4x4::LookAtLH(this->cameraPos, this->lookAt, MyMath::Vector3::UnitY());


Final step is to update camera system from view matrix.
this->right.X = this->viewMatrix.M[0][0];
this->right.Y = this->viewMatrix.M[1][0];
this->right.Z = this->viewMatrix.M[2][0];
this->up.X = this->viewMatrix.M[0][1];
this->up.Y = this->viewMatrix.M[1][1];
this->up.Z = this->viewMatrix.M[2][1];
this->forward.X = this->viewMatrix.M[0][2];
this->forward.Y = this->viewMatrix.M[1][2];
this->forward.Z = this->viewMatrix.M[2][2];


And thats basicly my whole camera. Of course, I have some utils function around it, but idea is to have independent coordinate system and all transformation do on this system.
P.S: Used notification is DirectX (row-base), so for OpenGL matrices should be transposed (col-based)

PARTNERS