Character Input Helper - Mouse Control

Senzin

01-12-2012 23:15:46

I'm trying to use the mouse to rotate an AnimatedCharacter via the CharacterInputHelper. I've looked through a lot of posts here, but short of editing the source, haven't seen any ways of getting proper usage.

The closest I've gotten is:


// mouseMoved
mTurn = Degree(-evt.state.X.rel * 0.25f);
...
// frameRenderingQueued
mCharHelper.turn(mTurn, Math::Abs(mTurn));

However, the rate of turn appears to be constant, regardless of the rate at which I move the mouse. If I do this:


mCharHelper.turn(Degree(45), Degree(45));

It still turns a tiny amount. I dug into the code and found this:


// CharacterInputHelper::turn
input.left_right = char(Ogre::Math::Clamp<Ogre::Real>(difference.valueDegrees() / maxTurningAngle.valueDegrees(), -1.0f, 1.0f) * 127.0f);

The turn angle is being divided by the max turn angle. I guess that's why when I was using Degree(360) as max, nothing happened. So it's not really a max, because the larger the value of max, the smaller the turn. And then, the result is clamped. So that explains why the turn rate appears to be constant. Why do this? What is 127? And why is everything a char?

I think my best bet really is to expose the mYaw and just do it myself. However, I also spotted this:


// CharacterBase::advanceAnimation
mNode->setOrientation(mYaw, mUpDirection);

mUpDirection appears to be an enum. So it looks like the controller forces characters to align to an axis. So basically, without heavy editing, this is not at all suited to controlling a character that can have arbitrary orientation (as in my case). At what level is this restriction applied? AnimatedCharacter? NxOgreCharacterController? Or all the way down to PhysX itself?

For my particular project, the character can jump to any surface and walk on it (think magnet boots). And the character probably won't be subjected to global gravity. What is the best starting point for a character controller for a character with these requirements?