Exemplo n.º 1
0
void 
OpenSteer::SimpleVehicle::regenerateLocalSpaceForBanking (const Vec3& newVelocity,
                                                          const float elapsedTime)
{
    // the length of this global-upward-pointing vector controls the vehicle's
    // tendency to right itself as it is rolled over from turning acceleration
    const Vec3 globalUp (0, 0.2f, 0);

    // acceleration points toward the center of local path curvature, the
    // length determines how much the vehicle will roll while turning
    const Vec3 accelUp = _smoothedAcceleration * 0.05f;

    // combined banking, sum of UP due to turning and global UP
    const Vec3 bankUp = accelUp + globalUp;

    // blend bankUp into vehicle's UP basis vector
    const float smoothRate = elapsedTime * 3;
    Vec3 tempUp = up();
    blendIntoAccumulator (smoothRate, bankUp, tempUp);
    setUp (tempUp.normalize());

//  annotationLine (position(), position() + (globalUp * 4), gWhite);  // XXX
//  annotationLine (position(), position() + (bankUp   * 4), gOrange); // XXX
//  annotationLine (position(), position() + (accelUp  * 4), gRed);    // XXX
//  annotationLine (position(), position() + (up ()    * 1), gYellow); // XXX

    // adjust orthonormal basis vectors to be aligned with new velocity
    if (speed() > 0) regenerateOrthonormalBasisUF (newVelocity / speed());
}
Exemplo n.º 2
0
void 
OpenSteer::SimpleVehicle::regenerateLocalSpace (const Vec3& newVelocity,
                                                const float /* elapsedTime */)
{
    // adjust orthonormal basis vectors to be aligned with new velocity
    if (speed() > 0) regenerateOrthonormalBasisUF (newVelocity / speed());
}
void SteeringVehicle::resetLocalSpace()
{
	setForward(mForwardVector);
	setSide(localRotateForwardToSide(getForward()));
    setUp(Vector3::UNIT_Y);
	Vector3 pos = mCreature->getPosition();
	setPosition(pos);
	Vector3 src = mCreature->getOrientation()*Vector3::NEGATIVE_UNIT_Z;

    // regenerate local space(by default: align vehicle's forward axis with
    // new velocity, but this behavior may be overridden by derived classes.)
	regenerateOrthonormalBasisUF(src);
}
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;
}