private void SetupDPadInput(GCControllerDirectionPad dPad, string name)
 {
     SetupDigitalAxisInput(dPad.XAxis, $"{name}_X");
     SetupDigitalAxisInput(dPad.YAxis, $"{name}_Y");
 }
 private void SetupJoyInput(GCControllerDirectionPad joy, string name)
 {
     SetupAnalogAxisInput(joy.XAxis, $"{name}_X");
     SetupAnalogAxisInput(joy.YAxis, $"{name}_Y");
 }
Ejemplo n.º 3
0
        public virtual void DidSimulatePhysics(ISCNSceneRenderer renderer, double timeInSeconds)
        {
            float defaultEngineForce  = 300.0f;
            float defaultBrakingForce = 3.0f;
            float steeringClamp       = 0.6f;
            float cameraDamping       = 0.3f;

            GameView scnView = GameView;

            float engineForce  = 0;
            float brakingForce = 0;

            var   controllers = GCController.Controllers;
            float orientation = this.orientation;

            switch (scnView.TouchesCount)
            {
            case 1:
                engineForce       = defaultEngineForce;
                reactor.BirthRate = reactorDefaultBirthRate;
                break;

            case 2:
                engineForce       = -defaultEngineForce;
                reactor.BirthRate = 0;
                break;

            case 3:
                brakingForce      = 100;
                reactor.BirthRate = 0;
                break;

            default:
                brakingForce      = defaultBrakingForce;
                reactor.BirthRate = 0;
                break;
            }

            if (controllers != null && controllers.Length > 0)
            {
                GCController             controller = controllers [0];
                GCGamepad                pad        = controller.Gamepad;
                GCControllerDirectionPad dpad       = pad.DPad;

                if (dpad.Right.IsPressed)
                {
                    if (orientationCum < 0f)
                    {
                        orientationCum *= decrementOrientation;
                    }

                    orientationCum += incrementOrientation;

                    if (orientationCum > 1f)
                    {
                        orientationCum = 1f;
                    }
                }
                else if (dpad.Left.IsPressed)
                {
                    if (orientationCum > 0)
                    {
                        orientationCum *= decrementOrientation;
                    }

                    orientationCum -= incrementOrientation;

                    if (orientationCum < -1)
                    {
                        orientationCum = -1;
                    }
                }
                else
                {
                    orientationCum *= decrementOrientation;
                }
            }

            vehicleSteering = -orientation;
            if (orientation == 0)
            {
                vehicleSteering *= 0.9f;
            }
            if (vehicleSteering < -steeringClamp)
            {
                vehicleSteering = -steeringClamp;
            }
            if (vehicleSteering > steeringClamp)
            {
                vehicleSteering = steeringClamp;
            }

            vehicle.SetSteeringAngle(vehicleSteering, 0);
            vehicle.SetSteeringAngle(vehicleSteering, 1);

            vehicle.ApplyEngineForce(engineForce, 2);
            vehicle.ApplyEngineForce(engineForce, 3);

            vehicle.ApplyBrakingForce(brakingForce, 2);
            vehicle.ApplyBrakingForce(brakingForce, 3);

            ReorientCarIfNeeded();

            SCNNode    car       = vehicleNode.PresentationNode;
            SCNVector3 carPos    = car.Position;
            var        targetPos = new SCNVector3(carPos.X, 30f, carPos.Z + 25f);
            var        cameraPos = new SCNVector3(cameraNode.Position);

            cameraPos           = SCNVector3.Add(cameraPos, cameraDamping * (SCNVector3.Subtract(targetPos, cameraPos)));
            cameraNode.Position = cameraPos;

            if (scnView.InCarView)
            {
                var frontPosition = scnView.PointOfView.PresentationNode.ConvertPositionToNode(new SCNVector3(0f, 0f, -30f), null);
                spotLightNode.Position = new SCNVector3(frontPosition.X, 80f, frontPosition.Z);
                spotLightNode.Rotation = new SCNVector4(1f, 0f, 0f, -(float)Math.PI / 2f);
            }
            else
            {
                spotLightNode.Position = new SCNVector3(carPos.X, 80f, carPos.Z + 30f);
                spotLightNode.Rotation = new SCNVector4(1f, 0f, 0f, -(float)(Math.PI / 2.8));
            }

            var overlayScene = (OverlayScene)scnView.OverlayScene;

            overlayScene.SpeedNeedle.ZRotation = -(vehicle.SpeedInKilometersPerHour * (float)Math.PI / maxSpeed);
        }