Пример #1
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            var target = FixVec2.Zero;

            if (!owner.TryGetTargetPosition(ref target))
            {
                return(SteeringVelocity.Zero);
            }

            var maxVelocity = owner.Get <MaxVelocity>().Value;
            var position    = owner.Get <Position>().Value;

            target.Sub(ref position);

            if (target.MagnitudeSqr == 0)
            {
                return(SteeringVelocity.Zero);
            }

            target.Normalize();
            target.Scale(ref maxVelocity);

            return(new SteeringVelocity
            {
                Linear = target
            });
        }
Пример #2
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            var steering = new SteeringVelocity();

            if (!owner.Has <FlowField>())
            {
                return(steering);
            }

            var flowField  = owner.Get <FlowField>().Field;
            var flowVector = flowField.LookupFlowVector(owner.Get <Position>().Value);

            if (!owner.Has <TargetOrientation>())
            {
                return(SteeringVelocity.Zero);
            }

            if (flowVector.MagnitudeSqr <= ZeroVelocity * ZeroVelocity)
            {
                return(SteeringVelocity.Zero);
            }

            var targetOrientation = FixMath.Atan2(-flowVector.X, flowVector.Y);

            return(DoReachOrientation(owner, targetOrientation));
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            if (!owner.Has <TargetOrientation>())
            {
                return(SteeringVelocity.Zero);
            }

            return(DoReachOrientation(owner, owner.Get <TargetOrientation>().Value));
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity steering)
        {
            var linearVelocity = steering.Linear;

            if (linearVelocity.MagnitudeSqr <= ZeroVelocity * ZeroVelocity)
            {
                return(SteeringVelocity.Zero);
            }

            var targetOrientation = FixMath.Atan2(-linearVelocity.X, linearVelocity.Y);

            return(DoReachOrientation(owner, targetOrientation));
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            var steering = new SteeringVelocity();

            if (!owner.Has <FlowField>())
            {
                return(steering);
            }

            var flowField   = owner.Get <FlowField>().Field;
            var flowVector  = flowField.LookupFlowVector(owner.Get <Position>().Value);
            var maxVelocity = owner.Get <MaxVelocity>().Value;

            steering.Linear = flowVector * maxVelocity;
            return(steering);
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _linear   = FixVec2.Zero;
            _position = owner.Get <Position>().Value;

            Proximity.FindNeighbors(owner, _proximityCallback);

            var maxVelocity = owner.Get <MaxVelocity>().Value;

            if (_linear.MagnitudeSqr == 0)
            {
                return(SteeringVelocity.Zero);
            }

            _linear.Normalize();
            _linear.Scale(ref maxVelocity);

            return(new SteeringVelocity(_linear));
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity steering)
        {
            var targetLocation = FixVec2.Zero;

            if (!owner.TryGetTargetPosition(ref targetLocation))
            {
                return(SteeringVelocity.Zero);
            }

            var direction = targetLocation - owner.Get <Position>().Value;

            if (direction.MagnitudeSqr <= ZeroVelocity * ZeroVelocity)
            {
                return(SteeringVelocity.Zero);
            }

            var targetOrientation = FixMath.Atan2(direction.Y, -direction.X);

            return(DoReachOrientation(owner, targetOrientation));
        }
Пример #8
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _averageVelocity = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                var maxVelocity = owner.Get <MaxVelocity>().Value;

                _averageVelocity /= neighborCount;

                if (_averageVelocity.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _averageVelocity.Normalize();
                _averageVelocity.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_averageVelocity));
        }
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedVelocity)
        {
            var steering           = SteeringVelocity.Zero;
            var maxVelocity        = Fix.MaxValue;
            var maxAngularVelocity = Fix.MaxValue;

            if (owner.Has <MaxVelocity>())
            {
                maxVelocity = owner.Get <MaxVelocity>().Value;
            }
            if (owner.Has <MaxAngularVelocity>())
            {
                maxAngularVelocity = owner.Get <MaxAngularVelocity>().Value;
            }

            foreach (var behaviour in _behaviours)
            {
                steering += behaviour.Calculate(owner, ref steering);
            }

            steering.Limit(maxVelocity, maxAngularVelocity);
            return(steering);
        }
Пример #10
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            _centroid = FixVec2.Zero;

            var neighborCount = Proximity.FindNeighbors(owner, _proximityCallback);

            if (neighborCount > 0)
            {
                _centroid /= neighborCount;
                _centroid -= owner.Get <Position>().Value;

                if (_centroid.MagnitudeSqr == 0)
                {
                    return(SteeringVelocity.Zero);
                }

                _centroid.Normalize();

                var maxVelocity = owner.Get <MaxVelocity>().Value;
                _centroid.Scale(ref maxVelocity);
            }

            return(new SteeringVelocity(_centroid));
        }
 public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
 {
     return(_behaviour.Calculate(owner, ref accumulatedSteering) * _weight);
 }
Пример #12
0
 public SteeringVelocity Calculate(Entity <Game> owner, ref SteeringVelocity velocity)
 {
     return(DoCalculate(owner, ref velocity));
 }
Пример #13
0
 public abstract SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering);
Пример #14
0
        public override SteeringVelocity DoCalculate(Entity <Game> owner, ref SteeringVelocity accumulatedSteering)
        {
            var target = FixVec2.Zero;

            return(owner.TryGetTargetPosition(ref target) ? Arrive(owner, target) : SteeringVelocity.Zero);
        }