|
@@ -5,6 +5,7 @@
|
|
*/
|
|
*/
|
|
package com.jme3.input.vr;
|
|
package com.jme3.input.vr;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
@@ -183,28 +184,50 @@ public class OpenVRInput implements VRInputAPI {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Vector3f getVelocity(int controllerIndex) {
|
|
public Vector3f getVelocity(int controllerIndex) {
|
|
- int index = OpenVRInput.controllerIndex[controllerIndex];
|
|
|
|
- if( needsNewVelocity[index] ) {
|
|
|
|
- OpenVR.hmdTrackedDevicePoses[index].readField("vVelocity");
|
|
|
|
- needsNewVelocity[index] = false;
|
|
|
|
- }
|
|
|
|
- tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[0];
|
|
|
|
- tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[1];
|
|
|
|
- tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vVelocity.v[2];
|
|
|
|
- return tempVel;
|
|
|
|
|
|
+
|
|
|
|
+ if (environment != null){
|
|
|
|
+
|
|
|
|
+ if (environment.getVRHardware() instanceof OpenVR){
|
|
|
|
+ int index = OpenVRInput.controllerIndex[controllerIndex];
|
|
|
|
+ if( needsNewVelocity[index] ) {
|
|
|
|
+ ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vVelocity");
|
|
|
|
+ needsNewVelocity[index] = false;
|
|
|
|
+ }
|
|
|
|
+ tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[0];
|
|
|
|
+ tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[1];
|
|
|
|
+ tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vVelocity.v[2];
|
|
|
|
+ return tempVel;
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR input is not attached to a VR environment.");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Vector3f getAngularVelocity(int controllerIndex) {
|
|
public Vector3f getAngularVelocity(int controllerIndex) {
|
|
- int index = OpenVRInput.controllerIndex[controllerIndex];
|
|
|
|
- if( needsNewAngVelocity[index] ) {
|
|
|
|
- OpenVR.hmdTrackedDevicePoses[index].readField("vAngularVelocity");
|
|
|
|
- needsNewAngVelocity[index] = false;
|
|
|
|
- }
|
|
|
|
- tempVel.x = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[0];
|
|
|
|
- tempVel.y = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[1];
|
|
|
|
- tempVel.z = OpenVR.hmdTrackedDevicePoses[index].vAngularVelocity.v[2];
|
|
|
|
- return tempVel;
|
|
|
|
|
|
+
|
|
|
|
+ if (environment != null){
|
|
|
|
+
|
|
|
|
+ if (environment.getVRHardware() instanceof OpenVR){
|
|
|
|
+
|
|
|
|
+ int index = OpenVRInput.controllerIndex[controllerIndex];
|
|
|
|
+ if( needsNewAngVelocity[index] ) {
|
|
|
|
+ ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].readField("vAngularVelocity");
|
|
|
|
+ needsNewAngVelocity[index] = false;
|
|
|
|
+ }
|
|
|
|
+ tempVel.x = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[0];
|
|
|
|
+ tempVel.y = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[1];
|
|
|
|
+ tempVel.z = ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[index].vAngularVelocity.v[2];
|
|
|
|
+ return tempVel;
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR input is not attached to a VR environment.");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -309,7 +332,16 @@ public class OpenVRInput implements VRInputAPI {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- return OpenVR.hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid != 0;
|
|
|
|
|
|
+ if (environment != null){
|
|
|
|
+
|
|
|
|
+ if (environment.getVRHardware() instanceof OpenVR){
|
|
|
|
+ return ((OpenVR)environment.getVRHardware()).hmdTrackedDevicePoses[controllerIndex[index]].bPoseIsValid != 0;
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR input is not attached to a VR environment.");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -317,9 +349,19 @@ public class OpenVRInput implements VRInputAPI {
|
|
if( isInputDeviceTracking(index) == false ){
|
|
if( isInputDeviceTracking(index) == false ){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- index = controllerIndex[index];
|
|
|
|
- VRUtil.convertMatrix4toQuat(OpenVR.poseMatrices[index], rotStore[index]);
|
|
|
|
- return rotStore[index];
|
|
|
|
|
|
+
|
|
|
|
+ if (environment != null){
|
|
|
|
+
|
|
|
|
+ if (environment.getVRHardware() instanceof OpenVR){
|
|
|
|
+ index = controllerIndex[index];
|
|
|
|
+ VRUtil.convertMatrix4toQuat(((OpenVR)environment.getVRHardware()).poseMatrices[index], rotStore[index]);
|
|
|
|
+ return rotStore[index];
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR input is not attached to a VR environment.");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -328,12 +370,23 @@ public class OpenVRInput implements VRInputAPI {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- // the hmdPose comes in rotated funny, fix that here
|
|
|
|
- index = controllerIndex[index];
|
|
|
|
- OpenVR.poseMatrices[index].toTranslationVector(posStore[index]);
|
|
|
|
- posStore[index].x = -posStore[index].x;
|
|
|
|
- posStore[index].z = -posStore[index].z;
|
|
|
|
- return posStore[index];
|
|
|
|
|
|
+ if (environment != null){
|
|
|
|
+
|
|
|
|
+ if (environment.getVRHardware() instanceof OpenVR){
|
|
|
|
+ // the hmdPose comes in rotated funny, fix that here
|
|
|
|
+ index = controllerIndex[index];
|
|
|
|
+ ((OpenVR)environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]);
|
|
|
|
+ posStore[index].x = -posStore[index].x;
|
|
|
|
+ posStore[index].z = -posStore[index].z;
|
|
|
|
+ return posStore[index];
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new IllegalStateException("VR input is not attached to a VR environment.");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -424,6 +477,12 @@ public class OpenVRInput implements VRInputAPI {
|
|
|
|
|
|
controllerIndex[controllerCount] = i;
|
|
controllerIndex[controllerCount] = i;
|
|
|
|
|
|
|
|
+ // Adding tracked controller to control.
|
|
|
|
+ if (trackedControllers == null){
|
|
|
|
+ trackedControllers = new ArrayList<VRTrackedController>(JOpenVRLibrary.k_unMaxTrackedDeviceCount);
|
|
|
|
+ }
|
|
|
|
+ trackedControllers.add(new OpenVRTrackedController(i, this, controllerName, manufacturerName, environment));
|
|
|
|
+
|
|
// Send an Haptic pulse to the controller
|
|
// Send an Haptic pulse to the controller
|
|
triggerHapticPulse(controllerCount, 1.0f);
|
|
triggerHapticPulse(controllerCount, 1.0f);
|
|
|
|
|