void Kinematic::calcNewVelocities( const Steering& theSteering, float time, float maxSpeed, float maxRotationalVelocity ) { mVelocity += theSteering.getLinear() * time; mRotationVel += theSteering.getAngular() * time; //cap the velocities capVelocity( maxSpeed ); if( mRotationVel > maxRotationalVelocity ) { mRotationVel = maxRotationalVelocity; } }
void KinematicUnit::update(float time) { Steering* steering; if( mpCurrentSteering != NULL ) { steering = mpCurrentSteering->getSteering(); } else { steering = &gNullSteering; } if( steering->shouldApplyDirectly() ) { //not stopped if( getVelocity().getLengthSquared() > MIN_VELOCITY_TO_TURN_SQUARED ) { setVelocity( steering->getLinear() ); setOrientation(steering->getAngular() ); //setNewOrientation(); } //since we are applying the steering directly we don't want any rotational velocity setRotationalVelocity( 0.0f ); steering->setAngular( 0.0f ); } else { setNewOrientation(); //updates the orientation of most types } //move the unit using current velocities Kinematic::update( time ); //calculate new velocities calcNewVelocities( *steering, time, mMaxVelocity, 25.0f ); //move to oposite side of screen if we are off GRAPHICS_SYSTEM->wrapCoordinates( mPosition ); //set the orientation to match the direction of travel //setNewOrientation(); }