Ejemplo n.º 1
0
 public CarData(CarControls car)
 {
     MaxtorquevariableR = car.MaxtorquevariableR; //torque massimo variabile
     MaxtorquevariableF = car.MaxtorquevariableF; //torque massimo variabile
     MaxtorqueairF      = car.MaxtorqueairF;      //torque massimo per l'aria
     MaxtorqueairR      = car.MaxtorqueairR;      //torque massimo per l'aria
     Brakefront         = car.Brakefront;         //potenza freno anteriore
     Brakerear          = car.Brakerear;          //potenza freno posteriore
     torqueFdv          = car.torqueFdv;          //valore che divide il max torque per ottenere il valore di accelerazione
     torqueRdv          = car.torqueRdv;          //valore che divide il max torque per ottenere il valore di accelerazione
     rotation_powa      = car.rotation_powa;      //potenza di rotazione
     fuel            = car.fuel;                  //fuel di partenza
     fuelvalue       = car.fuelvalue;
     maxfuel         = car.maxfuel;
     divisoreconsumo = car.divisoreconsumo; //determina il consumo del carburante rapportato alla potenza , insomma l'efficenza , più alto = più efficiente
     cmass           = car.cmass;           //massa del centro di gravità
     frequency_front = car.frequency_front;
     frequency_back  = car.frequency_back;
     dampening_front = car.dampening_front;
     dampening_back  = car.dampening_back;
     height_front    = car.height_front;
     height_back     = car.height_back;
     lvFsh           = car.lvFsh;
     lvRsh           = car.lvRsh;
     lvFgr           = car.lvFgr;
     lvE             = car.lvE;
     lvT             = car.lvT;
     lvG             = car.lvG;
     gripF           = car.gripF;
     gripR           = car.gripR;
 }
Ejemplo n.º 2
0
 private void ObjectSelect_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ObjectSelect.SelectedIndex == 0)
     {
         if (initialized)
         {
             mainDisplay.setObjectId(0);
         }
         StationaryObjects.Hide();
         mainDisplay.triggerType = CarActivation.SelectedIndex;
         CarControls.Show();
         //Invalidate();
     }
     else if (ObjectSelect.SelectedIndex == 1)
     {
         if (initialized)
         {
             mainDisplay.setObjectId(1);
         }
         CarControls.Hide();
         StationaryObjects.Show();
         mainDisplay.triggerType = AppearBehaviour.SelectedIndex;
         //Invalidate();
     }
 }
Ejemplo n.º 3
0
    /*
     * private void OnDisable()
     * {
     *  control.GamepadController.Disable();
     * }
     */

    private void Awake()
    {
        control = new CarControls();

        // Gamepad Controls
        control.GamepadController.Headlight.performed    += ctx => ntwk.toggelHeadLights();
        control.GamepadController.Direction.performed    += ctx => ntwk.right = ctx.ReadValue <Vector2>().x;
        control.GamepadController.Direction.canceled     += ctx => ntwk.right = 0f;
        control.GamepadController.Acceleration.performed += ctx => ntwk.forward = ctx.ReadValue <Vector2>().y *ThrottleMultiplier.value;
        control.GamepadController.Acceleration.canceled  += ctx => ntwk.forward = 0f;
        control.GamepadController.IncreaseThrottleMultiplier.performed += ctk => ThrottleMultiplier.value += ThrottleMultiplier.maxValue / 10f;
        control.GamepadController.DecreaseThrottleMultiplier.performed += ctk => ThrottleMultiplier.value -= ThrottleMultiplier.maxValue / 10f;
        control.GamepadController.Disconnect.performed += ctx => logger.clickedDisconnect();

        // Keyboard Controls
        control.Keyboard.Headlight.performed += ctx => ntwk.toggelHeadLights();
        control.Keyboard.Forward.performed   += ctx => ntwk.forward = ThrottleMultiplier.value;
        control.Keyboard.Forward.canceled    += ctx => ntwk.forward = 0f;
        control.Keyboard.Backward.performed  += ctx => ntwk.forward = -1f * ThrottleMultiplier.value;
        control.Keyboard.Backward.canceled   += ctx => ntwk.forward = 0f;
        control.Keyboard.Right.performed     += ctx => ntwk.right = 1f;
        control.Keyboard.Right.canceled      += ctx => ntwk.right = 0f;
        control.Keyboard.Left.performed      += ctx => ntwk.right = -1f;
        control.Keyboard.Left.canceled       += ctx => ntwk.right = 0f;
        control.Keyboard.IncreaseThrottleMultiplier.performed += ctk => ThrottleMultiplier.value += ThrottleMultiplier.maxValue / 10f;
        control.Keyboard.DecreaseThrottleMultiplier.performed += ctk => ThrottleMultiplier.value -= ThrottleMultiplier.maxValue / 10f;
        control.Keyboard.Disconnect.performed += ctx => logger.clickedDisconnect();
    }
        private static bool SetCarApiControls(CarControls controls, string vehicleName)
        {
            if (vehicleName == "")
            {
                foreach (var v in Vehicles)
                {
                    if (v != null)
                    {
                        v.VehicleInterface.SetCarControls(controls);
                    }
                    else
                    {
                        Debug.LogError("Should not happen - Check why this happend");
                    }
                }
                return(true);
            }

            var vehicle = Vehicles.Find(element => element.vehicleName == vehicleName);

            if (vehicle != null)
            {
                return(vehicle.VehicleInterface.SetCarControls(controls));
            }
            return(false);
        }
Ejemplo n.º 5
0
    public override void DoAction()
    {
        Transform actor = GameObject.Find(actorName).transform;

        if (actor.GetComponent <IDVehicle>())
        {
            IDVehicle   ident      = actor.GetComponent <IDVehicle>();
            CarControls carControl = ident.carController;

            if (ident.vehicle.GetComponent <Rigidbody>().velocity.magnitude < carControl.maxVelocityMagnitudeToExit)
            {
                ParallelActions parActs = new ParallelActions();
                parActs.actions = new List <Action>();
                if (ident.GetDriversID() != null)
                {
                    if (ident.GetDriversID().GetType() == typeof(IDCharacter))
                    {
                        IDCharacter IDChar = (IDCharacter)ident.GetDriversID();
                        foreach (Action act in IDChar.exitCarActions)
                        {
                            parActs.actions.Add(act);
                        }
                    }
                }
                foreach (Action act in ident.exitActions)
                {
                    parActs.actions.Add(act);
                }

                //foreach (Action act in parActs.actions) { act.DoAction(); }

                FindObjectOfType <ActionSceneCoordinator>().TriggerParallelActions(parActs);

                if (isTed)
                {
                    if (headOrientation != null)
                    {
                        FindObjectOfType <TeddyHead>().transform.localRotation = headOrientation;
                    }
                    else
                    {
                        FindObjectOfType <TeddyHead>().transform.localRotation = Quaternion.identity;
                    }
                }

                // For now this only works with Ted
                FindObjectOfType <BodyCam>().LeaveVehicle(ident);

                carControl.DisableInteriorInteractables();
            }
            else
            {
                carControl.HighSpeedExitWarning();
            }
        }
    }
Ejemplo n.º 6
0
 public static void SetCarControls(CarControls src, ref CarControls dst)
 {
     dst.brake          = src.brake;
     dst.gear_immediate = src.gear_immediate;
     dst.handbrake      = src.handbrake;
     dst.is_manual_gear = src.is_manual_gear;
     dst.manual_gear    = src.manual_gear;
     dst.steering       = src.steering;
     dst.throttle       = src.throttle;
 }
Ejemplo n.º 7
0
    public static void saveCar(CarControls car)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/Car.dat";
        FileStream      stream    = new FileStream(path, FileMode.OpenOrCreate);

        CarData data = new CarData(car);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Ejemplo n.º 8
0
 // if picked up by a car, change state and call method on the car.
 void OnTriggerEnter(Collider other)
 {
     if (!collected)
     {
         CarControls car = other.GetComponent <CarControls>();
         if (car != null)
         {
             collected = true;
             Debug.Log("Collision with " + other);
             car.CollectPoint(this);
         }
     }
 }
Ejemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        float height = 2.0f * Camera.main.orthographicSize;

        screenWidthInPoints = height * Camera.main.aspect;

        spawner                = GetComponent <SpawnHandler>();
        playerAudio            = GetComponent <AudioSource>();
        car                    = GetComponent <CarControls>();
        fly                    = GetComponent <FlyControls>();
        gameState              = GetComponent <GameState>();
        playerRenderer         = GetComponent <SpriteRenderer>();
        playerAnimator         = GetComponent <Animator>();
        heartIndicatorRenderer = heartIndicator.GetComponent <SpriteRenderer>();

        // Start on ground
        vehicleState    = VehicleStateEnum.Ground;
        currentControls = car;
    }
Ejemplo n.º 10
0
 private void Start()
 {
     _gameMode    = (GameMode)System.Enum.Parse(typeof(GameMode), PlayerPrefs.GetString("GameMode", "Teams"));
     _carControls = GetComponentInParent <CarControls>();
     if (_gameMode == GameMode.Teams)
     {
         if (_sourceID == 0)
         {
             _stereoChannel = -1;
         }
         if (_sourceID == 1)
         {
             _stereoChannel = 1;
         }
     }
     else
     {
         _stereoChannel = 0;
     }
 }
Ejemplo n.º 11
0
 public void Update(CarControls controls)
 {
     Update(controls.Gas, controls.Brake, controls.Steer);
 }
Ejemplo n.º 12
0
        private static bool SetCarApiControls(CarControls controls, string vehicleName)
        {
            var vehicle = Vehicles.Find(element => element.vehicleName == vehicleName);

            return(vehicle.VehicleInterface.SetCarControls(controls));
        }
Ejemplo n.º 13
0
        protected override void Update(GameTime gameTime)
        {
            currKeyboard = Keyboard.GetState();

            if (currKeyboard.IsKeyDown(Keys.Escape) && currKeyboard.IsKeyDown(Keys.LeftShift))
            {
                this.Exit();
            }

            if (!console.Opened)
            {
                camera.HandleInput();

                // View options
                if (keyPressed(Keys.F11))
                {
                    toggleFullscreen();
                }
                if (keyPressed(Keys.F12))
                {
                    backgroundLight = !backgroundLight;
                }
                if (keyPressed(Keys.C))
                {
                    drawCar = !drawCar;
                }
                if (keyPressed(Keys.R))
                {
                    rotateCar = !rotateCar;
                }
                if (keyPressed(Keys.G))
                {
                    drawGrid = !drawGrid;
                    drawVoro = false;
                    drawHeur = false;
                }
                if (keyPressed(Keys.V))
                {
                    drawVoro = !drawVoro;
                    drawGrid = false;
                    drawHeur = false;
                }
                if (keyPressed(Keys.H))
                {
                    drawHeur = !drawHeur;
                    drawVoro = false;
                    drawGrid = false;
                }
                if (keyPressed(Keys.B))
                {
                    if (currKeyboard.IsKeyDown(Keys.LeftShift) || currKeyboard.IsKeyDown(Keys.RightShift))
                    {
                        watchSearch = !watchSearch;
                    }
                    else
                    {
                        drawSearch = !drawSearch;
                    }
                }
                if (keyPressed(Keys.P))
                {
                    drawPath = !drawPath;
                }
                if (keyPressed(Keys.L))
                {
                    drawSmoothedPath = !drawSmoothedPath;
                    drawController   = false;
                }
                if (keyPressed(Keys.O))
                {
                    drawController   = !drawController;
                    drawSmoothedPath = false;
                }
                if (keyPressed(Keys.F))
                {
                    drawFrontPath = !drawFrontPath;
                }
                if (keyPressed(Keys.Home))
                {
                    drawStart = !drawStart;
                }
                if (keyPressed(Keys.End))
                {
                    drawGoal = !drawGoal;
                }
                if (keyPressed(Keys.Scroll))
                {
                    drawCurrent = !drawCurrent;
                }
                if (keyPressed(Keys.N))
                {
                    drawDebugData = !drawDebugData;
                }

                if (keyPressed(Keys.OemComma))
                {
                    HybridAStar.Delay = HybridAStar.Delay == 0 ? 1 : 0;
                }
                if (keyPressed(Keys.OemPeriod))
                {
                    Smoother.Delay = Smoother.Delay == 0 ? 10 : 0;
                }

                // Zoom
                if (currKeyboard.IsKeyDown(Keys.OemPlus))
                {
                    scale *= 1.02f;
                }
                if (currKeyboard.IsKeyDown(Keys.OemMinus))
                {
                    scale *= 0.98f;
                }

                // Translate
                if (currKeyboard.IsKeyDown(Keys.Up))
                {
                    yOffset += 5f / scale;
                }
                if (currKeyboard.IsKeyDown(Keys.Down))
                {
                    yOffset -= 5f / scale;
                }
                if (currKeyboard.IsKeyDown(Keys.Right))
                {
                    xOffset += 5f / scale;
                }
                if (currKeyboard.IsKeyDown(Keys.Left))
                {
                    xOffset -= 5f / scale;
                }

                if (currKeyboard.IsKeyDown(Keys.W))
                {
                    gas = 1;
                }
                else if (currKeyboard.IsKeyDown(Keys.S))
                {
                    gas = -1;
                }
                else
                {
                    gas = 0;
                }

                if (currKeyboard.IsKeyDown(Keys.D))
                {
                    steer = -1;
                }
                else if (currKeyboard.IsKeyDown(Keys.A))
                {
                    steer = 1;
                }
                else
                {
                    steer = 0;
                }

                if (currKeyboard.IsKeyDown(Keys.Space))
                {
                    brake = 1;
                }
                else
                {
                    brake = 0;
                }

                if (gas != 0 || brake != 0 || steer != 0)
                {
                    autoDrive = false;
                }

                if (currKeyboard.IsKeyDown(Keys.Enter) && pathSmoothDone)
                {
                    run = true;
                }

                // Camera views
                if (keyPressed(Keys.D1))
                {
                    cameraView = 1;
                }
                if (keyPressed(Keys.D2))
                {
                    cameraView = 2;
                }
                if (keyPressed(Keys.D3))
                {
                    cameraView = 3;
                }
                if (keyPressed(Keys.D4))
                {
                    cameraView = 4;
                }
                if (keyPressed(Keys.D5))
                {
                    cameraView = 5;
                }

                if (keyPressed(Keys.D0))
                {
                    ClearWorld();
                    InitSim(false);
                }

                if (keyPressed(Keys.Back))
                {
                    paused = !paused;
                }
            }

            prevKeyboard = currKeyboard;

            if (!paused)
            {
                if (autoDrive)
                {
                    if (run)
                    {
                        currentControls = controller.Update(car.Pose, car.WheelAngle, car.SpeedMetersPerSecond, gameTime);
                        car.Update(currentControls);
                    }
                }
                else
                {
                    currentControls = new CarControls(gas, brake, steer);
                    car.Update(new CarControls(gas, brake, steer));
                }

                if (run && controller.State == StanleyFSMController.ControllerState.MissionComplete && MissionCompleted != null)
                {
                    MissionCompleted(this, controller.Info);
                }

                world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);
                dashboard.Update(car.WheelAngle, currentControls.Gas, currentControls.Brake, car.SpeedMPH);

                if (isCollided && Collided != null)
                {
                    Collided(this, null);
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 14
0
 private void Start()
 {
     carController = GetComponent <CarControls>();
 }
Ejemplo n.º 15
0
 void FindObjectsAndComponents()
 {
     big         = GameObject.Find("Big");
     myCam       = GetComponent <Camera>();
     carControls = car.GetComponent <CarControls>();
 }
Ejemplo n.º 16
0
 public void Init()
 {
     _target = new CarControls();
 }
Ejemplo n.º 17
0
 //Car controls being set through client api calls
 public override bool SetCarControls(CarControls controls)
 {
     DataManager.SetCarControls(controls, ref carControls);
     return(true);
 }
Ejemplo n.º 18
0
        public void InitSim(bool autoStart, bool smoothingOn, Mission mission)
        {
            gridDone          = false;
            pathDone          = false;
            pathSmoothDone    = false;
            pathSearching     = false;
            pathSearchingDone = false;
            autoDrive         = true;
            run             = false;
            isCollided      = false;
            currentControls = new CarControls(0f, 0f, 0f);

            if (camera == null)
            {
                camera          = new Camera(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000f);
                camera.Position = new Vector3(75f, 75f, 180f);
            }

            startPose                  = mission.Start;
            goalPose                   = mission.Goal;
            HybridAStar.Epsilon        = mission.AStarEpsilon;
            HybridAStar.GridResolution = mission.AStarGridResolution;
            HybridAStar.SafetyFactor   = 1.5f;
            HybridAStar.Reset();

            car  = new Car(world, startPose);
            grid = new ObstacleGrid(world, mission.Environment);

            car.Body.OnCollision += new OnCollisionEventHandler(OnCollision);

            gridDone          = false;
            pathDone          = false;
            pathSearchingDone = false;
            bg = new Thread(() =>
            {
                DateTime now = DateTime.Now;
                grid.BuildGVD();
                console.WriteLine("GVD Generation Time: " + Math.Round((DateTime.Now - now).TotalMilliseconds) + " ms");
                gridDone = true;

                now                = DateTime.Now;
                pathSearching      = true;
                astar              = HybridAStar.FindPath(grid, startPose, goalPose);
                TimeSpan astarTime = DateTime.Now - now;
                poses              = astar.Path;

                pathSearching     = false;
                pathSearchingDone = true;

                if (astar.Path.Count > 0)
                {
                    pathDone = true;
                }

                now = DateTime.Now;
                if (smoothingOn)
                {
                    smoothedPath = Smoother.Smooth(astar.Path, grid);
                }
                else
                {
                    smoothedPath = astar.Path;
                }
                TimeSpan smoothingTime = DateTime.Now - now;

                int numUnsafe = Smoother.UnsafeIndices != null ? Smoother.UnsafeIndices.Count : 0;

                console.WriteLine("A*: Total Planning Time: " + Math.Round((astarTime + smoothingTime).TotalMilliseconds) + " ms");
                console.WriteLine("         Heuristic Time: " + Math.Round(astar.HeuristicInitTime.TotalMilliseconds) + " ms");
                console.WriteLine("         Searching Time: " + Math.Round((astarTime - astar.HeuristicInitTime).TotalMilliseconds) + " ms");
                console.WriteLine("         Smoothing Time: " + Math.Round(smoothingTime.TotalMilliseconds) + " ms (" + Smoother.NumIterations + " iterations, " + Smoother.Change + "m, " + numUnsafe + " unsafe points)");
                console.WriteLine("    " + astar.Discovered.Count + " nodes discovered");
                console.WriteLine("    " + astar.Expanded.Count + " nodes expanded");

                controller = new StanleyFSMController(smoothedPath, goalPose);

                pathSmoothDone = true;
                if (autoStart)
                {
                    run = true;
                }
            });
            bg.IsBackground = true;
            bg.Priority     = ThreadPriority.Lowest;
            bg.Start();
        }