Rockinredross867

12-11-2015, 07:24 PM

I made a similar post a couple days ago and now I made some changes to the code and I still don't thing my lookAt matrix is working. Please help.

EDITED!

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

{

mat4 result(1.0f);

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

vec3 rightVector = vec3::normalize(vec3::cross(upVector, directionVector));

vec3 theUpVector = vec3::normalize(vec3::cross(directionVector, upVector));

result.elements[0 + 0 * 4] = rightVector.x;

result.elements[0 + 1 * 4] = rightVector.y;

result.elements[0 + 2 * 4] = rightVector.z;

result.elements[1 + 0 * 4] = theUpVector.x;

result.elements[1 + 1 * 4] = theUpVector.y;

result.elements[1 + 2 * 4] = theUpVector.z;

result.elements[2 + 0 * 4] = directionVector.x;

result.elements[2 + 1 * 4] = directionVector.y;

result.elements[2 + 2 * 4] = directionVector.z;

result.elements[3 + 0 * 4] = cameraVector.x;

result.elements[3 + 1 * 4] = cameraVector.y;

result.elements[3 + 2 * 4] = cameraVector.z;

return result;

}

EDITED!

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

{

mat4 result(1.0f);

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

vec3 rightVector = vec3::normalize(vec3::cross(upVector, directionVector));

vec3 theUpVector = vec3::normalize(vec3::cross(directionVector, upVector));

result.elements[0 + 0 * 4] = rightVector.x;

result.elements[0 + 1 * 4] = rightVector.y;

result.elements[0 + 2 * 4] = rightVector.z;

result.elements[1 + 0 * 4] = theUpVector.x;

result.elements[1 + 1 * 4] = theUpVector.y;

result.elements[1 + 2 * 4] = theUpVector.z;

result.elements[2 + 0 * 4] = directionVector.x;

result.elements[2 + 1 * 4] = directionVector.y;

result.elements[2 + 2 * 4] = directionVector.z;

result.elements[3 + 0 * 4] = cameraVector.x;

result.elements[3 + 1 * 4] = cameraVector.y;

result.elements[3 + 2 * 4] = cameraVector.z;

return result;

}