I've been trying to figure out what 2 portions of code are doing in this tutorial: Keyboard and Mouse.
Specifically:
// Direction : Spherical coordinates to Cartesian coordinates conversion
glm::vec3 direction(
cos(verticalAngle) * sin(horizontalAngle),
sin(verticalAngle),
cos(verticalAngle) * cos(horizontalAngle)
);
and
// Right vector
glm::vec3 right = glm::vec3(
sin(horizontalAngle - 3.14f/2.0f),
0,
cos(horizontalAngle - 3.14f/2.0f)
);
I don't see how the first one is spherical -> cartesian. When I look it up, I get:
x = r * sin(theta) * cos(phi)
y = r * sin(theta) * sin(phi)
z = r * cos(theta)
I've read on Euler angles, axis-angle and quaternions none of those have shed light on what this is doing or I'm just not able to grasp what I'm reading. ;)
On the 2nd one, shouldn't the right vector just be 90 degrees to the right of the direction vector?
gluLookAt (...)
or are they forming the basis of your matrix? One reason the "90 degrees to the right of direction" generalization does not work is because it could be parallel to your up vector and then you have a degenerate 3D space.gluLookAt (...)
actually re-orthgonalizes the basis vectors after computing the cross-product, that way the input up and forward vectors do not have to be at 90 degrees to produce a working view matrix. – Andon M. Coleman