0

I need to implement a quaternion for rotating a camera. Before implementing quaternion, I use LookAt(&eye, &at, &up) for expressing a camera coordinate (vpn, vup, ...).

vec3 eye = vec3(0.0,0.0,-10.0);
vec3 to = vec3(0.0,0.0,0.0); // initial
vec3 up = vec3(0.0,1.0,0.0);

vec3 d = to - eye;

and at display callback.

        m = LookAt(eye,to,up);

        glUniformMatrix4fv(ModelView,1,GL_TRUE,m);

and Add an rotation (it is still euclidean rotation, and keyboard interation)

        case 'a':
                temp = RotateX(1.0) * vec4(d,0);
                temp1 = RotateX(1.0) * vec4(up,0);
                d = vec3(temp.x, temp.y, temp.z);
                up = vec3(temp1.x, temp1.y, temp1.z);
                eye = to - d;
                break;
        case 'd':
                temp = RotateY(1.0) * vec4(d,0);
                temp1 = RotateY(1.0) * vec4(up,0);
                d = vec3(temp.x, temp.y, temp.z);
                up = vec3(temp1.x, temp1.y, temp1.z);
                eye = to - d;
                break;

So my question is, LookAt function is only making camera coordinate? Is there any rotation matrix to make camera coordinate? As you see I make rotate my camera by using some rotation not in LookAt, I will this rotation by using quaternion. However LookAt() uses some rotation, I will implement quaternion version of LookAt to avoid gimbal lock

user1732445
  • 235
  • 2
  • 4
  • 14

1 Answers1

2

All what LookAt does is a translation T (so that the new origin is at the point eye) followed by a rotation R. The rotation is defined by building an orthonormal basis from the 3 vectors (direction defined by the vector from eye to center, the up vector directly specified, and the right vector which is defined to be perpendicular to both). The final transorm produced by LookAt would be R*T.

You can use LookAt without any gimbal lock problems if you specify your input vectors correctly, but you can also describe your camera by a position vector (defining T) and orientation quaternion (defining R), and wouldn't have to use LookAt at all.

derhass
  • 43,833
  • 2
  • 57
  • 78
  • that is true that it is first T and R transformation applied for LooAt. I have seen some discussion in this video too: https://www.youtube.com/watch?v=s9FhcvjM7Hk But I have no idea whey we can't apply R and then T. Do you have an explanation? – Narek Sep 20 '17 at 07:23
  • @Narek: _Every_ transformation matrix consiting solely from rotations and translations can both be decomposed into `M=T1*R` and `M=R*T2` form, just that the translation value itself will change beetween both forms. – derhass Sep 20 '17 at 18:31