コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
 public Vehicle(GameWorld world, Vector2 position, float rotation, Vector2 velocity, float mass)
 {
     this.world    = world;
     this.position = position;
     this.heading  = new Vector2((float)+Math.Sin(rotation), (float)-Math.Cos(rotation));
     this.side     = Helper2.Perp(this.heading);
     steering      = new SteeringBehavior(this);
     this.mass     = mass;
     this.maxSpeed = 150.0f;
     this.maxForce = 2.0f * SteeringBehavior.steeringForceTweaker;
 }