Exemplo n.º 1
0
        public SteeringBehavior(MovingEntity agent)
        {
            m_parentMovingEntity = agent;
            m_iFlags = 0;
            m_dDBoxLength = SteerParams.Instance.MinDetectionBoxLength;
            m_dWeightCohesion = SteerParams.Instance.AppliedCohesionWeight();
            m_dWeightAlignment = SteerParams.Instance.AppliedAlignmentWeight();
            m_dWeightSeparation = SteerParams.Instance.AppliedSeparationWeight();
            m_dWeightObstacleAvoidance = SteerParams.Instance.AppliedObstacleAvoidanceWeight();
            m_dWeightWander = SteerParams.Instance.AppliedWanderWeight();
            m_dWeightWallAvoidance = SteerParams.Instance.AppliedWallAvoidanceWeight();
            m_dViewDistance = SteerParams.Instance.ViewDistance;
            m_dWallDetectionFeelerLength = SteerParams.Instance.WallDetectionFeelerLength;
            m_Feelers = new List<Vector2D>(3);
            m_Deceleration = Deceleration.normal;
            m_pTargetAgent1 = null;
            m_pTargetAgent2 = null;
            m_dWanderDistance = WanderDist;
            m_dWanderJitter = WanderJitterPerSec;
            m_dWanderRadius = WanderRad;
            m_dWaypointSeekDistSq = WaypointSeekDist * WaypointSeekDist;
            m_dWeightSeek = SteerParams.Instance.AppliedSeekWeight();
            m_dWeightFlee = SteerParams.Instance.AppliedFleeWeight();
            m_dWeightArrive = SteerParams.Instance.AppliedArriveWeight();
            m_dWeightPursuit = SteerParams.Instance.AppliedPursuitWeight();
            m_dWeightOffsetPursuit = SteerParams.Instance.AppliedOffsetPursuitWeight();
            m_dWeightInterpose = SteerParams.Instance.AppliedInterposeWeight();
            m_dWeightHide = SteerParams.Instance.AppliedHideWeight();
            m_dWeightEvade = SteerParams.Instance.AppliedEvadeWeight();
            m_dWeightFollowPath = SteerParams.Instance.AppliedFollowPathWeight();
            m_SummingMethod = summing_method.prioritized;

            //stuff for the wander behavior
            double theta = Utils.RandFloat() * Utils.TwoPi;

            //create a vector to a target position on the wander circle
            m_vWanderTarget = new Vector2D(m_dWanderRadius * Math.Cos(theta), m_dWanderRadius * Math.Sin(theta));

            //create a Path
            m_pPath = new Path2D(true);

            m_vSteeringForce = new Vector2D();

        }
Exemplo n.º 2
0
        private Path2D CreateRandomPath()
        {
            Path2D pPath = new Path2D(true);
            List<Vector2D> listWayPoints = new List<Vector2D>();

            int NumWaypoints = 8;
            double MinX = m_bordersize;
            double MinY = m_bordersize;
            double MaxX = m_cxClient - m_bordersize;
            double MaxY = m_cyClient - m_bordersize;

            double midX = (MaxX + MinX) / 2.0;
            double midY = (MaxY + MinY) / 2.0;

            double smaller = Math.Min(midX, midY);

            double spacing = Utils.TwoPi / (double)NumWaypoints;

            for (int i = 0; i < NumWaypoints; ++i)
            {
                double RadialDist = Utils.RandInRange(smaller * 0.2f, smaller);

                Vector2D temp = new Vector2D(RadialDist, 0.0f);

                Utils.Vec2DRotateAroundOrigin(temp, i * spacing);

                temp.X += midX;
                temp.Y += midY;

                bool bOverlapped = false;

                foreach (BaseGameEntity objObs in m_Obstacles)
                {
                    if (Utils.PointInCircle(objObs.Pos, objObs.BRadius, temp))
                    {
                        bOverlapped = true;
                        break;
                    }
                }

                if (!bOverlapped) listWayPoints.Add(temp);

            }

            pPath.Set(listWayPoints);

            return pPath;
        }
Exemplo n.º 3
0
        private void RenderPath2D(Path2D objPath2D, Graphics objGraphics, Pen objPen)
        {
            if (objPath2D.GetPath().Count > 1)
            {
                IEnumerator<Vector2D> nextVec = objPath2D.GetPath().GetEnumerator();
                nextVec.MoveNext();

                int intCount = 0;

                foreach (Vector2D objVec in objPath2D.GetPath())
                {
                    intCount = intCount + 1;

                    if (!nextVec.MoveNext() && objPath2D.Loop)
                    {
                        nextVec.Reset();
                        nextVec.MoveNext();           
                    }

                    if (Vector2D.IsNull(nextVec.Current)){ break;}

                    objGraphics.DrawLine(objPen, (PointF)objVec, (PointF)nextVec.Current);
                    objGraphics.DrawString(intCount.ToString(), mFont, Brushes.YellowGreen, (float)objVec.X, (float)objVec.Y);

                }
            }
        }
Exemplo n.º 4
0
	    public void Set(Path2D path)
        {
            m_WayPoints = path.GetPath();
            m_curWaypoint = m_WayPoints.GetEnumerator();

            m_bLooped = path.Loop;

            m_curWaypoint.MoveNext(); // set the first item ready to go
        }