0

I'm trying to make rotation of the camera without roll effect.

I accumulate 3 angles from 0 to 359.9 degrees. Then I make 3 quaternions (glm::quat) from accumulated angles (half) with global axial vectors and multiply them into 1 quaternion. Then I convert this quaternion to rotation matrix. And at least I insert this 3x3 matrix into 4x4 view transform matrix (to [0][0] corner).

void View::rotate(const float& angleX, const  float& angleY, const  float& angleZ)
{
    float rad = 3.14159265359/180.0;

    pitchAngle += angleX;
    degree360(pitchAngle);

    yawAngle   += angleY;
    degree360(yawAngle);

    rollAngle  += angleZ;
    degree360(rollAngle);

    float angle_x = pitchAngle*rad/2;
    float angle_y = yawAngle*rad/2;
    float angle_z = rollAngle*rad/2;

    glm::quat qX = glm::quat(angle_x, glm::vec3(1.0, 0.0, 0.0));
    glm::quat qY = glm::quat(angle_y, glm::vec3(0.0, 1.0, 0.0));
    glm::quat qZ = glm::quat(angle_z, glm::vec3(0.0, 0.0, -1.0));

    glm::quat q = qZ * qX * qY;

    glm::mat4 spin_mat = glm::mat4_cast(q);

    matrix[0][0] = spin_mat[0][0];
    matrix[0][1] = spin_mat[0][1];
    matrix[0][2] = spin_mat[0][2];
    matrix[1][0] = spin_mat[1][0];
    matrix[1][1] = spin_mat[1][1];
    matrix[1][2] = spin_mat[1][2];
    matrix[2][0] = spin_mat[2][0];
    matrix[2][1] = spin_mat[2][1];
    matrix[2][2] = spin_mat[2][2];
}

I can't understand what I am doing wrong. This function rotate in strange incredible directions and angles.

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
Kroll
  • 649
  • 2
  • 6
  • 17
  • Can you illustrate your expectations and observations ? – minorlogic Mar 09 '15 at 07:42
  • Mouse x & y movements must doing summary only yaw and pitch, like in this demo http://bionica.esy.es/files/ogt.zip . Execute it and tab key, then rotat mouse many times in ccw. It makes roll effect. I don't want this roll. In second demo http://code.google.com/p/gl33lessons/downloads/detail?name=lesson04.zip no roll effect. This behavior of mouse camera rotation I want. – Kroll Mar 09 '15 at 12:21
  • In quaternions as I trying. – Kroll Mar 09 '15 at 12:26
  • Sorry, cant edit after 5 min. "Mouse x & y movements must doing summary only yaw and pitch, **NOT** like in this demo bionica.esy.es/files/ogt.zip ." – Kroll Mar 09 '15 at 12:30

0 Answers0