Rockinredross867

12-10-2015, 04:58 PM

The title says it all I just need some feedback if my lookAt function is correct.

mat4 mat4::view(vec3 cameraVector, vec3 targetPos, vec3 rightVector, vec3 upVector)

{

mat4 result;

mat4 secondMatrix(1.0f);

mat4 firstMat(1.0f);

vec3 directionVector = vec3::normalize(cameraVector - targetPos);

firstMat.elements[0] = rightVector.x;

firstMat.elements[1] = rightVector.y;

firstMat.elements[2] = rightVector.z;

firstMat.elements[4] = upVector.x;

firstMat.elements[5] = upVector.y;

firstMat.elements[6] = upVector.z;

firstMat.elements[8] = directionVector.x;

firstMat.elements[9] = directionVector.y;

firstMat.elements[10] = directionVector.z;

secondMatrix.elements[3] = -cameraVector.x;

secondMatrix.elements[7] = -cameraVector.y;

secondMatrix.elements[11] = -cameraVector.z;

result = firstMat * secondMatrix;

return result;

}

mat4 mat4::view(vec3 cameraVector, vec3 targetPos, vec3 rightVector, vec3 upVector)

{

mat4 result;

mat4 secondMatrix(1.0f);

mat4 firstMat(1.0f);

vec3 directionVector = vec3::normalize(cameraVector - targetPos);

firstMat.elements[0] = rightVector.x;

firstMat.elements[1] = rightVector.y;

firstMat.elements[2] = rightVector.z;

firstMat.elements[4] = upVector.x;

firstMat.elements[5] = upVector.y;

firstMat.elements[6] = upVector.z;

firstMat.elements[8] = directionVector.x;

firstMat.elements[9] = directionVector.y;

firstMat.elements[10] = directionVector.z;

secondMatrix.elements[3] = -cameraVector.x;

secondMatrix.elements[7] = -cameraVector.y;

secondMatrix.elements[11] = -cameraVector.z;

result = firstMat * secondMatrix;

return result;

}