making VRViewManagerOSVR more similar to VRViewManagerOpenVR

empirephoenix-patch-1
Rickard Edén 7 years ago
parent 22bf08d9e7
commit ffed048472
  1. 127
      jme3-vr/src/main/java/com/jme3/util/VRViewManagerOSVR.java

@ -50,18 +50,6 @@ import com.sun.jna.ptr.PointerByReference;
public class VRViewManagerOSVR extends AbstractVRViewManager{ public class VRViewManagerOSVR extends AbstractVRViewManager{
private static final Logger logger = Logger.getLogger(VRViewManagerOpenVR.class.getName()); private static final Logger logger = Logger.getLogger(VRViewManagerOpenVR.class.getName());
private Camera leftCamera;
private ViewPort leftViewport;
private FilterPostProcessor leftPostProcessor;
private Texture2D leftEyeTexture;
private Texture2D leftEyeDepth;
private Camera rightCamera;
private ViewPort rightViewport;
private FilterPostProcessor rightPostProcessor;
private Texture2D rightEyeTexture;
private Texture2D rightEyeDepth;
// OpenVR values // OpenVR values
private Texture_t leftTextureType; private Texture_t leftTextureType;
private Texture_t rightTextureType; private Texture_t rightTextureType;
@ -73,15 +61,10 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
OSVR_ViewportDescription.ByValue osvr_viewDescRight; OSVR_ViewportDescription.ByValue osvr_viewDescRight;
Pointer osvr_rmBufferState; Pointer osvr_rmBufferState;
//private static boolean useCustomDistortion;
private float heightAdjustment;
private Texture2D dualEyeTex; private Texture2D dualEyeTex;
private final PointerByReference grabRBS = new PointerByReference(); private final PointerByReference grabRBS = new PointerByReference();
private float resMult = 1f;
//final & temp values for camera calculations //final & temp values for camera calculations
private final Vector3f finalPosition = new Vector3f(); private final Vector3f finalPosition = new Vector3f();
private final Quaternion finalRotation = new Quaternion(); private final Quaternion finalRotation = new Quaternion();
@ -96,42 +79,6 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
this.environment = environment; this.environment = environment;
} }
/**
* Get the {@link Camera camera} attached to the left eye.
* @return the {@link Camera camera} attached to the left eye.
* @see #getRightCamera()
*/
public Camera getLeftCamera() {
return leftCamera;
}
/**
* Get the {@link Camera camera} attached to the right eye.
* @return the {@link Camera camera} attached to the right eye.
* @see #getLeftCamera()
*/
public Camera getRightCamera() {
return rightCamera;
}
/**
* Get the {@link ViewPort viewport} attached to the left eye.
* @return the {@link ViewPort viewport} attached to the left eye.
* @see #getRightViewPort()
*/
public ViewPort getLeftViewPort() {
return leftViewport;
}
/**
* Get the {@link ViewPort viewport} attached to the right eye.
* @return the {@link ViewPort viewport} attached to the right eye.
* @see #getLeftViewPort()
*/
public ViewPort getRightViewPort() {
return rightViewport;
}
/** /**
* Get the identifier of the left eye texture. * Get the identifier of the left eye texture.
* @return the identifier of the left eye texture. * @return the identifier of the left eye texture.
@ -162,42 +109,6 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
return (int)dualEyeTex.getImage().getId(); return (int)dualEyeTex.getImage().getId();
} }
/**
* Get the height adjustment to apply to the cameras before rendering.
* @return the height adjustment to apply to the cameras before rendering.
* @see #setHeightAdjustment(float)
*/
public float getHeightAdjustment() {
return heightAdjustment;
}
/**
* Set the height adjustment to apply to the cameras before rendering.
* @param amount the height adjustment to apply to the cameras before rendering.
* @see #getHeightAdjustment()
*/
public void setHeightAdjustment(float amount) {
heightAdjustment = amount;
}
/**
* Get the resolution multiplier.
* @return the resolution multiplier.
* @see #setResolutionMultiplier(float)
*/
public float getResolutionMuliplier() {
return resMult;
}
/**
* Set the resolution multiplier.
* @param resMult the resolution multiplier.
* @see #getResolutionMuliplier()
*/
public void setResolutionMultiplier(float resMult) {
this.resMult = resMult;
}
/** /**
* Initialize the system binds of the textures. * Initialize the system binds of the textures.
*/ */
@ -442,8 +353,8 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
// other adjustments // other adjustments
size.x *= xMult; size.x *= xMult;
size.x *= resMult; size.x *= getResolutionMuliplier();
size.y *= resMult; size.y *= getResolutionMuliplier();
if( cam.getWidth() != size.x || cam.getHeight() != size.y ){ if( cam.getWidth() != size.x || cam.getHeight() != size.y ){
cam.resize((int)size.x, (int)size.y, false); cam.resize((int)size.x, (int)size.y, false);
@ -469,10 +380,10 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
return; return;
} }
leftEyeTexture = (Texture2D) leftViewport.getOutputFrameBuffer().getColorBuffer().getTexture(); leftEyeTexture = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getColorBuffer().getTexture();
rightEyeTexture = (Texture2D)rightViewport.getOutputFrameBuffer().getColorBuffer().getTexture(); rightEyeTexture = (Texture2D)getRightViewPort().getOutputFrameBuffer().getColorBuffer().getTexture();
leftEyeDepth = (Texture2D) leftViewport.getOutputFrameBuffer().getDepthBuffer().getTexture(); leftEyeDepth = (Texture2D) getLeftViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture();
rightEyeDepth = (Texture2D)rightViewport.getOutputFrameBuffer().getDepthBuffer().getTexture(); rightEyeDepth = (Texture2D)getRightViewPort().getOutputFrameBuffer().getDepthBuffer().getTexture();
// main viewport is either going to be a distortion scene or nothing // main viewport is either going to be a distortion scene or nothing
// mirroring is handled by copying framebuffers // mirroring is handled by copying framebuffers
@ -587,7 +498,7 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
if( obsPosition != null ){ if( obsPosition != null ){
finalPosition.addLocal(obsPosition); finalPosition.addLocal(obsPosition);
} }
finalPosition.y += heightAdjustment; finalPosition.y += getHeightAdjustment();
cam.setFrame(finalPosition, finalRotation); cam.setFrame(finalPosition, finalRotation);
} }
@ -595,7 +506,7 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
* Handles moving filters from the main view to each eye * Handles moving filters from the main view to each eye
*/ */
public void moveScreenProcessingToEyes() { public void moveScreenProcessingToEyes() {
if( rightViewport == null ){ if( getRightViewPort() == null ){
return; return;
} }
@ -617,7 +528,7 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
* @param sourceViewport the {@link ViewPort viewport} that contains the processors to use. * @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
*/ */
public void syncScreenProcessing(ViewPort sourceViewport) { public void syncScreenProcessing(ViewPort sourceViewport) {
if( rightViewport == null ){ if( getRightViewPort() == null ){
return; return;
} }
@ -631,13 +542,13 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
// clear out all filters & processors, to start from scratch // clear out all filters & processors, to start from scratch
rightPostProcessor.removeAllFilters(); rightPostProcessor.removeAllFilters();
leftPostProcessor.removeAllFilters(); leftPostProcessor.removeAllFilters();
leftViewport.clearProcessors(); getLeftViewPort().clearProcessors();
rightViewport.clearProcessors(); getRightViewPort().clearProcessors();
// if we have no processors to sync, don't add the FilterPostProcessor // if we have no processors to sync, don't add the FilterPostProcessor
if( sourceViewport.getProcessors().isEmpty() ) return; if( sourceViewport.getProcessors().isEmpty() ) return;
// add post processors we just made, which are empty // add post processors we just made, which are empty
leftViewport.addProcessor(leftPostProcessor); getLeftViewPort().addProcessor(leftPostProcessor);
rightViewport.addProcessor(rightPostProcessor); getRightViewPort().addProcessor(rightPostProcessor);
// go through all of the filters in the processors list // go through all of the filters in the processors list
// add them to the left viewport processor & clone them to the right // add them to the left viewport processor & clone them to the right
for(SceneProcessor sceneProcessor : sourceViewport.getProcessors()) { for(SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
@ -670,8 +581,8 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor; VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone(); VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
dlsrRight.setLight(dlsr.getLight()); dlsrRight.setLight(dlsr.getLight());
rightViewport.getProcessors().add(0, dlsrRight); getRightViewPort().getProcessors().add(0, dlsrRight);
leftViewport.getProcessors().add(0, sceneProcessor); getLeftViewPort().getProcessors().add(0, sceneProcessor);
} }
} }
// make sure each has a translucent filter renderer // make sure each has a translucent filter renderer
@ -718,16 +629,16 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
//org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB); //org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_FRAMEBUFFER_SRGB);
if( !environment.isInstanceRendering()) { if( !environment.isInstanceRendering()) {
leftViewport = setupViewBuffers(leftCamera, LEFT_VIEW_NAME); leftViewPort = setupViewBuffers(leftCamera, LEFT_VIEW_NAME);
rightCamera = leftCamera.clone(); rightCamera = leftCamera.clone();
if( environment.getVRHardware() != null ){ if( environment.getVRHardware() != null ){
rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera)); rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
} }
rightViewport = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME); rightViewPort = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME);
} else { } else {
System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!"); System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!");
leftViewport = environment.getApplication().getViewPort(); leftViewPort = environment.getApplication().getViewPort();
//leftViewport.attachScene(app.getRootNode()); //leftViewport.attachScene(app.getRootNode());
rightCamera = leftCamera.clone(); rightCamera = leftCamera.clone();
if( environment.getVRHardware() != null ){ if( environment.getVRHardware() != null ){
@ -742,7 +653,7 @@ public class VRViewManagerOSVR extends AbstractVRViewManager{
} }
// setup gui // setup gui
environment.getVRGUIManager().setupGui(leftCamera, rightCamera, leftViewport, rightViewport); environment.getVRGUIManager().setupGui(leftCamera, rightCamera, getLeftViewPort(), getRightViewPort());
if( environment.getVRHardware() != null ) { if( environment.getVRHardware() != null ) {
// call these to cache the results internally // call these to cache the results internally

Loading…
Cancel
Save