So I started to make my own engine, and got my Z axis pointing away from my camera. I don't know why it happened, I followed this tutorial pretty much.

I'll post my persprojection and view calculations of my camera, please comment what other code should I post, and I'll update my post.


void Camera::setPerspective(float width, float height, float nearZ, float farZ, float angleDeg) {

float ar = width / height;

angleDeg = Math3D::ToRadian(angleDeg);

perspectiveTrans(0, 0) = 1.0f / (ar * tanf(angleDeg / 2.0f));
perspectiveTrans(1, 1) = 1.0f / tanf(angleDeg / 2.0f);
perspectiveTrans(2, 2) = (-nearZ - farZ) / (nearZ - farZ);
perspectiveTrans(2, 3) = (2.0f * farZ * nearZ) / (nearZ - farZ);
perspectiveTrans(3, 2) = 1.0f;

View and Projection calculations

Matrix4x4f Camera::getViewProjection() {
Matrix4x4f cameraRotationTrans(MatrixType::IDENTITY);

Vector3f N = target;
Vector3f U = up;
U = U.cross(target);
Vector3f V = N.cross(U);

cameraRotationTrans.setRow(0, Vector4f(U, 0));
cameraRotationTrans.setRow(1, Vector4f(V, 0));
cameraRotationTrans.setRow(2, Vector4f(N, 1));

Matrix4x4f cameraTranslationTrans(MatrixType::IDENTITY);
cameraTranslationTrans.setCol(3, Vector4f(-position, 1));

return perspectiveTrans * cameraRotationTrans * cameraTranslationTrans;
  • \$\begingroup\$ yeah sorry, I modified the title \$\endgroup\$ Aug 30 '16 at 14:46

Not to be glib but obviously you have something out of order in your operations or some other basic error like that. It is not immediately clear where that is happening though.


You might consider using GLM at least as a starting point. That way you won't always be wondering whether it is your current code that has an issue, or your base code. Then later when you are confident you have lots of stuff working you can switch it out completely.


This tutorial starts off kind of basic but talks about glm and shows how to get the perspective etc. working with it. You can also compare the implemenation to what you are doing and see if anything jumps out as obviously wrong.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .