Vector3 SteeringVehicle::calcWander(const float elapsedTime) { Vector3 steering = mForwardVector; steering += Vec3Utils::setYtoZero(steerForWander(elapsedTime/12.0f)); mDebugWander = steering; return steering; }
//----------------------------------------------------------------------------- // compute combined steering force: move forward, avoid obstacles // or neighbors if needed, otherwise follow the path and wander osVector3 Pedestrian::determineCombinedSteering (const float elapsedTime) { // note: to enable a better view on a remote vehicle we just // skip computing a steering force for these guys // it is the model to use anyways // AI code has nothing todo on the remote side if( isRemoteObject() ) { return osVector3::zero; } // move forward osVector3 steeringForce = forward(); // probability that a lower priority behavior will be given a // chance to "drive" even if a higher priority behavior might // otherwise be triggered. // const float leakThrough = 0.1f; // no random behaviour for network samples const float leakThrough = -1.0f; // determine if obstacle avoidance is required osVector3 obstacleAvoidance; if (leakThrough < frandom01()) { const float oTime = 6; // minTimeToCollision = 6 seconds // ------------------------------------ xxxcwr11-1-04 fixing steerToAvoid // just for testing // obstacleAvoidance = steerToAvoidObstacles (oTime, gObstacles); // obstacleAvoidance = steerToAvoidObstacle (oTime, gObstacle1); // obstacleAvoidance = steerToAvoidObstacle (oTime, gObstacle3); obstacleAvoidance = steerToAvoidObstacles (oTime, gObstacles); // ------------------------------------ xxxcwr11-1-04 fixing steerToAvoid } // if obstacle avoidance is needed, do it if (obstacleAvoidance != osVector3::zero) { steeringForce += obstacleAvoidance; } else { // otherwise consider avoiding collisions with others osVector3 collisionAvoidance; const float caLeadTime = 3; // find all neighbors within maxRadius using proximity database // (radius is largest distance between vehicles traveling head-on // where a collision is possible within caLeadTime seconds.) const float maxRadius = caLeadTime * maxSpeed() * 2; if( _proximityToken != nullptr) { _neighbors.clear(); _proximityToken->findNeighbors (position(), maxRadius, _neighbors); } // allways avoid neighbors // if (leakThrough < frandom01()) { collisionAvoidance = steerToAvoidNeighbors (caLeadTime, _neighbors) * 10; } // if collision avoidance is needed, do it if (collisionAvoidance != osVector3::zero) { steeringForce += collisionAvoidance; } else { #if 0 NetPedestrianPlugin* netPedestrianPlugin = dynamic_cast<NetPedestrianPlugin*>(getParentEntity()); // add in wander component (according to user switch) if (netPedestrianPlugin->m_bWanderSwitch) steeringForce += steerForWander (elapsedTime); #endif // do (interactively) selected type of path following const float pfLeadTime = 3; const bool useDirectPathFollowing(true); const osVector3 pathFollow = (useDirectPathFollowing ? //(netPedestrianPlugin->m_bUseDirectedPathFollowing ? steerToFollowPath (pathDirection, pfLeadTime, *path) : steerToStayOnPath (pfLeadTime, *path)); // add in to steeringForce steeringForce += pathFollow * 0.5; } } #if OPENSTEER_Z_ISUP // return steering constrained to global XY "ground" plane return steeringForce.setZtoZero(); #else // return steering constrained to global XZ "ground" plane return steeringForce.setYtoZero(); #endif }