How to get Yaw, Pitch and Roll from a 3D vector

前端 未结 4 1898
别跟我提以往
别跟我提以往 2020-12-14 09:15

I have a direction vector that applied to a position gives me the point at which the camera should look. How can I get from that yaw, pitch and roll in order to use glRotate

4条回答
  •  甜味超标
    2020-12-14 10:00

    pheelicks's equations are wrong. Dear future googlers, here you got what's working:

    Assuming pitch: rotation by X axis, yaw: rotation by Y axis, roll: rotation by Z axis. Direction vector V(x,y,z)

    pitch = asin(V.y / length(V));
    yaw = asin( V.x / (cos(pitch)*length(V)) ); //Beware cos(pitch)==0, catch this exception!
    roll = 0;
    

提交回复
热议问题