Controlling a rigid body from user input

Post Reply
Nyx Erebos
Posts: 4
Joined: Sun Sep 08, 2013 8:50 pm

Controlling a rigid body from user input

Post by Nyx Erebos »

I'm trying to rotate a rigid from the mouse movement (I'm using bullet 2.81 and irrlicht 1.8 ) but I have a problem figuring out how to do it :

Code: Select all

//mousePosition is the relative position of the mouse, (0,0) is the upper left corner and (1,1) the lower right corner
//left/right rotation, I substract 0.5 to get a number between -0.5 and 0.5
float rotationOverY = mousePosition.X - 0.5;
//up/down rotation
float rotationOverX = mousePosition.Y - 0.5;

btVector3 angularVelocity = btVector3(rotationOverX,rotationOverY,0);

myRigidBody->setAngularVelocity(angularVelocity*100);
//the velocity is set back to (0,0,0) when the mouse stop moving
When I try to rotate only over x or only over y it works fine but when I move the mouse randomly it doesn't work anymore. Namely if I rotate 90° (or -90°) over y (so right/left) and then try to rotate over x (so up/down) the body rotates on itself over z. Another weird behaviour is when the body rotates 180° over y (looking back), up and down are inverted. Looks like a local/world rotation problem so I guess that I don't understand how to use setAngularVelocity. If someone can tell me what I'm doing wrong it would help me :)
Post Reply