Skip to main content
added 2 characters in body
Source Link
Pablo Ariel
  • 1.4k
  • 8
  • 13

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I believe you cancould have an error with your current values because your camera "front" vector is aligned with the "up" vector, and if I guess well that could result in a zero-length "right" vector. Again I'm not sure if this is right...

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I believe you can have an error with your current values because your camera "front" vector is aligned with the "up" vector, and if I guess well that could result in a zero-length "right" vector. Again I'm not sure if this is right...

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I believe you could have an error with your current values because your camera "front" vector is aligned with the "up" vector, and if I guess well that could result in a zero-length "right" vector. Again I'm not sure if this is right...

added 238 characters in body
Source Link
Pablo Ariel
  • 1.4k
  • 8
  • 13

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I believe you can have an error with your current values because your camera "front" vector is aligned with the "up" vector, and if I guess well that could result in a zero-length "right" vector. Again I'm not sure if this is right...

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.

I believe you can have an error with your current values because your camera "front" vector is aligned with the "up" vector, and if I guess well that could result in a zero-length "right" vector. Again I'm not sure if this is right...

Source Link
Pablo Ariel
  • 1.4k
  • 8
  • 13

I think that for creating the matrix you should get the front vector first, you do:

Vector3 vFront = Camera.vTarget - Camera.vPosition,
    vUp = Camera.vUp, vRight(0,0,0);
vFront.Normalize();
vRight.Cross( vUp, vFront ); // Up x Front = Right
vRight.Normalize();
vUp.Cross( vFront, vRight ); // Front x Right = Up
vUp.Normalize();

then you build the matrix from these vectors as follows:

Matrix4 m;
m._14 = m._24 = m._34 = 0.0f;
m._44 = 1.0f;

m._11 = vRight.x;
m._21 = vRight.y;
m._31 = vRight.z;
m._41 = - (vPosition.Dot(vRight));

m._12 = vUp.x;
m._22 = vUp.y;
m._32 = vUp.z;
m._42 = - (vPosition.Dot(vUp));

m._13 = vFront.x;
m._23 = vFront.y;
m._33 = vFront.z;
m._43 = - (vPosition.Dot(vFront));

I don't know much about what I'm talking about but my renderer works so chances are this is the right matrix formula.

No... actually you may need to transpose the result, depending on your math conventions.