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.
PersProjection
void Camera::setPerspective(float width, float height, float nearZ, float farZ, float angleDeg) {
perspectiveTrans.toZero();
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;
N.normalize();
Vector3f U = up;
U.normalize();
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;
}