void PlayerVehicle::update(const float currentTime, const float elapsedTime)
{
	PhysicalThing* pt = mActor->getPhysicalThing();
	OgreNewt::Body* body = NULL;
	if(pt) pt->_getBody();
	if(body)
	{
		Vector3 position;
		Quaternion orientation;
		body->getPositionOrientation(position, orientation);
		setPosition(Vec3(position.x, position.y, position.z));

	//  Get the velocity vector
		mCurrentVelocity = body->getVelocity();
	//  enforce speed limit
	//  newVelocity = newVelocity.truncateLength (maxSpeed ());
	//  update speed
		setSpeed(mCurrentVelocity.length());
		Vec3 newVelocity(mCurrentVelocity.x, mCurrentVelocity.y, mCurrentVelocity.z);

	//  regenerate local space (by default: align vehicle's forward axis with
	//  new velocity, but this behavior may be overridden by derived classes.)
		if (speed() > 0) regenerateOrthonormalBasisUF (newVelocity / speed());

	//  prevent adding a counter force against gravity
		if (mCurrentVelocity.y < 0.0f) mCurrentVelocity.y = 0.0f;
	}
	mCurrentForce = Ogre::Vector3::ZERO;
}
    void StepRecognitionMovement::calculateForceAndTorque(Vector3 &force, Vector3 &torque, Real timestep)
    {
        // move to nextTarget
        if( mMoveToNextTarget )
        {
            Real mass;
            Vector3 inertia;
            OgreNewt::Body *body = mMovingCreature->getCreature()->getActor()->getPhysicalThing()->_getBody();
            body->getMassMatrix(mass, inertia);

            Vector3 pos = mMovingCreature->getCreature()->getPosition();
            Vector3 diff = mNextTarget - pos;

            Vector3 vel = body->getVelocity();

            force.y = mass*( mLinearSpringK*diff.y - mLinearDampingK*vel.y );
            std::ostringstream oss;
            oss << "Step-Recognition: diff: " << diff.y << "    vel: " << vel.y << "    Step force: " << force.y;
            oss << "    DiffToTarget: " << 
                mMovingCreature->getCreature()->getOrientation().Inverse() * 
                (mNextTarget - mMovingCreature->getCreature()->getPosition());
            LOG_MESSAGE(Logger::RULES, oss.str());
        }
    }
void SteeringVehicle::update(const float currentTime, const float elapsedTime)
{
    SimpleVehicle::update(currentTime, elapsedTime);

    Vector3 pos = mCreature->getPosition();
	setPosition(pos);
    
    OgreNewt::Body* body = mCreature->getActor()->getPhysicalThing()->_getBody();
    //  Get the velocity vector
	mCurrentVelocity = body->getVelocity();
	//  enforce speed limit
	//  newVelocity = newVelocity.truncateLength(maxSpeed());
	//  update speed
	setSpeed(mCurrentVelocity.length());
	Vector3 newVelocity(mCurrentVelocity);

    //  regenerate local space(by default: align vehicle's forward axis with
    //  new velocity, but this behavior may be overridden by derived classes.)
    // use future orientation or not??
    Quaternion orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y);
    Vector3 newUnitForward = orientation*Vector3::NEGATIVE_UNIT_Z;
    regenerateOrthonormalBasisUF(newUnitForward);

    // only process if mMovingCreature not NULL
    if (mController == NULL || mCreature->getQueryFlags() & QUERYFLAG_PLAYER)
    {
        mCurrentForce = Vector3::ZERO;
        return;
    }
    
    // calculate the result of the force    
    Vector3 result = mCurrentForce;// + mCurrentVelocity;
    
    mDebugSteer = mCurrentForce;

    // @todo remove this
    if (mCreature->getAu() <= 6)
        mCreature->modifyAu(20,true);

    AbstractMovement* mov_drehen = mController->getMovementFromId(CreatureController::MT_DREHEN);
    Real vel_drehen(0);
    Radian max_drehen = Degree(0);
    if (mov_drehen->calculateBaseVelocity(vel_drehen))
    {
        max_drehen = Degree(vel_drehen * 360 * elapsedTime);
    }

    Ogre::Quaternion future_orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y);
    Ogre::Vector3 creatureDirection = future_orientation * Ogre::Vector3::NEGATIVE_UNIT_Z;
    Radian yaw(0);
    creatureDirection.y = result.y = 0;
    yaw = creatureDirection.getRotationTo(result, Ogre::Vector3::UNIT_Y).getYaw();
    if (yaw > Radian(0) && yaw > max_drehen)
        yaw = max_drehen;
    if (yaw < Radian(0) && yaw < -max_drehen)
        yaw = -max_drehen;

    Ogre::Vector3 direction(Ogre::Vector3::ZERO);
    Ogre::Vector3 rotation(0,yaw.valueRadians(),0);
    CreatureController::MovementType movement = CreatureController::MT_STEHEN;
    if (result != Ogre::Vector3::ZERO)
    {
        direction.z = -1;
        movement = CreatureController::MT_GEHEN;
    }

    mController->setMovement(movement, direction, rotation);
    LOG_DEBUG(Logger::AI, "SteeringVehicle: mController->setMovement " + 
        Ogre::StringConverter::toString(movement) + ", "
        + Ogre::StringConverter::toString(direction) + ", "
        + Ogre::StringConverter::toString(rotation));

	mCurrentForce = Ogre::Vector3::ZERO;
}