Better controll when using the mouse

Epimetheus

18-03-2006 17:54:03

I wonder if there are anyone out there who has a good suggestion on how to increase the responsiveness to the mouse movement when controlling something via applying force?

BergBoy

21-03-2006 01:46:01

I use inverse dynamics so that the mouse turn speed is consistant (appears like its not even being turned by forces). YOu just need to remember that:

A = (V1 - V2) / DT

Where A is the acceleration (or amount of force we will apply), V1 is our old velocity, V2 is our desired velocity and DT is our timestep. V2 should be a constant turn rate so set up a constant in your code. Heres some code I made earlier:

//Look up and down is done directly on the camera Node - Like a head tilt
m_camNode->pitch(mRotY);
//Turn our camera - requires torque because we use the body
//1) get difference to show how much to yaw
Ogre::Radian rotateValue = mRotX - mPrevRotX;
mPrevRotX = mRotX;
// ****
// A = (V1 - V2) / DT
// ****
//2) Create the value that will become our desired turn speed (V1)
float newTorque = mPrevRotX.valueAngleUnits() * 700;
//3) Get our current Torque (hope thats as easy as it sounds...)
float oldTorque = me->getOmega().y;
//4) new - old
newTorque -= oldTorque;
//5) now apply it
me->setOmega(Ogre::Vector3(0,0,0));
Ogre::Vector3 turnVec = Ogre::Vector3(0, newTorque, 0);
me->addTorque(turnVec);
// VIVA LA RAZA!!!!!!11111


Thats code is straight from my little game so let me explain (yeah, I know its hacky. My timestep is always 1 so im good). mRotY and mRotX are relative mouse values and mPrevRotX is the last used mRotX. So the difference between those two values gets us our desired amount of turn since the last callback. This is the ammount of turn we would have if we wernt using forces. The result is a constant turn rate.

The above code is hacky but works btw. My camera is on a second node on top of a physics object representing the player. That object is an elipsoid and has an up vector to hold it upright. This is why the camera is allowed to freely look up and down without forces.

Epimetheus

21-03-2006 15:49:26

Thanks, i just hope it works in my application too :D
ill get back to anyone interseted with the result when i get back to coding.

[edit]
hmm... i couldn't really figure out how to apply this to force movement :S
solidBody* controller = solidBody::sBodies["padcontroller"];
Vector3 pull_pos = controller->getPosition();
Vector3 dir = pull_pos - pos;
Vector3 vel = body->getVelocity();
Real dist = dir.length();
Vector3 speed = Vector3(1,1,1) * dist * 700;
Vector3 delta = speed - vel;

body->setVelocity(Vector3(0,0,0));

force -= delta;

body->setForce(force);

[/edit]

BergBoy

22-03-2006 03:08:45

In my above code I havnt used DeltaT (naughty code...). All I did was took the turn rate I wanted (which was taken straight from Ogres mouse and had its previous value subtracted - thus getting the difference) and then subtracted that value from the current value. You said you were doing this to the camera so you want to rotate using Torque. Omega is rotational velocity.

Take DT out of it for a bit:

A = V1 - V2

Simple really, its the difference between our current omega and our desired omega. We are adding the PERFECT amount of torque to make our omega the same as the desired omega but while using force.

Epimetheus

22-03-2006 10:40:51

You said you were doing this to the camera...

Uhm... no i didn't :shock:

Anyway, thanks for the tips, im pretty sure i wouldn't have figure out this by my self either and sometime soon i will probably want to rotate my camera too.

BergBoy

23-03-2006 11:39:45

Well, regardless of if your rotating your camera or your avatar it will be the same theory. I had assumed you were rotating the camera via the mouse. Sorry.