Note that there are some explanatory texts on larger screens.

plurals
  1. POgluLookAt vectors and FPS-style camera
    text
    copied!<p>I am attempting to implemented an FPS-style camera by updating three vectors: EYE, DIR, UP. These vectors are the same that are used by gluLookAt (since gluLookAt is specified by the position of the camera, the direction it is looking at, and an up vector). </p> <p>I have already implemented the left-right and up-down strafing movements, but I'm having a lot of trouble understanding the math behind making the camera look-around while remaining stationary. In this case, the EYE vector remains the same, while I must update DIR and UP. </p> <p>Below is the code I tried, but it doesn't seem to work properly. Any suggestions?</p> <pre><code>void Transform::left(float degrees, vec3&amp; dir, vec3&amp; up) { vec3 axis; axis = glm::normalize(up); mat3 R = rotate(-degrees, axis); dir = R*dir; up = R*up; }; void Transform::up(float degrees, vec3&amp; dir, vec3&amp; up) { vec3 axis; axis=glm::normalize(glm::cross(dir,up)); mat3 R = rotate(-degrees, axis); dir = R*dir; up = R*up; }; </code></pre> <p>The rotate method creates a rotation matrix that rotates an an amount degrees around axis.</p> <p>--</p> <p>EDIT: I edited it to this (switching 'dir' to 'center', as well), but it still didn't work. When I try to rotate left/right, nothing happens. When I try to rotate up/down, the object disappears. </p> <pre><code>void Transform::left(float degrees, vec3&amp; center, vec3&amp; up) { center = center*rotate(-degrees,glm::normalize(up)); } void Transform::up(float degrees, vec3&amp; center, vec3&amp; up) { vec3 axis = glm::normalize(glm::cross(center,up)); center = center*rotate(-degrees, axis); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload