PDA

View Full Version : Need help with my lookAt function

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;
}

GClements
12-11-2015, 08:02 PM
1. Your matrices appear to be transposed. OpenGL (and GLM) uses column-major order, i.e. elements 0, 1, 2, and 3 are the left-hand column, not the top row.
2. rightVector will actually point to the left; the arguments to vec3::cross() should be the other way around.

This assumes that all of the functions and operators follow the usual conventions (the ones from GLM do).

Rockinredross867
12-12-2015, 08:23 AM

carsten neumann
12-12-2015, 10:40 AM

Please consider that in general it is better to describe which aspect of your question was not answered by a post or what you need more details on.

Take a look at gluLookAt (https://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml) for how the matrix is assembled.

Rockinredross867
12-12-2015, 12:55 PM
Please consider that in general it is better to describe which aspect of your question was not answered by a post or what you need more details on.

Take a look at gluLookAt (https://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml) for how the matrix is assembled.

Like I said I need some feedback to see if my matrix is alright just like what my title says. I don't need any other information. I just need to see if I did the math right. I'm just a beginner so take it easy on me.

Rockinredross867
12-16-2015, 05:11 PM
Please I need help I want to do some 3D Graphics! PLS!!!

Rockinredross867
12-18-2015, 08:09 AM
The theUpVector should have the rightVector in there not upVector. My bad.