Exemplo n.º 1
0
        public bool IsMovingAway(AITunnel ActiveTunnel)
        {
            float Min, Max;

            PolygonMesh.ProjectPolygon(ActiveTunnel.Right, ActiveTunnel.CollisionBox, out Min, out Max);

            float FinalPosition    = Vector3.Dot(ActiveTunnel.Right, Position);
            float RelativePosition = 0;

            //On the Right
            if (FinalPosition < Min && FinalPosition < Max)
            {
                RelativePosition = 1;
            }
            //On the Left
            else if (FinalPosition > Min && FinalPosition > Max)
            {
                RelativePosition = -1;
            }

            float DirectionFromTunnel = GetDirectionFromInsideTunnel(ActiveTunnel);

            if (RelativePosition != 0 && DirectionFromTunnel != 0 && DirectionFromTunnel != RelativePosition)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public TunnelChangePredictionResults GetTunnelChangePrediction(AITunnel NextTunnel, out bool NeedToTurnRight)
        {
            if (Forward == NextTunnel.Forward)
            {
                NeedToTurnRight = false;
                return(TunnelChangePredictionResults.Aligned);
            }

            double VehiculeYaw     = Math.Atan2(Forward.Z, Forward.X);
            double TunnelYaw       = Math.Atan2(NextTunnel.Forward.Z, NextTunnel.Forward.X);
            double AngleDifference = VehiculeYaw - TunnelYaw;
            double ExpectedSecondsToAlignWithNextTurn = Math.Abs(AngleDifference / RotationMaxSpeedPerSecond);

            Vector3 ExpectedSpeedAfterAlignWithNextTurn = Forward * Acceleration * (float)ExpectedSecondsToAlignWithNextTurn;

            ExpectedSpeedAfterAlignWithNextTurn += Speed;
            ExpectedSpeedAfterAlignWithNextTurn  = ComputeSpeedAfterFriction(ExpectedSpeedAfterAlignWithNextTurn, ExpectedSecondsToAlignWithNextTurn);
            ExpectedSpeedAfterAlignWithNextTurn  = ComputeSpeedAfterLateralFriction(ExpectedSpeedAfterAlignWithNextTurn);

            Vector3 ExpectedPositionAfterAlignWithNextTurn = Position + ExpectedSpeedAfterAlignWithNextTurn;

            float PlayerPosition = Vector3.Dot(NextTunnel.Right, ExpectedPositionAfterAlignWithNextTurn);
            float TunnelPositionLeftEntryPoint;
            float TunnelPositionRightEntryPoint;

            NextTunnel.GetEntryPoints(NextTunnel.Right, out TunnelPositionLeftEntryPoint, out TunnelPositionRightEntryPoint);

            float NextTunnelAngle = Vector3.Dot(Right, NextTunnel.Forward);

            NeedToTurnRight = NextTunnelAngle > 0;

            if (NeedToTurnRight)
            {
                //Entry would at the right of the player after turning, meaning you overshoot and need to brake.
                if (TunnelPositionLeftEntryPoint > PlayerPosition && TunnelPositionRightEntryPoint > PlayerPosition)
                {
                    return(TunnelChangePredictionResults.Overshoot);
                }
                //Entry would at the left of the player after turning, meaning you undershoot and will hit a wall if turning right now.
                else if (TunnelPositionLeftEntryPoint < PlayerPosition && TunnelPositionRightEntryPoint < PlayerPosition)
                {
                    return(TunnelChangePredictionResults.Undershoot);
                }
            }
            else
            {
                //Entry would at the left of the player after turning, meaning you overshoot and need to brake.
                if (TunnelPositionLeftEntryPoint < PlayerPosition && TunnelPositionRightEntryPoint < PlayerPosition)
                {
                    return(TunnelChangePredictionResults.Overshoot);
                }
                //Entry would at the right of the player after turning, meaning you undershoot and will hit a wall if turning right now.
                else if (TunnelPositionLeftEntryPoint > PlayerPosition && TunnelPositionRightEntryPoint > PlayerPosition)
                {
                    return(TunnelChangePredictionResults.Undershoot);
                }
            }

            return(TunnelChangePredictionResults.Turn);
        }
Exemplo n.º 3
0
        public float GetDistanceToEntryPointOfAITunnel(AITunnel ActiveTunnel)
        {
            float ActiveAITunnelPosition = ActiveTunnel.GetDistanceEntryPoint();
            float FinalPosition          = Vector3.Dot(ActiveTunnel.Forward, Position);

            return(ActiveAITunnelPosition - FinalPosition);
        }
Exemplo n.º 4
0
        public AITunnel CreateAITunnel()
        {
            AITunnel NewAITunnel = new AITunnel(GraphicsDevice, Camera.Projection);

            ListAITunnel.Add(NewAITunnel);

            return(NewAITunnel);
        }
Exemplo n.º 5
0
        public override void Load()
        {
            fntFinlanderFont = Content.Load <SpriteFont>("Fonts/Finlander Font");
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(5, 0, 0)));
            ListVehicule[0].ListActionMenuChoice.Add(new ActionPanelAIFirstAction(ListVehicule[0]));
            //ListVehicule[0].ListActionMenuChoice.Add(new ActionPanelPlayerAction(ListVehicule[0]));
            ListVehicule[0].Load(Content, GraphicsDevice);

            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(0, 0, 0)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(-5, 0, 5)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(10, 0, 10)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(-10, 0, 16)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(0, 0, 20)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(-5, 0, 35)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(10, 0, 30)));
            ListVehicule.Add(new Vehicule2D(ListAITunnel, ListCollisionBox, GraphicsDevice, new Vector3(-10, 0, 46)));
            for (int V = 1; V < ListVehicule.Count; ++V)
            {
                ListVehicule[V].ListActionMenuChoice.Add(new ActionPanelAIFirstAction(ListVehicule[V]));
                ListVehicule[V].Load(Content, GraphicsDevice);
            }

            ActiveVehicule = ListVehicule[5];
            Camera         = new ChaseCamera(GraphicsDevice, ActiveVehicule);

            if (!string.IsNullOrEmpty(MapPath))
            {
                FileStream   FS = new FileStream("Content/Maps/Racing/" + MapPath + ".pem", FileMode.Open, FileAccess.Read);
                BinaryReader BR = new BinaryReader(FS, Encoding.UTF8);
                BR.BaseStream.Seek(0, SeekOrigin.Begin);

                int ListAITunnelCount = BR.ReadInt32();
                for (int T = 0; T < ListAITunnelCount; ++T)
                {
                    ListAITunnel.Add(AITunnel.Load(BR, GraphicsDevice, Camera.Projection));
                }

                int ListCollisionBoxCount = BR.ReadInt32();
                for (int T = 0; T < ListCollisionBoxCount; ++T)
                {
                    ListCollisionBox.Add(CollisionBox.Load(BR, GraphicsDevice, Camera.Projection));
                }

                BR.Close();
                FS.Close();

                LinkAITunnelTogether();
            }
        }
Exemplo n.º 6
0
        public float GetDirectionFromInsideTunnel(AITunnel ActiveTunnel)
        {
            float PlayerPosition = Vector3.Dot(Right, Forward);
            float TunnelPosition = Vector3.Dot(Right, ActiveTunnel.Forward);

            if (TunnelPosition > 0)
            {
                return(-1);
            }
            if (TunnelPosition < 0)
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 7
0
        public float GetDirectionFromOutsideTunnel(AITunnel ActiveTunnel)
        {
            float MinTunnel, MaxTunnel;

            PolygonMesh.ProjectPolygon(Right, ActiveTunnel.CollisionBox, out MinTunnel, out MaxTunnel);
            float FinalPlayerPosition = Vector3.Dot(Right, Position);

            if (MinTunnel < FinalPlayerPosition && MaxTunnel < FinalPlayerPosition)
            {
                return(-1);
            }
            if (MinTunnel > FinalPlayerPosition && MaxTunnel > FinalPlayerPosition)
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 8
0
        public float GetRandomEntryPointOfAITunnel(AITunnel ActiveTunnel)
        {
            float Min, Max;

            ActiveTunnel.GetEntryPoints(Right, out Min, out Max);
            float FinalPosition = Vector3.Dot(Right, Position);

            if (FinalPosition < Min && FinalPosition < Max)
            {
                return(Min - FinalPosition);
            }
            else if (FinalPosition > Min && FinalPosition > Max)
            {
                return(FinalPosition - Max);
            }

            return(0);
        }
Exemplo n.º 9
0
        public float GetHorizontalDistanceToExitPointOfAITunnel(AITunnel ActiveTunnel)
        {
            float Min, Max;

            ActiveTunnel.GetExitPoints(Right, out Min, out Max);
            float FinalPosition = Vector3.Dot(Right, Position);

            if (FinalPosition < Min && FinalPosition < Max)
            {//Tunnel is at your left.
                return(-1);
            }
            else if (FinalPosition > Min && FinalPosition > Max)
            {//Tunnel is at your right.
                return(1);
            }

            return(0);
        }
Exemplo n.º 10
0
        public float GetHorizontalDistanceToAITunnel(AITunnel ActiveTunnel)
        {
            if (IsMovingAway(ActiveTunnel))
            {
                return(GetDirectionFromInsideTunnel(ActiveTunnel));
            }

            float Min, Max;

            PolygonMesh.ProjectPolygon(Right, ActiveTunnel.CollisionBox, out Min, out Max);

            float FinalPosition = Vector3.Dot(Right, Position);

            if (FinalPosition < Min && FinalPosition < Max)
            {
                return(-1);
            }
            else if (FinalPosition > Min && FinalPosition > Max)
            {
                return(1);
            }
            //Inside Tunnel
            else if (FinalPosition > Min && FinalPosition < Max)
            {
                return(GetHorizontalDistanceToExitPointOfAITunnel(ActiveTunnel));
            }

            //if perpendicular
            float a = Vector3.Dot(ActiveTunnel.Forward, Right);

            if (a == 0)
            {
                return(-1);
            }

            return(0);
        }
Exemplo n.º 11
0
        public static AITunnel Load(BinaryReader BR, GraphicsDevice g, Matrix Projection)
        {
            AITunnel NewAITunnel = new AITunnel(BR, g, Projection);

            return(NewAITunnel);
        }
Exemplo n.º 12
0
 public void AlignWithTunnel(AITunnel CurrentAITunnel)
 {
     Rotate(CurrentAITunnel.Direction.X, Direction.Y, Direction.Z);
 }