Search in sources :

Example 11 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR 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) {
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
        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 *= resMult;
        size.y *= resMult;
        if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
            cam.resize((int) size.x, (int) size.y, false);
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) VRAPI(com.jme3.input.vr.VRAPI)

Example 12 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR 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.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 13 with Camera

use of com.jme3.renderer.Camera 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.");
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) VRAPI(com.jme3.input.vr.VRAPI)

Example 14 with Camera

use of com.jme3.renderer.Camera 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.");
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera) VRAPI(com.jme3.input.vr.VRAPI)

Example 15 with Camera

use of com.jme3.renderer.Camera 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.");
    }
}
Also used : Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7