Esempio n. 1
0
        // Methods
        public void Run(float deltaTime)
        {
            if (this.vehicleIndex < 0)
            {
                return;
            }
            if (AIRegionsDS == null)
            {
                if (AIRegions == null)
                {
                    return;
                }
                AIRegionsDS = AIRegions.GetDrawingSurface();
            }
            float angleSum = 0f;
            int   agscolor = AIRegionsDS.GetPixel(FloatToInt(Cars[this.vehicleIndex].position.x, eRoundNearest), FloatToInt(Cars[this.vehicleIndex].position.y, eRoundNearest));
            int   i        = 0;

            for (i = 0; i < 16; i += 1)
            {
                if (RegionAngles[i].color == agscolor)
                {
                    angleSum = RegionAngles[i].angle;
                    break;
                }
            }
            this.targetAngle = angleSum;
            float dirAngle     = Cars[this.vehicleIndex].direction.angle();
            float angleBetween = Maths.AnglePiFast(this.targetAngle - Maths.Angle2Pi(dirAngle));
            float steeringDT   = UISteeringAngle * deltaTime * 1.1f;

            if (Maths.AbsF(angleBetween) <= Maths.AbsF(steeringDT))
            {
                Cars[this.vehicleIndex].steeringWheelAngle = 0.0f;
                Cars[this.vehicleIndex].direction.set2(1.0f, 0.0f);
                Cars[this.vehicleIndex].direction.rotate(this.targetAngle);
            }
            else if (angleBetween > 0.0f)
            {
                Cars[this.vehicleIndex].steeringWheelAngle = UISteeringAngle;
            }
            else if (angleBetween < 0.0f)
            {
                Cars[this.vehicleIndex].steeringWheelAngle = -UISteeringAngle;
            }
            else
            {
                Cars[this.vehicleIndex].steeringWheelAngle = 0.0f;
            }
            Cars[this.vehicleIndex].Accelerator = 1.0f;
            Cars[this.vehicleIndex].Brakes      = 0.0f;
        }
Esempio n. 2
0
        public static float angleBetween(VectorF a, VectorF b)
        {
            float angle = Maths.ArcTan2(b.y, b.x) - Maths.ArcTan2(a.y, a.x);

            return(Maths.AnglePiFast(angle));
        }