private GameControllerType GetGameControllerType(GCController controller) { try { if (controller.MicroGamepad != null) { return(GameControllerType.Micro); } } catch (InvalidCastException) { } try { if (controller.Gamepad != null) { return(GameControllerType.Standard); } } catch (InvalidCastException) { } try { if (controller.ExtendedGamepad != null) { return(GameControllerType.Extended); } } catch (InvalidCastException) { } return(GameControllerType.Unknown); }
private void FoundController() { lock (_lockObject) { _gameController = GCController.Controllers.FirstOrDefault(); if (_gameController != null) { GCController.StopWirelessControllerDiscovery(); _didConnectNotification?.Dispose(); _didConnectNotification = null; _didDisconnectNotification = GCController.Notifications.ObserveDidDisconnect((sender, args) => { FindController(); }); switch (GetGameControllerType(_gameController)) { case GameControllerType.Micro: SetupMicroGamePad(_gameController.MicroGamepad); break; case GameControllerType.Standard: SetupGamePad(_gameController.Gamepad); break; case GameControllerType.Extended: SetupExtendedGamePad(_gameController.ExtendedGamepad); break; } } } }
private static GamePadCapabilities GetCapabilities(GCController controller) { //All iOS controllers have these basics var capabilities = new GamePadCapabilities() { IsConnected = false, GamePadType = GamePadType.GamePad, }; if (controller.ExtendedGamepad != null) { capabilities.HasAButton = true; capabilities.HasBButton = true; capabilities.HasXButton = true; capabilities.HasYButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; capabilities.HasLeftShoulderButton = true; capabilities.HasRightShoulderButton = true; capabilities.HasLeftTrigger = true; capabilities.HasRightTrigger = true; capabilities.HasLeftXThumbStick = true; capabilities.HasLeftYThumbStick = true; capabilities.HasRightXThumbStick = true; capabilities.HasRightYThumbStick = true; } else if (controller.Gamepad != null) { capabilities.HasAButton = true; capabilities.HasBButton = true; capabilities.HasXButton = true; capabilities.HasYButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; capabilities.HasLeftShoulderButton = true; capabilities.HasRightShoulderButton = true; } else if (controller.MicroGamepad != null) { capabilities.HasAButton = true; capabilities.HasXButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; } return(capabilities); }
private void FindController() { lock (_lockObject) { _didConnectNotification = GCController.Notifications.ObserveDidConnect((sender, args) => { FoundController(); }); GCController.StartWirelessControllerDiscoveryAsync(); } }
/* This method should be called when the level is loaded to set up currently-connected game controllers, * and register for the relevant notifications to deal with new connections/disconnections. */ public void ConfigureGameControllers() { // Receive notifications when a controller connects or disconnects. didConnectObserver = GCController.Notifications.ObserveDidConnect(GameControllerDidConnect); didDisconnectObserver = GCController.Notifications.ObserveDidDisconnect(GameControllerDidDisconnect); // Configure all the currently connected game controllers. ConfigureConnectedGameControllers(); // And start looking for any wireless controllers. GCController.StartWirelessControllerDiscovery(() => Console.WriteLine("Finished finding controllers")); }
void AssignPresetController(GCController controller, nint playerIndex) { Player player = ConnectPlayerFor(playerIndex); if (player.Controller != null && player.Controller != controller) { // Taken by another controller so reassign to another player. AssignUnknownController(controller); return; } ConfigureController(controller, player); }
void AssignUnknownController(GCController controller) { for (int playerIndex = 0; playerIndex < NUM_PLAYERS; playerIndex++) { Player player = ConnectPlayerFor(playerIndex); if (player.Controller != null) { continue; } // Found an unlinked player. controller.PlayerIndex = playerIndex; ConfigureController(controller, player); return; } }
/// <summary> /// Updates Dolphin's input queue with the class internal queue, if there is enough space. /// </summary> private void SendInputsToDolphin() { // Number of inputs to send to Dolphin int countInputsToSend = m_inputsToSend.Count; // countInputsToSend is limited to (10 - InputsInQueue) because Dolphin's queue is limited to 10 inputs if (countInputsToSend > 10 - m_mInterface.InputsInQueue) { countInputsToSend = 10 - m_mInterface.InputsInQueue; } // If there's no input to send, return if (countInputsToSend == 0) { return; } // Each input is represented by an array of 8 bytes int size = Marshal.SizeOf(typeof(byte)) * 8 * countInputsToSend; byte[] data = new byte[size]; // Build data array with the byte values of each input for (int i = 0; i < countInputsToSend; i++) { GCController input = m_inputsToSend.Dequeue(); IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * 8); Marshal.StructureToPtr(input, p, false); Marshal.Copy(p, data, i * 8, Marshal.SizeOf(typeof(byte)) * 8); } // The position to write the array is offset by (8 * InputsInQueue) because there are "InputsInQueue" inputs in queue already long position = (long)Marshal.OffsetOf(typeof(MInterface), "ControllerInputQueue") + m_mInterface.InputsInQueue * 8; m_accessor.WriteArray <byte>(position, data, 0, data.Length); // Finally, InputsInQueue is updated with the value that was written WriteByteToMemory("InputsInQueue", (byte)(m_mInterface.InputsInQueue + countInputsToSend)); }
void ConfigureController(GCController controller, Player player) { Console.WriteLine("Assigning {0} to player {1} [{2}]", controller.VendorName, player, players.IndexOf(player)); // Assign the controller to the player. player.Controller = controller; GCControllerDirectionPadValueChangedHandler dpadMoveHandler = (dpad, xValue, yValue) => { var length = GraphicsUtilities.Hypotenuse(xValue, yValue); if (length > 0f) { var invLength = 1 / length; player.HeroMoveDirection = new CGPoint(xValue * invLength, yValue * invLength); } else { player.HeroMoveDirection = CGPoint.Empty; } }; // Use either the dpad or the left thumbstick to move the character. controller.ExtendedGamepad.LeftThumbstick.ValueChangedHandler = dpadMoveHandler; controller.Gamepad.DPad.ValueChangedHandler = dpadMoveHandler; GCControllerButtonValueChanged fireButtonHandler = (button, value, pressed) => { player.FireAction = pressed; }; controller.Gamepad.ButtonA.SetValueChangedHandler(fireButtonHandler); controller.Gamepad.ButtonB.SetValueChangedHandler(fireButtonHandler); if (player != DefaultPlayer && player.Hero == null) { AddHeroFor(player); } }
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); }
private Gamepad(GCController controller) { _controller = controller; _id = _nextGamepadId++; }
private static GamePadCapabilities GetCapabilities(GCController controller) { //All iOS controllers have these basics var capabilities = new GamePadCapabilities() { IsConnected = false, GamePadType = GamePadType.GamePad, }; if (controller.ExtendedGamepad != null) { capabilities.HasAButton = true; capabilities.HasBButton = true; capabilities.HasXButton = true; capabilities.HasYButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; capabilities.HasLeftShoulderButton = true; capabilities.HasRightShoulderButton = true; capabilities.HasLeftTrigger = true; capabilities.HasRightTrigger = true; capabilities.HasLeftXThumbStick = true; capabilities.HasLeftYThumbStick = true; capabilities.HasRightXThumbStick = true; capabilities.HasRightYThumbStick = true; } else if (controller.Gamepad != null) { capabilities.HasAButton = true; capabilities.HasBButton = true; capabilities.HasXButton = true; capabilities.HasYButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; capabilities.HasLeftShoulderButton = true; capabilities.HasRightShoulderButton = true; } else if (controller.MicroGamepad != null) { capabilities.HasAButton = true; capabilities.HasXButton = true; capabilities.HasBackButton = true; capabilities.HasDPadUpButton = true; capabilities.HasDPadDownButton = true; capabilities.HasDPadLeftButton = true; capabilities.HasDPadRightButton = true; } return capabilities; }
void ConfigureController(GCController controller, Player player) { Console.WriteLine ("Assigning {0} to player {1} [{2}]", controller.VendorName, player, players.IndexOf (player)); // Assign the controller to the player. player.Controller = controller; GCControllerDirectionPadValueChangedHandler dpadMoveHandler = (dpad, xValue, yValue) => { var length = GraphicsUtilities.Hypotenuse (xValue, yValue); if (length > 0f) { var invLength = 1 / length; player.HeroMoveDirection = new CGPoint (xValue * invLength, yValue * invLength); } else { player.HeroMoveDirection = CGPoint.Empty; } }; // Use either the dpad or the left thumbstick to move the character. controller.ExtendedGamepad.LeftThumbstick.ValueChangedHandler = dpadMoveHandler; controller.Gamepad.DPad.ValueChangedHandler = dpadMoveHandler; GCControllerButtonValueChanged fireButtonHandler = (button, value, pressed) => { player.FireAction = pressed; }; controller.Gamepad.ButtonA.SetValueChangedHandler (fireButtonHandler); controller.Gamepad.ButtonB.SetValueChangedHandler (fireButtonHandler); if (player != DefaultPlayer && player.Hero == null) AddHeroFor (player); }
void AssignUnknownController(GCController controller) { for (int playerIndex = 0; playerIndex < NUM_PLAYERS; playerIndex++) { Player player = ConnectPlayerFor (playerIndex); if (player.Controller != null) continue; // Found an unlinked player. controller.PlayerIndex = playerIndex; ConfigureController (controller, player); return; } }
void AssignPresetController(GCController controller, nint playerIndex) { Player player = ConnectPlayerFor (playerIndex); if (player.Controller != null && player.Controller != controller) { // Taken by another controller so reassign to another player. AssignUnknownController (controller); return; } ConfigureController (controller, player); }
/// <summary> /// Adds a GameCube Controller input object to the queue of inputs that will be sent to Dolphin. /// </summary> /// <param name="t_gcCont">The input specified as a GCController object.</param> public void AddInputInQueue(GCController t_gcCont) { m_inputsToSend.Enqueue(t_gcCont); }