PDA

View Full Version : scene interaction



08-05-2002, 12:58 AM
Hi,

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.

Thanks.

Gavin
08-05-2002, 01:12 AM
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?

08-05-2002, 10:15 AM
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.

08-05-2002, 05:46 PM
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?

08-05-2002, 06:33 PM
oh & also, like you said, I want to the rotation abt the central axis of the object. How do I determine this?

Niftybitz
08-05-2002, 11:15 PM
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
const int MOUSE_SENSITIVITY=10;

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

Your window procedure:

case WM_MOUSEMOVE:

if(First WM_MOUSEMOVE Message)
{
startx=LOWORD(lParam);
starty=HIWORD(lParam);
dispx=startx; //Rotation angle of 0
dispy=starty;
}
else
{
dispx=LOWORD(lParam)-startx;
dispy=HIWORD(lParam)-starty;
startx=LOWORD(lParam);
starty=HIWORD(lParam);
}

Your render procedure:

xangle=(GLfloat)dispy/MOUSE_SENSITIVITY;
yangle=(GLfloat)dispx/MOUSE_SENSITIVITY;

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.

Ciao,

Niftybitz.

08-06-2002, 06:34 PM
hey thanks for the help niftybitz. Will try it out http://www.opengl.org/discussion_boards/ubb/smile.gif