Пример #1
0
        public IVehicleController GetController(string vid)
        {
            Hashtable          vehicle_ht        = GetVehicleInfoByID(vid);
            string             platform_id       = SiteHelper.GetHashTableValueByKey(vehicle_ht, "PlatformId").ToUpper();
            IVehicleController vehicleController = null;

            switch (platform_id)
            {
            /*case "0EF1FB75-9792-4E2E-8D21-6AA4302E49A5":
             *  vehicleController = new SZVehicleController();
             *  break;
             * case "0EF1FB75-9792-4E2E-8D21-6AA4302E49A6":
             *  vehicleController = new SZ2VehicleController();
             *  break;
             * case "F064C683-DB9C-4DF4-9208-474BE935CCC9":
             *  vehicleController = new ZYBoxVehicleController();
             *  break;
             * case "F064C683-DB9C-4DF4-9208-474BE966CCC9":
             *  vehicleController = new ZYBoxVehicleController();
             *  break;*/
            case "DCA83FF6-DBB6-41F1-BE45-FDCE7C87AA25":
                vehicleController = new XiaoAnVehicleController();
                break;

            default:
                break;
            }
            return(vehicleController);
        }
Пример #2
0
        /// <summary>
        /// Establece el vehículo a seguir
        /// </summary>
        /// <param name="vehicle">Vehículo</param>
        public void Follow(IVehicleController vehicle, float velocity)
        {
            this.m_VehicleToFollow = vehicle;

            this.m_AutoVelocity = velocity;

            this.m_Enabled = true;
        }
Пример #3
0
        /// <summary>
        /// Actualiza el piloto automático
        /// </summary>
        /// <param name="gameTime">Tiempo de juego</param>
        /// <param name="vehicle">Vehículo</param>
        public void UpdateAutoPilot(GameTime gameTime, IVehicleController vehicle)
        {
            if (this.m_Enabled)
            {
                // Obtener las componentes sin altura
                Vector3 currentPosition = new Vector3(vehicle.Position.X, 0f, vehicle.Position.Z);
                Vector3 targetPosition  = new Vector3(this.Target.X, 0f, this.Target.Z);

                this.m_DistanceToTarget = Vector3.Distance(currentPosition, targetPosition);
                if (this.m_DistanceToTarget < vehicle.Velocity * 2f)
                {
                    this.m_OnRange = true;

                    // Frenar ...
                    if (this.m_VehicleToFollow != null)
                    {
                        if (this.m_VehicleToFollow.Velocity > vehicle.Velocity)
                        {
                            // Frenar
                            //vehicle.Brake();
                        }
                    }
                    else
                    {
                        // Frenar
                        //vehicle.Brake();

                        // Detener el piloto automático si se ha alcanzado el destino
                        this.m_Enabled = (this.m_DistanceToTarget > 100f);
                    }
                }
                else
                {
                    this.m_OnRange = false;

                    // Obtener la rotación que se quiere alcanzar girando con un Billboard
                    Matrix     rotationMatrix     = Matrix.CreateBillboard(currentPosition, targetPosition, Vector3.Up, null);
                    Quaternion rotationQuaternion = Quaternion.CreateFromRotationMatrix(rotationMatrix);

                    // Obtener el ángulo de la rotación
                    Vector3 targetDirection  = Vector3.Normalize(targetPosition - currentPosition);
                    Vector3 currentDirection = Vector3.Normalize(vehicle.Direction);
                    float   angle            = currentDirection.Angle(targetDirection);

                    // Aplicar la nueva rotación directamente a la rotación actual
                    if (angle >= 0.01f)
                    {
                        vehicle.Orientation = Quaternion.Slerp(vehicle.Orientation, rotationQuaternion, MathHelper.ToRadians(1f));
                    }

                    // Si el ángulo es menor de 180º se acelera
                    if (angle < MathHelper.PiOver2)
                    {
                        if (this.m_VehicleToFollow != null)
                        {
                            if (this.m_DistanceToTarget >= vehicle.Velocity * 3f)
                            {
                                // Acelerar
                                if (this.m_AutoVelocity > vehicle.Velocity)
                                {
                                    // La velocidad actual es menor que la máxima que se puede usar
                                    vehicle.Accelerate(gameTime);
                                }
                            }
                        }
                        else
                        {
                            // Acelerar
                            if (this.m_AutoVelocity > vehicle.Velocity)
                            {
                                // Si la velocidad a alcanzar no es suficiente se acelera
                                vehicle.Accelerate(gameTime);
                            }
                        }
                    }
                }
            }
        }