Example #1
0
        public Vector2 CalculateWeightedSum()
        {
            if (On(behavior_type.seek))
            {
                steeringForce += Seek(vehicle.World.Crosshair) * weightSeek;
            }

            if (On(behavior_type.flee))
            {
                steeringForce += Flee(vehicle.World.Crosshair) * weightFlee;
            }

            if (On(behavior_type.arrive))
            {
                steeringForce += Arrive(vehicle.World.Crosshair, 2) * weightArrive;
            }

            if (On(behavior_type.pursuit))
            {
                steeringForce += Pursuit(TargetAgent1) * weightPursuit;
            }

            if (On(behavior_type.evade))
            {
                steeringForce += Evade(TargetAgent1) * weightEvade;
            }

            if (On(behavior_type.wander))
            {
                steeringForce += Wander() * weightWander;
            }

            Helper2.Truncate(ref steeringForce, vehicle.MaxForce);
            return(steeringForce);
        }
Example #2
0
        public void Update(double time_elapsed)
        {
            this.TimeElapsed = time_elapsed;

            //calculate the combined force from each steering behavior in the
            //vehicle's list
            Vector2 steeringForce = steering.Calculate();

            //Acceleration = Force/Mass
            Vector2 acceleration = steeringForce * (float)(1 / mass);

            //update velocity
            velocity += acceleration * (float)time_elapsed;

            //make sure vehicle does not exceed maximum velocity
            Helper2.Truncate(ref velocity, maxSpeed);

            //update the position
            position += velocity * (float)time_elapsed;

            //update the heading if the vehicle has a non zero velocity
            if (velocity.LengthSq() > 0.00000001)
            {
                heading = Vector2.Normalize(velocity);
                side    = Helper2.Perp(heading);
            }

            //treat the screen as a toroid
            Helper2.WrapRound(ref position, world.cxClient, world.cyClient);
        }