kangaba

December 22nd, 2013, 11:09 PM

Hi,

I got an IcoSphere at the center of the canvas, it rotates "down" (-Y) when dragging with the mouse down, "up" when dragging up, and left and right respectively -X and X.

Soon after playing with it (dragging in random directions) it starts rotating in the opposite direction ("up" when I drag it "down") it's supposed to.

Any idea what this issue is called or how to fix it?

I'm using 4x4 matrices for X and Y rotations which I multiply into the final rotation:

about_x += mgl::Rad() * state_->mouse_motion()->delta_y * kAccel;

about_y += mgl::Rad() * state_->mouse_motion()->delta_x * kAccel;

mat_mv.i(); // i() = set to identity

mat_rot.i();

mat_rot.rot_y(about_y); // Rotation about Y

mat_mv *= mat_rot;

mat_rot.i();

mat_rot.rot_x(about_x); // Rotation about X

mat_mv *= mat_rot; // concatenate both rotations

mat_mv3 = mat_mv.to_mat3();

mat_transl.transl(0.0f, 0.0f, frame->zn - 12.0f);

mat_mv *= mat_transl;

mat_mvp = frame->mat_persp * mat_mv;

// send "map_mvp" to the shader

I got an IcoSphere at the center of the canvas, it rotates "down" (-Y) when dragging with the mouse down, "up" when dragging up, and left and right respectively -X and X.

Soon after playing with it (dragging in random directions) it starts rotating in the opposite direction ("up" when I drag it "down") it's supposed to.

Any idea what this issue is called or how to fix it?

I'm using 4x4 matrices for X and Y rotations which I multiply into the final rotation:

about_x += mgl::Rad() * state_->mouse_motion()->delta_y * kAccel;

about_y += mgl::Rad() * state_->mouse_motion()->delta_x * kAccel;

mat_mv.i(); // i() = set to identity

mat_rot.i();

mat_rot.rot_y(about_y); // Rotation about Y

mat_mv *= mat_rot;

mat_rot.i();

mat_rot.rot_x(about_x); // Rotation about X

mat_mv *= mat_rot; // concatenate both rotations

mat_mv3 = mat_mv.to_mat3();

mat_transl.transl(0.0f, 0.0f, frame->zn - 12.0f);

mat_mv *= mat_transl;

mat_mvp = frame->mat_persp * mat_mv;

// send "map_mvp" to the shader