Java Code Examples for com.badlogic.gdx.controllers.PovDirection#east()

The following examples show how to use com.badlogic.gdx.controllers.PovDirection#east() . 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 vote down vote up
@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 vote down vote up
@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: ControllerMappingsTest.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
@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 4
Source File: ControllerMappingsTest.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
@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);
}