//----------------------------------------------------------------------------- // (parameter names commented out to prevent compiler warning from "-W") void Pedestrian::annotateAvoidNeighbor (const AbstractVehicle& threat, const float /*steer*/, const osVector3& ourFuture, const osVector3& threatFuture) { const Color green (0.15f, 0.6f, 0.0f); annotationLine( position(), ourFuture, green ); annotationLine( threat.position(), threatFuture, green ); annotationLine( ourFuture, threatFuture, gRed ); annotationXZCircle( radius(), ourFuture, green, 12 ); annotationXZCircle( radius(), threatFuture, green, 12 ); }
void OpenSteer::SimpleVehicle::annotationVelocityAcceleration (float maxLengthA, float maxLengthV) { const float desat = 0.4f; const float aScale = maxLengthA / maxForce (); const float vScale = maxLengthV / maxSpeed (); const Vec3& p = position(); const Vec3 aColor (desat, desat, 1); // bluish const Vec3 vColor ( 1, desat, 1); // pinkish annotationLine (p, p + (velocity () * vScale), vColor); annotationLine (p, p + (_smoothedAcceleration * aScale), aColor); }
//----------------------------------------------------------------------------- // xxx perhaps this should be a call to a general purpose annotation for // xxx "local xxx axis aligned box in XZ plane" -- same code in in // xxx CaptureTheFlag.cpp void Pedestrian::annotateAvoidObstacle( const float minDistanceToCollision ) { const osVector3 boxSide = side() * radius(); const osVector3 boxFront = forward() * minDistanceToCollision; const osVector3 FR = position() + boxFront - boxSide; const osVector3 FL = position() + boxFront + boxSide; const osVector3 BR = position() - boxSide; const osVector3 BL = position() + boxSide; const Color white( 1,1,1 ); annotationLine( FR, FL, white ); annotationLine( FL, BL, white ); annotationLine( BL, BR, white ); annotationLine( BR, FR, white ); }
OpenSteer::Vec3 OpenSteer::SimpleVehicleAnnotated::steerForPursuit(const OpenSteer::AbstractVehicle& quarry, const float maxPredictionTime) { int forward, parallel; Vec3 target, colour; Vec3 ret = SimpleVehicle_2::steerForPursuit(quarry, maxPredictionTime, forward, parallel, target); switch (forward) { case +1: switch (parallel) { case +1: // ahead, parallel colour = gBlack; break; case 0: // ahead, perpendicular colour = gGray50; break; case -1: // ahead, anti-parallel colour = gWhite; break; } break; case 0: switch (parallel) { case +1: // aside, parallel colour = gRed; break; case 0: // aside, perpendicular colour = gYellow; break; case -1: // aside, anti-parallel colour = gGreen; break; } break; case -1: switch (parallel) { case +1: // behind, parallel colour= gCyan; break; case 0: // behind, perpendicular colour= gBlue; break; case -1: // behind, anti-parallel colour = gMagenta; break; } break; } // annotation annotationLine (position(), target, gaudyPursuitAnnotation ? colour : gGray40); return ret; }
//----------------------------------------------------------------------------- // called when steerToFollowPath decides steering is required void Pedestrian::annotatePathFollowing (const osVector3& future, const osVector3& onPath, const osVector3& target, const float outside) { const Color yellow (1, 1, 0); const Color lightOrange (1.0f, 0.5f, 0.0f); const Color darkOrange (0.6f, 0.3f, 0.0f); const Color yellowOrange (1.0f, 0.75f, 0.0f); // draw line from our position to our predicted future position annotationLine (position(), future, yellow); // draw line from our position to our steering target on the path annotationLine (position(), target, yellowOrange); // draw a two-toned line between the future test point and its // projection onto the path, the change from dark to light color // indicates the boundary of the tube. const osVector3 boundaryOffset = (onPath - future).normalized() * outside; const osVector3 onPathBoundary = future + boundaryOffset; annotationLine (onPath, onPathBoundary, darkOrange); annotationLine (onPathBoundary, future, lightOrange); }
float3 OpenSteer::SteerLibrary:: steerForPursuit (const AbstractVehicle& v, const AbstractVehicle& quarry, const float maxPredictionTime) { // offset from this to quarry, that distance, unit vector toward quarry const float3 offset = float3_subtract(make_float3(quarry.position()), make_float3(v.position())); const float distance = float3_length(offset); const float3 unitOffset = float3_scalar_divide(offset, distance); // how parallel are the paths of "this" and the quarry // (1 means parallel, 0 is pependicular, -1 is anti-parallel) const float parallelness = float3_dot(make_float3(v.forward()), make_float3(quarry.forward())); // how "forward" is the direction to the quarry // (1 means dead ahead, 0 is directly to the side, -1 is straight back) const float forwardness = float3_dot(make_float3(v.forward()), unitOffset); const float directTravelTime = distance / v.speed (); const int f = intervalComparison (forwardness, -0.707f, 0.707f); const int p = intervalComparison (parallelness, -0.707f, 0.707f); float timeFactor = 0; // to be filled in below float3 color; // to be filled in below (xxx just for debugging) // Break the pursuit into nine cases, the cross product of the // quarry being [ahead, aside, or behind] us and heading // [parallel, perpendicular, or anti-parallel] to us. switch (f) { case +1: switch (p) { case +1: // ahead, parallel timeFactor = 4; color = gBlack; break; case 0: // ahead, perpendicular timeFactor = 1.8f; color = gGray50; break; case -1: // ahead, anti-parallel timeFactor = 0.85f; color = gWhite; break; } break; case 0: switch (p) { case +1: // aside, parallel timeFactor = 1; color = gRed; break; case 0: // aside, perpendicular timeFactor = 0.8f; color = gYellow; break; case -1: // aside, anti-parallel timeFactor = 4; color = gGreen; break; } break; case -1: switch (p) { case +1: // behind, parallel timeFactor = 0.5f; color= gCyan; break; case 0: // behind, perpendicular timeFactor = 2; color= gBlue; break; case -1: // behind, anti-parallel timeFactor = 2; color = gMagenta; break; } break; } // estimated time until intercept of quarry const float et = directTravelTime * timeFactor; // xxx experiment, if kept, this limit should be an argument const float etl = (et > maxPredictionTime) ? maxPredictionTime : et; // estimated position of quarry at intercept const float3 target = quarry.predictFuturePosition (etl); // annotation annotationLine (make_float3(v.position()), target, gaudyPursuitAnnotation ? color : gGray40); return steerForSeek (v, target); }