Removing more static references.
This commit is contained in:
parent
f7a852b755
commit
16b4dade2d
@ -8,6 +8,7 @@ import com.jme3.app.state.AppState;
|
||||
import com.jme3.input.vr.OSVR;
|
||||
import com.jme3.input.vr.OpenVR;
|
||||
import com.jme3.input.vr.VRAPI;
|
||||
import com.jme3.input.vr.VRBounds;
|
||||
import com.jme3.input.vr.VRInputAPI;
|
||||
import com.jme3.renderer.Camera;
|
||||
import com.jme3.scene.Spatial;
|
||||
@ -28,6 +29,8 @@ public class VREnvironment {
|
||||
private VRMouseManager mouseManager = null;
|
||||
private VRViewManager viewmanager = null;
|
||||
|
||||
private VRBounds bounds = null;
|
||||
|
||||
/**
|
||||
* The underlying system VR API. By default set to {@link VRConstants#SETTING_VRAPI_OPENVR_VALUE}.
|
||||
*/
|
||||
@ -65,7 +68,6 @@ public class VREnvironment {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private boolean attached = false;
|
||||
|
||||
public VREnvironment(AppSettings settings){
|
||||
|
||||
@ -73,7 +75,8 @@ public class VREnvironment {
|
||||
|
||||
guiManager = new VRGuiManager(this);
|
||||
mouseManager = new VRMouseManager(this);
|
||||
// dummyCam = new Camera(settings.getWidth(), settings.getHeight());
|
||||
|
||||
bounds = new VRBounds();
|
||||
|
||||
processSettings();
|
||||
}
|
||||
@ -86,6 +89,14 @@ public class VREnvironment {
|
||||
return hardware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VR bounds.
|
||||
* @return the VR bounds.
|
||||
*/
|
||||
public VRBounds getVRBounds(){
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VR dedicated input.
|
||||
* @return the VR dedicated input.
|
||||
@ -347,7 +358,12 @@ public class VREnvironment {
|
||||
if (application.getCamera() != null){
|
||||
dummyCam = application.getCamera().clone();
|
||||
} else {
|
||||
return new Camera(settings.getWidth(), settings.getHeight());
|
||||
|
||||
if ((settings != null) && (settings.getWidth() != 0) && (settings.getHeight() != 0)){
|
||||
dummyCam = new Camera(settings.getWidth(), settings.getHeight());
|
||||
} else {
|
||||
dummyCam = new Camera();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("VR environment is not attached to any application.");
|
||||
|
@ -46,14 +46,14 @@ public class OpenVR implements VRAPI {
|
||||
private static boolean initSuccess = false;
|
||||
private static boolean flipEyes = false;
|
||||
|
||||
private static IntBuffer hmdDisplayFrequency;
|
||||
private static TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference;
|
||||
protected static TrackedDevicePose_t[] hmdTrackedDevicePoses;
|
||||
private IntBuffer hmdDisplayFrequency;
|
||||
private TrackedDevicePose_t.ByReference hmdTrackedDevicePoseReference;
|
||||
protected TrackedDevicePose_t[] hmdTrackedDevicePoses;
|
||||
|
||||
protected static IntByReference hmdErrorStore;
|
||||
protected IntByReference hmdErrorStore;
|
||||
|
||||
private static final Quaternion rotStore = new Quaternion();
|
||||
private static final Vector3f posStore = new Vector3f();
|
||||
private final Quaternion rotStore = new Quaternion();
|
||||
private final Vector3f posStore = new Vector3f();
|
||||
|
||||
private static FloatByReference tlastVsync;
|
||||
|
||||
@ -65,20 +65,21 @@ public class OpenVR implements VRAPI {
|
||||
// for debugging latency
|
||||
private int frames = 0;
|
||||
|
||||
protected static Matrix4f[] poseMatrices;
|
||||
protected Matrix4f[] poseMatrices;
|
||||
|
||||
private static final Matrix4f hmdPose = Matrix4f.IDENTITY.clone();
|
||||
private static Matrix4f hmdProjectionLeftEye;
|
||||
private static Matrix4f hmdProjectionRightEye;
|
||||
private static Matrix4f hmdPoseLeftEye;
|
||||
private static Matrix4f hmdPoseRightEye;
|
||||
private final Matrix4f hmdPose = Matrix4f.IDENTITY.clone();
|
||||
private Matrix4f hmdProjectionLeftEye;
|
||||
private Matrix4f hmdProjectionRightEye;
|
||||
private Matrix4f hmdPoseLeftEye;
|
||||
private Matrix4f hmdPoseRightEye;
|
||||
|
||||
private static Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand;
|
||||
private Vector3f hmdPoseLeftEyeVec, hmdPoseRightEyeVec, hmdSeatToStand;
|
||||
|
||||
private float vsyncToPhotons;
|
||||
private double timePerFrame, frameCountRun;
|
||||
private long frameCount;
|
||||
private OpenVRInput VRinput;
|
||||
|
||||
private static float vsyncToPhotons;
|
||||
private static double timePerFrame, frameCountRun;
|
||||
private static long frameCount;
|
||||
private static OpenVRInput VRinput;
|
||||
|
||||
private VREnvironment environment = null;
|
||||
|
||||
@ -181,7 +182,7 @@ public class OpenVR implements VRAPI {
|
||||
VRinput.updateConnectedControllers();
|
||||
|
||||
// init bounds & chaperone info
|
||||
VRBounds.init();
|
||||
environment.getVRBounds().init(this);
|
||||
|
||||
logger.config("Initializing OpenVR system [SUCCESS]");
|
||||
initSuccess = true;
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.jme3.input.vr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -183,28 +184,50 @@ public class OpenVRInput implements VRInputAPI {
|
||||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
@ -309,7 +332,16 @@ public class OpenVRInput implements VRInputAPI {
|
||||
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
|
||||
@ -317,9 +349,19 @@ public class OpenVRInput implements VRInputAPI {
|
||||
if( isInputDeviceTracking(index) == false ){
|
||||
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
|
||||
@ -328,12 +370,23 @@ public class OpenVRInput implements VRInputAPI {
|
||||
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
|
||||
@ -411,9 +464,9 @@ public class OpenVRInput implements VRInputAPI {
|
||||
if (environment != null){
|
||||
controllerCount = 0;
|
||||
for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) {
|
||||
int classCallback = ((OpenVR)environment.getVRHardware()).getVRSystem().GetTrackedDeviceClass.apply(i);
|
||||
int classCallback = ((OpenVR)environment.getVRHardware()).getVRSystem().GetTrackedDeviceClass.apply(i);
|
||||
if( classCallback == JOpenVRLibrary.ETrackedDeviceClass.ETrackedDeviceClass_TrackedDeviceClass_Controller || classCallback == JOpenVRLibrary.ETrackedDeviceClass.ETrackedDeviceClass_TrackedDeviceClass_GenericTracker) {
|
||||
|
||||
|
||||
String controllerName = "Unknown";
|
||||
String manufacturerName = "Unknown";
|
||||
try {
|
||||
@ -425,6 +478,12 @@ public class OpenVRInput implements VRInputAPI {
|
||||
|
||||
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
|
||||
triggerHapticPulse(controllerCount, 1.0f);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user