Here, the Up
vector defines the "upwards" direction in your 3D world (for this camera). For example, the value of vec3(0, 0, 1)
means the Z-axis points upwards.
Eye
is the point where you virtual 3D camera is located.
And Center
is the point which the camera looks at (center of the scene).
The best way to understand something is to make it yourself. Here is how a camera transformation can be constructed using 3 vectors: Eye
, Center
, and Up
.
LMatrix4 LookAt( const LVector3& Eye, const LVector3& Center, const LVector3& Up )
{
LMatrix4 Matrix;
LVector3 X, Y, Z;
Create a new coordinate system:
Z = Eye - Center;
Z.Normalize();
Y = Up;
X = Y.Cross( Z );
Recompute Y = Z cross X
:
Y = Z.Cross( X );
The length of the cross product is equal to the area of the parallelogram, which is < 1.0 for non-perpendicular unit-length vectors; so normalize X
, Y
here:
X.Normalize();
Y.Normalize();
Put everything into the resulting 4x4 matrix:
Matrix[0][0] = X.x;
Matrix[1][0] = X.y;
Matrix[2][0] = X.z;
Matrix[3][0] = -X.Dot( Eye );
Matrix[0][1] = Y.x;
Matrix[1][1] = Y.y;
Matrix[2][1] = Y.z;
Matrix[3][1] = -Y.Dot( Eye );
Matrix[0][2] = Z.x;
Matrix[1][2] = Z.y;
Matrix[2][2] = Z.z;
Matrix[3][2] = -Z.Dot( Eye );
Matrix[0][3] = 0;
Matrix[1][3] = 0;
Matrix[2][3] = 0;
Matrix[3][3] = 1.0f;
return Matrix;
}
up
vector explicitly defines the up (Y) axis, the other two are computed based on the direction from theeye
to thecenter
(sometimes called theforward
vector or Z-axis) and the cross-product between the Z-axis and Y-axis to produce the X-axis (left
vector), which is perpendicular to both. LookAt also defines the origin in adition to axes. – Andon M. Coleman