com.badlogic.gdx.controllers.PovDirection Java Examples
The following examples show how to use
com.badlogic.gdx.controllers.PovDirection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidController.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
@Override public PovDirection getPov (int povIndex) { if (povIndex != 0) return PovDirection.center; switch (pov) { case 0x00000000: return PovDirection.center; case 0x00000001: return PovDirection.north; case 0x00000010: return PovDirection.south; case 0x00000100: return PovDirection.east; case 0x00001000: return PovDirection.west; case 0x00000101: return PovDirection.northEast; case 0x00000110: return PovDirection.southEast; case 0x00001001: return PovDirection.northWest; case 0x00001010: return PovDirection.southWest; default: throw new RuntimeException("Unexpected POV value : " + pov); } }
Example #2
Source File: GwtController.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
@Override public PovDirection getPov(int povIndex) { if (povIndex != 0) return PovDirection.center; switch (pov) { case 0x00000001: return PovDirection.north; case 0x00000010: return PovDirection.south; case 0x00000100: return PovDirection.east; case 0x00001000: return PovDirection.west; case 0x00000101: return PovDirection.northEast; case 0x00000110: return PovDirection.southEast; case 0x00001001: return PovDirection.northWest; case 0x00001010: return PovDirection.southWest; default: return PovDirection.center; } }
Example #3
Source File: CompositeControllerListener.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public boolean povMoved(final Controller controller, final int povCode, final PovDirection value) { for (ControllerListener listener : listeners) { if (listener.povMoved(controller, povCode, value)) { return true; } } return false; }
Example #4
Source File: LibgdxGamePad.java From mini2Dx with Apache License 2.0 | 5 votes |
@Override public boolean povMoved(Controller controller, int povCode, PovDirection value) { switch(value) { case center: povs.put(povCode, PovState.CENTER); break; case north: povs.put(povCode, PovState.NORTH); break; case south: povs.put(povCode, PovState.SOUTH); break; case east: povs.put(povCode, PovState.EAST); break; case west: povs.put(povCode, PovState.WEST); break; case northEast: povs.put(povCode, PovState.NORTH_EAST); break; case southEast: povs.put(povCode, PovState.SOUTH_EAST); break; case northWest: povs.put(povCode, PovState.NORTH_WEST); break; case southWest: povs.put(povCode, PovState.SOUTH_WEST); break; } notifyPovChanged(povCode, povs.get(povCode, PovState.CENTER)); return true; }
Example #5
Source File: JoystickGameController.java From seventh with GNU General Public License v2.0 | 5 votes |
private int handleDPad(int inputKeys) { if (isPovDirectionDown(PovDirection.north)) { inputKeys |= Actions.UP.getMask(); } else if (isPovDirectionDown(PovDirection.northEast)) { inputKeys |= Actions.UP.getMask(); inputKeys |= Actions.RIGHT.getMask(); } else if (isPovDirectionDown(PovDirection.northWest)) { inputKeys |= Actions.UP.getMask(); inputKeys |= Actions.LEFT.getMask(); } else if (isPovDirectionDown(PovDirection.south)) { inputKeys |= Actions.DOWN.getMask(); } else if (isPovDirectionDown(PovDirection.southEast)) { inputKeys |= Actions.DOWN.getMask(); inputKeys |= Actions.RIGHT.getMask(); } else if (isPovDirectionDown(PovDirection.southWest)) { inputKeys |= Actions.DOWN.getMask(); inputKeys |= Actions.LEFT.getMask(); } else if (isPovDirectionDown(PovDirection.east)) { inputKeys |= Actions.RIGHT.getMask(); } else if (isPovDirectionDown(PovDirection.west)) { inputKeys |= Actions.LEFT.getMask(); } return inputKeys; }
Example #6
Source File: InputMap.java From seventh with GNU General Public License v2.0 | 5 votes |
/** * */ public InputMap(ControllerInput controllerInput) { this.controllerInput = controllerInput; this.actions = new HashMap<String, InputMap.Action>(); this.keymap = new IntMap<String>(); this.buttonmap = new IntMap<String>(); this.controllermap = new IntMap<String>(); this.povButtons = new String[PovDirection.values().length]; this.scroller = new String[2]; }
Example #7
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean povMoved(Controller controller, int povCode, PovDirection dir) { for(int i = 0; i<this.povDirections.length; i++) { this.povDirections[i] = false; } this.povDirections[dir.ordinal()] = true; return false; }
Example #8
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
/** */ public ControllerInput() { this.povDirections = new boolean[PovDirection.values().length]; this.buttons = new boolean[64]; this.isConnected = Controllers.getControllers().size > 0; this.triggerSensitivity = 0.3f; this.leftJoystickSensitivity = 0.2f; this.rightJoystickSensitivity = 0.3f; this.movements = new float[4]; }
Example #9
Source File: ControllerMappingsTest.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Override public PovDirection getPov(int povCode) { return (povCode != 0 ? PovDirection.center : povDirection); }
Example #10
Source File: ControllerMappingsTest.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Test public void testJsonSaveLoad() { ControllerMappings mappings = new ControllerMappings(); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.button, 1)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 2)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 3)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 4)); mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.center; controller.axisValues[0] = 1f; controller.pressedButton = -1; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 2)); controller.pressedButton = 2; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 1)); controller.pressedButton = 1; assertEquals(ControllerMappings.RecordResult.need_second_button, mappings.recordMapping(controller, 3)); controller.pressedButton = 0; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 3)); controller.pressedButton = -1; controller.povDirection = PovDirection.east; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 4)); JsonValue json = mappings.toJson(); System.out.println(json.toJson(JsonWriter.OutputType.json)); MappedController mappedController = new MappedController(controller, mappings); mappings.resetMappings(controller); mappedController.refreshMappingCache(); assertEquals(0, mappedController.getConfiguredAxisValue(4), 0.1f); mappings.fillFromJson(json); mappedController.refreshMappingCache(); assertEquals(1, mappedController.getConfiguredAxisValue(4), 0.1f); controller.pressedButton = 2; assertTrue(mappedController.isButtonPressed(1)); controller.pressedButton = 1; assertEquals(1, mappedController.getConfiguredAxisValue(3), 0.1f); }
Example #11
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 4 votes |
/** * Determines if a particular button is down * * @param button * @return true if the button is down, false otherwise */ public boolean isButtonDown(ControllerButtons button) { switch(button) { case NORTH_DPAD_BTN: return isPovDirectionDown(PovDirection.north); case NE_DPAD_BTN: return isPovDirectionDown(PovDirection.northEast); case EAST_DPAD_BTN: return isPovDirectionDown(PovDirection.east); case SE_DPAD_BTN: return isPovDirectionDown(PovDirection.southEast); case SOUTH_DPAD_BTN: return isPovDirectionDown(PovDirection.south); case SW_DPAD_BTN: return isPovDirectionDown(PovDirection.southWest); case WEST_DPAD_BTN: return isPovDirectionDown(PovDirection.west); case NW_DPAD_BTN: return isPovDirectionDown(PovDirection.northWest); case LEFT_TRIGGER_BTN: return isLeftTriggerDown(); case RIGHT_TRIGGER_BTN: return isRightTriggerDown(); case LEFT_BUMPER_BTN: return this.buttons[4]; case RIGHT_BUMPER_BTN: return this.buttons[5]; case LEFT_JOYSTICK_BTN: return this.buttons[8]; case RIGHT_JOYSTICK_BTN: return this.buttons[9]; case START_BTN: return this.buttons[7]; case SELECT_BTN: return this.buttons[6]; case A_BTN: return this.buttons[0]; case B_BTN: return this.buttons[1]; case X_BTN: return this.buttons[2]; case Y_BTN: return this.buttons[3]; default: return false; } }
Example #12
Source File: ControllerMappingsTest.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Test public void testPovToAxisMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 3 axis ConfiguredInput axis1 = new ConfiguredInput(ConfiguredInput.Type.axis, 5); ConfiguredInput axis2 = new ConfiguredInput(ConfiguredInput.Type.axisAnalog, 6); ConfiguredInput axis3 = new ConfiguredInput(ConfiguredInput.Type.axisDigital, 7); mappings.addConfiguredInput(axis1); mappings.addConfiguredInput(axis2); mappings.addConfiguredInput(axis3); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.east; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 5)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not two directions controller.povDirection = PovDirection.northWest; assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not same direction on different configurations controller.povDirection = PovDirection.west; assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not for analog axis controller.povDirection = PovDirection.north; assertEquals(ControllerMappings.RecordResult.nothing_done, mappings.recordMapping(controller, 6)); assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 7)); assertFalse(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); assertFalse(controllerAdapter.povMoved(controller, 1, PovDirection.center)); // the digital assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.center)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.east)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.southEast)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.west)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); MappedController mappedController = new MappedController(controller, mappings); controller.povDirection = PovDirection.center; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.north; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(-1, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.east; assertEquals(1, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.southWest; assertEquals(-1, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(1, mappedController.getConfiguredAxisValue(7), .01f); }
Example #13
Source File: ControllerMappingsTest.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Test public void testAxisToAxisMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 3 axis ConfiguredInput axis1 = new ConfiguredInput(ConfiguredInput.Type.axis, 5); ConfiguredInput axis2 = new ConfiguredInput(ConfiguredInput.Type.axisAnalog, 6); ConfiguredInput axis3 = new ConfiguredInput(ConfiguredInput.Type.axisDigital, 7); mappings.addConfiguredInput(axis1); mappings.addConfiguredInput(axis2); mappings.addConfiguredInput(axis3); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.center; controller.axisValues[0] = .2f; controller.axisValues[1] = .6f; controller.axisValues[2] = -.2f; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 5)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .2f; controller.axisValues[1] = .1f; controller.axisValues[2] = 0; assertEquals(ControllerMappings.RecordResult.nothing_done, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = 0; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = -1; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 7)); assertTrue(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); // the digital assertTrue(controllerAdapter.axisMoved(controller, 2, .8f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 2, -.8f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 2, -.2f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 1, .8f)); assertEquals(5, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 0, -.9f)); assertEquals(6, controllerAdapter.lastEventId); MappedController mappedController = new MappedController(controller, mappings); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = -.7f; assertEquals(.6f, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(.5f, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(-1f, mappedController.getConfiguredAxisValue(7), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(3), .01f); }
Example #14
Source File: InputMap.java From seventh with GNU General Public License v2.0 | 4 votes |
public void bindPovButton(PovDirection pov, String name) { this.povButtons[pov.ordinal()] = name; }
Example #15
Source File: InputMap.java From seventh with GNU General Public License v2.0 | 4 votes |
public void removePovBind(PovDirection pov) { this.povButtons[pov.ordinal()] = null; }
Example #16
Source File: JoystickGameController.java From seventh with GNU General Public License v2.0 | 4 votes |
public boolean isButtonReleased(ControllerButtons button) { switch(button) { case NORTH_DPAD_BTN: return !isPovDirectionDown(PovDirection.north); case NE_DPAD_BTN: return !isPovDirectionDown(PovDirection.northEast); case EAST_DPAD_BTN: return !isPovDirectionDown(PovDirection.east); case SE_DPAD_BTN: return !isPovDirectionDown(PovDirection.southEast); case SOUTH_DPAD_BTN: return !isPovDirectionDown(PovDirection.south); case SW_DPAD_BTN: return !isPovDirectionDown(PovDirection.southWest); case WEST_DPAD_BTN: return !isPovDirectionDown(PovDirection.west); case NW_DPAD_BTN: return !isPovDirectionDown(PovDirection.northWest); case LEFT_TRIGGER_BTN: return !isLeftTriggerDown(); case RIGHT_TRIGGER_BTN: return !isRightTriggerDown(); case LEFT_BUMPER_BTN: return this.isButtonReleased[4]; case RIGHT_BUMPER_BTN: return this.isButtonReleased[5]; case LEFT_JOYSTICK_BTN: return this.isButtonReleased[8]; case RIGHT_JOYSTICK_BTN: return this.isButtonReleased[9]; case START_BTN: return this.isButtonReleased[7]; case SELECT_BTN: return this.isButtonReleased[6]; case A_BTN: return this.isButtonReleased[0]; case B_BTN: return this.isButtonReleased[1]; case X_BTN: return this.isButtonReleased[2]; case Y_BTN: return this.isButtonReleased[3]; default: return false; } }
Example #17
Source File: MappedControllerAdapter.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Override public boolean povMoved(Controller controller, int povIndex, PovDirection value) { ControllerMappings.MappedInputs mapping = mappings.getControllerMapping(controller); if (mapping == null) return false; ConfiguredInput configuredInputV = mapping.getConfiguredFromPov(povIndex, true); ConfiguredInput configuredInputH = mapping.getConfiguredFromPov(povIndex, false); float valueH = 0; float valueV = 0; boolean handledH = false; boolean handledV = false; switch (value) { case east: valueH = 1f; break; case northEast: valueH = 1f; case north: valueV = -1f; break; case northWest: valueV = -1f; case west: valueH = -1f; break; case southEast: valueH = 1f; case south: valueV = 1f; break; case southWest: valueV = 1f; valueH = -1f; break; } if (configuredInputH != null) handledH = configuredAxisMoved(controller, configuredInputH.inputId, valueH); if (configuredInputV != null) handledV = configuredAxisMoved(controller, configuredInputV.inputId, valueV); return handledH || handledV; }
Example #18
Source File: BufferBciController.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** Unimplemented methods **/ @Override public PovDirection getPov(int povCode) { return null; }
Example #19
Source File: JamepadController.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Override public PovDirection getPov(int povCode) { // not supported return PovDirection.center; }
Example #20
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 2 votes |
/** * @param dir * @return true if the supplied {@link PovDirection} is down */ public boolean isPovDirectionDown(PovDirection dir) { return povDirections[dir.ordinal()]; }