#Rotation about 2 axis

4 messages · Page 1 of 1 (latest)

plush roost
#

hey there, I am trying to rotate m_up and m_front by offset (in degrees). the function below only rotates around the x-axis for now. But I also needs to rotate around the y-axis. I am not quite sure how to achieve this.

(when I first multiply m_up & m_front by rotate_x and then by rotate_y. the camera seems to rotate a bit about the z-axis)

(I am using row vectors).

void Camera::rotate(const Vec3<GLfloat>& offset) {
    GLfloat p = RADIANS(offset.x); /* pitch */
    GLfloat h = RADIANS(offset.y); /* heading */
    GLfloat b = RADIANS(offset.z); /* bank */

    Mat3<GLfloat> rotate_x{
        1.0f,  0.0f,    0.0f,
        0.0f,  cosf(p), sinf(p),
        0.0f, -sinf(p), cosf(p)
    };

    Mat3<GLfloat> rotate_y{
        cosf(h), 0.0f, -sinf(h),
        0.0f,    1.0f,  0.0f,
        sinf(h), 0.0f,  cosf(h),
    };

    Mat3<GLfloat> rotate_z{
         cosf(b), sinf(b), 0.0f,
        -sinf(b), cosf(b), 0.0f,
         0.0f,    0.0f,    1.0f
    };

    /* currently only rotates around x-axis! */
    m_front = m_front * rotate_x;
    m_up = m_up * rotate_x;
}
#

I found this matrix to rotate around an arbitrary axis, but wondered if there is a simpler approach since I don't need to rotate around the z-axis

twilit timber
#

then leave the zaxis part away

dawn ether
#

Rotate about the axes one at a time, in whichever order you want