private void RenderVehicle(MovingEntity objVehicle, Graphics objGraphics, Pen objPen) { PointF pntLeft,pntFront,pntRight; if (UseSmoothing) { Vector2D SmoothedPerp = objVehicle.SmoothedHeading().Perp(); pntLeft = (PointF)(objVehicle.Pos + (SmoothedPerp * objVehicle.BRadius)); pntFront = (PointF)(objVehicle.Pos + (objVehicle.SmoothedHeading() * (objVehicle.BRadius * 2))); pntRight = (PointF)(objVehicle.Pos - (SmoothedPerp * objVehicle.BRadius)); } else { pntLeft = (PointF)(objVehicle.Pos + (objVehicle.Side() * objVehicle.BRadius)); pntFront = (PointF)(objVehicle.Pos + (objVehicle.Heading() * (objVehicle.BRadius * 2))); pntRight = (PointF)(objVehicle.Pos - (objVehicle.Side() * objVehicle.BRadius)); } PointF[] points = new PointF[4]; points[0] = pntLeft; points[1] = pntFront; points[2] = pntRight; points[3] = pntLeft; objGraphics.DrawPolygon(objPen, points); }
//------------------------- Offset Pursuit ------------------------------- // // Produces a steering force that keeps a vehicle at a specified offset // from a leader vehicle //------------------------------------------------------------------------ public Vector2D OffsetPursuit(MovingEntity leader, Vector2D offset) { //calculate the offset's position in world space Vector2D WorldOffsetPos = Utils.PointToWorldSpace(offset, leader.Heading(), leader.Side(), leader.Pos); Vector2D ToOffset = WorldOffsetPos - m_parentMovingEntity.Pos; //the lookahead time is propotional to the distance between the leader //and the pursuer; and is inversely proportional to the sum of both //agent's velocities double LookAheadTime = ToOffset.Length() / (m_parentMovingEntity.MaxSpeed + leader.Speed()); //now Arrive at the predicted future position of the offset return Arrive(WorldOffsetPos + leader.Velocity * LookAheadTime, (int)Deceleration.fast); }
private void renderDetectionBox(MovingEntity objVehicle, Graphics objGraphics, Pen objPen) { List<Vector2D> points = new List<Vector2D>(); points.Add(new Vector2D(0, objVehicle.BRadius)); points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), objVehicle.BRadius)); points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), -objVehicle.BRadius)); points.Add(new Vector2D(0, -objVehicle.BRadius)); if (UseSmoothing) { points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.SmoothedHeading(), objVehicle.SmoothedHeading().Perp()); } else { points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.Heading(), objVehicle.Side()); } objGraphics.DrawLine(objPen, (PointF)points[0], (PointF)points[1]); objGraphics.DrawLine(objPen, (PointF)points[1], (PointF)points[2]); objGraphics.DrawLine(objPen, (PointF)points[2], (PointF)points[3]); }