aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jinput
diff options
context:
space:
mode:
Diffstat (limited to 'ardor3d-jinput')
-rw-r--r--ardor3d-jinput/build.gradle6
-rw-r--r--ardor3d-jinput/pom.xml26
-rw-r--r--ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java126
3 files changed, 158 insertions, 0 deletions
diff --git a/ardor3d-jinput/build.gradle b/ardor3d-jinput/build.gradle
new file mode 100644
index 0000000..b7bff7b
--- /dev/null
+++ b/ardor3d-jinput/build.gradle
@@ -0,0 +1,6 @@
+
+description = 'Ardor 3D JINPUT'
+dependencies {
+ compile project(':ardor3d-core')
+ compile group: 'net.java.jinput', name: 'jinput', version:'2.0.6'
+}
diff --git a/ardor3d-jinput/pom.xml b/ardor3d-jinput/pom.xml
new file mode 100644
index 0000000..48f7910
--- /dev/null
+++ b/ardor3d-jinput/pom.xml
@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.ardor3d</groupId>
+ <artifactId>ardor3d</artifactId>
+ <relativePath>../pom.xml</relativePath>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ardor3d-jinput</artifactId>
+ <packaging>bundle</packaging>
+ <name>Ardor 3D JINPUT</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ardor3d-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.java.jinput</groupId>
+ <artifactId>jinput</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java b/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java
new file mode 100644
index 0000000..52ab50a
--- /dev/null
+++ b/ardor3d-jinput/src/main/java/com/ardor3d/input/jinput/JInputControllerWrapper.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2008-2012 Ardor Labs, Inc.
+ *
+ * This file is part of Ardor3D.
+ *
+ * Ardor3D is free software: you can redistribute it and/or modify it
+ * under the terms of its license which may be found in the accompanying
+ * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.input.jinput;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import net.java.games.input.Component;
+import net.java.games.input.Component.Identifier;
+import net.java.games.input.Controller;
+import net.java.games.input.Controller.Type;
+import net.java.games.input.ControllerEnvironment;
+import net.java.games.input.Event;
+
+import com.ardor3d.input.ControllerEvent;
+import com.ardor3d.input.ControllerInfo;
+import com.ardor3d.input.ControllerState;
+import com.ardor3d.input.ControllerWrapper;
+import com.google.common.collect.AbstractIterator;
+import com.google.common.collect.PeekingIterator;
+
+public class JInputControllerWrapper implements ControllerWrapper {
+
+ protected final Event _event = new Event();
+ protected final List<ControllerEvent> _events = Collections.synchronizedList(new ArrayList<ControllerEvent>());
+ protected JInputControllerEventIterator _eventsIt = new JInputControllerEventIterator();
+ protected final List<ControllerInfo> _controllers = new ArrayList<ControllerInfo>();
+ protected static boolean _inited = false;
+
+ @Override
+ public PeekingIterator<ControllerEvent> getEvents() {
+ init();
+ if (!_eventsIt.hasNext()) {
+ _eventsIt = new JInputControllerEventIterator();
+ }
+ for (final Controller controller : ControllerEnvironment.getDefaultEnvironment().getControllers()) {
+ controller.poll();
+ while (controller.getEventQueue().getNextEvent(_event)) {
+ if (controller.getType() != Type.KEYBOARD && controller.getType() != Type.MOUSE) {
+ _events.add(createControllerEvent(controller, _event));
+ }
+ }
+ }
+
+ return _eventsIt;
+ }
+
+ @Override
+ public int getControllerCount() {
+ init();
+ return _controllers.size();
+ }
+
+ @Override
+ public ControllerInfo getControllerInfo(final int controllerIndex) {
+ init();
+ return _controllers.get(controllerIndex);
+ }
+
+ @Override
+ public synchronized void init() {
+ if (_inited) {
+ return;
+ }
+
+ try {
+ ControllerEnvironment.getDefaultEnvironment();
+
+ for (final Controller controller : ControllerEnvironment.getDefaultEnvironment().getControllers()) {
+ if (controller.getType() != Type.KEYBOARD && controller.getType() != Type.MOUSE) {
+ _controllers.add(getControllerInfo(controller));
+ for (final Component component : controller.getComponents()) {
+ ControllerState.NOTHING.set(controller.getName(), component.getIdentifier().getName(), 0);
+ }
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ } finally {
+ _inited = true;
+ }
+ }
+
+ protected ControllerInfo getControllerInfo(final Controller controller) {
+ final List<String> axisNames = new ArrayList<String>();
+ final List<String> buttonNames = new ArrayList<String>();
+
+ for (final Component comp : controller.getComponents()) {
+ if (comp.getIdentifier() instanceof Identifier.Axis) {
+ axisNames.add(comp.getName());
+ } else if (comp.getIdentifier() instanceof Identifier.Button) {
+ buttonNames.add(comp.getName());
+ }
+ }
+
+ return new ControllerInfo(controller.getName(), axisNames, buttonNames);
+ }
+
+ protected ControllerEvent createControllerEvent(final Controller controller, final Event event) {
+ return new ControllerEvent(event.getNanos(), controller.getName(), event.getComponent().getIdentifier()
+ .getName(), event.getValue());
+ }
+
+ protected class JInputControllerEventIterator extends AbstractIterator<ControllerEvent> implements
+ PeekingIterator<ControllerEvent> {
+
+ @Override
+ protected ControllerEvent computeNext() {
+ if (_events.size() > 0) {
+ final ControllerEvent controllerEvent = _events.remove(0);
+ return controllerEvent;
+ } else {
+ return endOfData();
+ }
+ }
+ }
+} \ No newline at end of file