use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method prepareCameraSize.
/**
* Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
* @param cam the {@link Camera camera} to prepare.
* @param xMult the camera width multiplier.
*/
private void prepareCameraSize(Camera cam, float xMult) {
if (environment != null) {
if (environment.getApplication() != null) {
Vector2f size = new Vector2f();
VRAPI vrhmd = environment.getVRHardware();
if (vrhmd == null) {
size.x = 1280f;
size.y = 720f;
} else {
vrhmd.getRenderSize(size);
}
if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
size.x = environment.getApplication().getContext().getSettings().getWidth();
}
if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
size.y = environment.getApplication().getContext().getSettings().getHeight();
}
if (environment.isInstanceRendering()) {
size.x *= 2f;
}
// other adjustments
size.x *= xMult;
size.x *= getResolutionMuliplier();
size.y *= getResolutionMuliplier();
if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
cam.resize((int) size.x, (int) size.y, false);
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method update.
@Override
public void update(float tpf) {
if (environment != null) {
// grab the observer
Object obs = environment.getObserver();
Quaternion objRot;
Vector3f objPos;
if (obs instanceof Camera) {
objRot = ((Camera) obs).getRotation();
objPos = ((Camera) obs).getLocation();
} else {
objRot = ((Spatial) obs).getWorldRotation();
objPos = ((Spatial) obs).getWorldTranslation();
}
// grab the hardware handle
VRAPI dev = environment.getVRHardware();
if (dev != null) {
// update the HMD's position & orientation
dev.updatePose();
dev.getPositionAndOrientation(hmdPos, hmdRot);
if (obs != null) {
// update hmdPos based on obs rotation
finalRotation.set(objRot);
finalRotation.mult(hmdPos, hmdPos);
finalRotation.multLocal(hmdRot);
}
finalizeCamera(dev.getHMDVectorPoseLeftEye(), objPos, getLeftCamera());
finalizeCamera(dev.getHMDVectorPoseRightEye(), objPos, getRightCamera());
} else {
getLeftCamera().setFrame(objPos, objRot);
getRightCamera().setFrame(objPos, objRot);
}
if (environment.hasTraditionalGUIOverlay()) {
// update the mouse?
environment.getVRMouseManager().update(tpf);
// update GUI position?
if (environment.getVRGUIManager().wantsReposition || environment.getVRGUIManager().getPositioningMode() != VRGUIPositioningMode.MANUAL) {
environment.getVRGUIManager().positionGuiNow(tpf);
environment.getVRGUIManager().updateGuiQuadGeometricState();
}
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupMirrorBuffers.
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
if (environment != null) {
if (environment.getApplication() != null) {
Camera clonecam = cam.clone();
ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
clonecam.setParallelProjection(true);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Picture pic = new Picture("fullscene");
pic.setLocalTranslation(-0.75f, -0.5f, 0f);
if (expand) {
pic.setLocalScale(3f, 1f, 1f);
} else {
pic.setLocalScale(1.5f, 1f, 1f);
}
pic.setQueueBucket(Bucket.Opaque);
pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
viewPort.attachScene(pic);
viewPort.setOutputFrameBuffer(null);
pic.updateGeometricState();
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupViewBuffers.
private ViewPort setupViewBuffers(Camera cam, String viewName) {
if (environment != null) {
if (environment.getApplication() != null) {
// create offscreen framebuffer
FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
//offBufferLeft.setSrgb(true);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBufferLeft.setDepthBuffer(Image.Format.Depth);
offBufferLeft.setColorTexture(offTex);
ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
viewPort.attachScene(spatialIter.next());
}
//set viewport to render to offscreen framebuffer
viewPort.setOutputFrameBuffer(offBufferLeft);
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method initTextureSubmitStructs.
/**
* Initialize the system binds of the textures.
*/
private void initTextureSubmitStructs() {
leftTextureType = new Texture_t();
rightTextureType = new Texture_t();
if (environment != null) {
if (environment.getVRHardware() instanceof OpenVR) {
leftTextureBounds = new VRTextureBounds_t();
rightTextureBounds = new VRTextureBounds_t();
// left eye
leftTextureBounds.uMax = 0.5f;
leftTextureBounds.uMin = 0f;
leftTextureBounds.vMax = 1f;
leftTextureBounds.vMin = 0f;
leftTextureBounds.setAutoSynch(false);
leftTextureBounds.setAutoRead(false);
leftTextureBounds.setAutoWrite(false);
leftTextureBounds.write();
// right eye
rightTextureBounds.uMax = 1f;
rightTextureBounds.uMin = 0.5f;
rightTextureBounds.vMax = 1f;
rightTextureBounds.vMin = 0f;
rightTextureBounds.setAutoSynch(false);
rightTextureBounds.setAutoRead(false);
rightTextureBounds.setAutoWrite(false);
rightTextureBounds.write();
// texture type
leftTextureType.eColorSpace = JOpenVRLibrary.EColorSpace.EColorSpace_ColorSpace_Gamma;
leftTextureType.eType = JOpenVRLibrary.ETextureType.ETextureType_TextureType_OpenGL;
leftTextureType.setAutoSynch(false);
leftTextureType.setAutoRead(false);
leftTextureType.setAutoWrite(false);
leftTextureType.handle = -1;
rightTextureType.eColorSpace = JOpenVRLibrary.EColorSpace.EColorSpace_ColorSpace_Gamma;
rightTextureType.eType = JOpenVRLibrary.ETextureType.ETextureType_TextureType_OpenGL;
rightTextureType.setAutoSynch(false);
rightTextureType.setAutoRead(false);
rightTextureType.setAutoWrite(false);
rightTextureType.handle = -1;
logger.config("Init eyes native texture binds");
logger.config(" Left eye texture");
logger.config(" address: " + leftTextureType.getPointer());
logger.config(" size: " + leftTextureType.size() + " bytes");
logger.config(" color space: " + OpenVRUtil.getEColorSpaceString(leftTextureType.eColorSpace));
logger.config(" type: " + OpenVRUtil.getETextureTypeString(leftTextureType.eType));
logger.config(" auto read: " + leftTextureType.getAutoRead());
logger.config(" auto write: " + leftTextureType.getAutoWrite());
logger.config(" handle address: " + leftTextureType.handle);
logger.config(" handle value: " + leftTextureType.handle);
logger.config("");
logger.config(" Right eye texture");
logger.config(" address: " + rightTextureType.getPointer());
logger.config(" size: " + rightTextureType.size() + " bytes");
logger.config(" color space: " + OpenVRUtil.getEColorSpaceString(rightTextureType.eColorSpace));
logger.config(" type: " + OpenVRUtil.getETextureTypeString(rightTextureType.eType));
logger.config(" auto read: " + rightTextureType.getAutoRead());
logger.config(" auto write: " + rightTextureType.getAutoWrite());
logger.config(" handle address: " + rightTextureType.handle);
logger.config(" handle value: " + rightTextureType.handle);
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
Aggregations