scene interaction


Can anyone tell me what the best way to implement interaction with the objects in the scene? eg. using the keyboard to rotate an object. I want the object to rotate a fixed amount every time the user presses a key and be able to accumulate the transformations. It doesn’t seem to work if I simply don’t clear the modelview matrix. I get unexpected results.


I assume you mean unexpected in that the way in which it rotates is that the axis is not centered where you thought it was, all that is happening is that the x,y,z axis rotate and the rotations you apply are about these axis. I assume you you want is more of a trackball effect?

To interact with the scene, just smack the monitor forcefully with the ball of your hand, and the scene will rock back and forth for a second or two. If your hand hurts, your system also supports force feedback.

yes I think I want to use something like Shoemake’s arcball? can’t find the original source code to look at it though…any better solutions?

oh & also, like you said, I want to the rotation abt the central axis of the object. How do I determine this?

Hi there!

In theory a trackball effect is very simple. Don’t need source from some well known implementation. Here is how you can do it. Every time respond at the WM_MOUSEMOVE message (or use DirectInput for the case) and at the first time you receive such a message, you remember the x and y coords of the mouse in tow variables named for example startx and starty. Now if you receive a following WM_TIMER message, you need to more variable to store the difference between the old position and the new position. Let’s name them dispx and dispy. So you would simply say then, that dispx=new x value - startx and dispy=new y value - starty. That gives you the difference. But afterwards don’t forget to make startx equal to the new x value again as the same goes for the starty, because the next time you receive a WM_MOUSEMOVE again, you need the difference between the previous x and y coords from the mouse.

Now what you can do with these values dispx and dispy is that you use the dispx as a rotation angle around the y-axis and the dispy as a rotation angle around the x-axis. But this would create a very fast rotation, so be sure to divide both dispx and dispy by some constant that you may call MOUSE_SENSITIVY. Some pseudo code follows:

Variables and constants:

//Sensitivity of mouse. Lower value means
//more sensitive mouse movement

int startx,starty,dispx,dispy;
GLfloat Xangle,Yangle;

Your window procedure:


if(First WM_MOUSEMOVE Message)
dispx=startx; //Rotation angle of 0

Your render procedure:


This would go for a nice mouse tracker. Fast movement of the mouse results in a fast rotation of your objects.

Hope you understood it. If not, mail me.



hey thanks for the help niftybitz. Will try it out