Hi, I wrote a program which loads a obj mesh file and render it. Now I wanted to be able to use mouse to rotate the model, in all directions. Exactly like in 3D modelling software Maya and Blender.
I think I need three values to store rotation in all direction. but how do I relate mouse moves to the rotatation degree change? any little demo examples would be good as well
I do understand the rotation matrix, however, what I wanted is how to use mouse to control rotation. E.g. How much the object rotate horizontally when mouse moved a couple of pixels?
I think it can be considered an advanced question as
I understand it. And, it is more of a widget+GL type
question than just GL.
WHat I do is use the Xlib (on unix and X11) to trap
mouse motion and key press and release events. On
a mouse-press event (and when my program is at a
particular state) the rotation is activated. Then,
pointer motion is trapped and for every pixel of
motion I rotate by 1 degree and redraw as often as
the event loop cycles. Upon release of the button,
I get out of the rotating motion.
A tricky part is to get quaternions working for
rotations and not Euler angles. You integrate the
quaternion to get the rotation and then revert to
direction cosines so that you can construct the
rotation matrix directly (or its transpose, I do
not remember).
Do google searches for all words you do not quite
understand. You may be able to find example code
online as well, but what I described is quite
basic and will work if implimented correctly. Good
luck.
One more thing. If you are using some Windows
machine or whatever, use SDL to handle the events
that you need to trap. I prefer to use my own event
loop so I do not use SDL, but it is good for the
person who asks questions like yours.