View Full Version : mouse rotation
I draw a grid on the zx plain like in any 3d editing software (maya, 3dmax) and I am trying to have the same mouse rotation movement. What I mean is that when the user clicks with his mouse he can rotate the grid around like in Maya and 3dmax. Would anybody know how to do this, or maybe a tutorial on it? Thanks in advance.
07-05-2004, 10:44 AM
It is quite easy.
Lets say the world z axis aims at you, the x to the right, the y goes up. The tricky part is that you may want to rotate around z first, then around x. But the order of operations is counter intuitive.
Get the mouse movement delta in the x and y screen axis. accumelate on some global x and y varaibles :
now lets, start :
<draw your grid and world>
You will want to clamp your xrot to an interval like [-90;90] or even more restrictive.
Some people prefer when the 2 rotations are exchanged (it is even the default mode for Blender) I really do not understand why. Anyway.
I hope it helps.
what is the "mouse movement delta" and do i need to use some sort of equation to get it?
07-05-2004, 06:15 PM
Originally posted by <ugor>:
what is the "mouse movement delta" and do i need to use some sort of equation to get it?i think some api's have that info for you but just in case they don't, you can do something like this:
// just an example
int, x, y, oldx, oldy;
void mouse_callback(int x, int y, mouseinfo &mouse)
mouse.oldx = mouse.x;
mouse.oldy = mouse.y;
mouse.x = x;
mouse.y = y;
int deltax = mouse.x - mouse.oldx;
int deltay = mouse y - mouse.oldy;... something along those lines. hope that gets you in the right direction.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.