Java Code Examples for com.jme3.renderer.Camera#setLocation()

The following examples show how to use com.jme3.renderer.Camera#setLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VRApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates the camera to use for rendering. Default values are perspective
 * projection with 45° field of view, with near and far values 1 and 1000
 * units respectively.
 */
private void initCamera(){
    cam = new Camera(settings.getWidth(), settings.getHeight());

    cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
    cam.setLocation(new Vector3f(0f, 0f, 10f));
    cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    renderManager = new RenderManager(renderer);
    //Remy - 09/14/2010 setted the timer in the renderManager
    renderManager.setTimer(timer);

    viewPort = renderManager.createMainView("Default", cam);
    viewPort.setClearFlags(true, true, true);

    // Create a new cam for the gui
    Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
    guiViewPort = renderManager.createPostView("Gui Default", guiCam);
    guiViewPort.setClearFlags(false, false, false);
}
 
Example 2
Source File: LegacyApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates the camera to use for rendering. Default values are perspective
 * projection with 45° field of view, with near and far values 1 and 1000
 * units respectively.
 */
private void initCamera(){
    cam = new Camera(settings.getWidth(), settings.getHeight());

    cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
    cam.setLocation(new Vector3f(0f, 0f, 10f));
    cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    renderManager = new RenderManager(renderer);
    //Remy - 09/14/2010 setted the timer in the renderManager
    renderManager.setTimer(timer);

    if (prof != null) {
        renderManager.setAppProfiler(prof);
    }

    viewPort = renderManager.createMainView("Default", cam);
    viewPort.setClearFlags(true, true, true);

    // Create a new cam for the gui
    Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
    guiViewPort = renderManager.createPostView("Gui Default", guiCam);
    guiViewPort.setClearFlags(false, false, false);
}
 
Example 3
Source File: PointLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 * @param viewCam
 * @return true if intersects
 */
@Override
protected boolean checkCulling(Camera viewCam) {

    if (light == null) {
        return false;
    }

    Camera cam = viewCam;
    if(frustumCam != null){
        cam = frustumCam;            
        cam.setLocation(viewCam.getLocation());
        cam.setRotation(viewCam.getRotation());
    }
    TempVars vars = TempVars.get();
    boolean intersects = light.intersectsFrustum(cam,vars);
    vars.release();
    return intersects;
}
 
Example 4
Source File: LightFilterTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setUp() {
    filter = new DefaultLightFilter();
    
    cam = new Camera(512, 512);
    cam.setFrustumPerspective(45, 1, 1, 1000);
    cam.setLocation(Vector3f.ZERO);
    cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
    filter.setCamera(cam);
    
    Box box = new Box(1, 1, 1);
    geom = new Geometry("geom", box);
    geom.setLocalTranslation(0, 0, 10);
    geom.updateGeometricState();
    list = new LightList(geom);
}
 
Example 5
Source File: ShadowCamera.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Updates the camera view direction and position based on the light
 */
public void updateLightCamera(Camera lightCam) {
    if (target.getType() == Light.Type.Directional) {
        DirectionalLight dl = (DirectionalLight) target;
        lightCam.setParallelProjection(true);
        lightCam.setLocation(Vector3f.ZERO);
        lightCam.lookAtDirection(dl.getDirection(), Vector3f.UNIT_Y);
        lightCam.setFrustum(-1, 1, -1, 1, 1, -1);
    } else {
        PointLight pl = (PointLight) target;
        lightCam.setParallelProjection(false);
        lightCam.setLocation(pl.getPosition());
        // direction will have to be calculated automatically
        lightCam.setFrustumPerspective(45, 1, 1, 300);
    }
}
 
Example 6
Source File: Application.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates the camera to use for rendering. Default values are perspective
 * projection with 45° field of view, with near and far values 1 and 1000
 * units respectively.
 */
private void initCamera(){
    cam = new Camera(settings.getWidth(), settings.getHeight());

    cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
    cam.setLocation(new Vector3f(0f, 0f, 10f));
    cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    renderManager = new RenderManager(renderer);
    //Remy - 09/14/2010 setted the timer in the renderManager
    renderManager.setTimer(timer);
    viewPort = renderManager.createMainView("Default", cam);
    viewPort.setClearFlags(true, true, true);

    // Create a new cam for the gui
    Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
    guiViewPort = renderManager.createPostView("Gui Default", guiCam);
    guiViewPort.setClearFlags(false, false, false);
}
 
Example 7
Source File: TestRenderToTexture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Texture setupOffscreenView(){
    Camera offCamera = new Camera(512, 512);

    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);

    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);

    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    //setup framebuffer's texture
    Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);

    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setColorTexture(offTex);
    
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);

    // setup framebuffer's scene
    Box boxMesh = new Box(1, 1, 1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);

    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
    
    return offTex;
}
 
Example 8
Source File: WaterUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam){
    
    TempVars vars = TempVars.get();
     //Temp vects for reflection cam orientation calculation
    Vector3f sceneTarget =  vars.vect1;
    Vector3f  reflectDirection =  vars.vect2;
    Vector3f  reflectUp =  vars.vect3;
    Vector3f  reflectLeft = vars.vect4;
    Vector3f  camLoc = vars.vect5;
    camLoc = plane.reflect(sceneCam.getLocation(), camLoc);
    reflectionCam.setLocation(camLoc);
    reflectionCam.setFrustum(sceneCam.getFrustumNear(),
            sceneCam.getFrustumFar(),
            sceneCam.getFrustumLeft(),
            sceneCam.getFrustumRight(),
            sceneCam.getFrustumTop(),
            sceneCam.getFrustumBottom());
    reflectionCam.setParallelProjection(sceneCam.isParallelProjection());

    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6));
    reflectDirection = plane.reflect(sceneTarget, reflectDirection);
    reflectDirection.subtractLocal(camLoc);

    sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6));
    reflectUp = plane.reflect(sceneTarget, reflectUp);
    reflectUp.subtractLocal(camLoc);

    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6));
    reflectLeft = plane.reflect(sceneTarget, reflectLeft);
    reflectLeft.subtractLocal(camLoc);

    reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection);

    vars.release();
}
 
Example 9
Source File: SpotLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 * @param viewCam
 * @return true if intersects, otherwise false
 */
@Override
protected boolean checkCulling(Camera viewCam) {      
    Camera cam = viewCam;
    if(frustumCam != null){
        cam = frustumCam;            
        cam.setLocation(viewCam.getLocation());
        cam.setRotation(viewCam.getRotation());
    }
    TempVars vars = TempVars.get();
    boolean intersects = light.intersectsFrustum(cam,vars);
    vars.release();
    return intersects;
    
}
 
Example 10
Source File: TestRenderToTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Texture setupOffscreenView(){
    Camera offCamera = new Camera(512, 512);

    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);

    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);

    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    //setup framebuffer's texture
    Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);

    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setColorTexture(offTex);
    
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);

    // setup framebuffer's scene
    Box boxMesh = new Box(Vector3f.ZERO, 1,1,1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);

    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
    
    return offTex;
}
 
Example 11
Source File: TestMultiViews.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // create the geometry and attach it
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(3);

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());

    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);

    // Setup first view
    viewPort.setBackgroundColor(ColorRGBA.Blue);
    cam.setViewPort(.5f, 1f, 0f, 0.5f);
    cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
    cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));

    // Setup second view
    Camera cam2 = cam.clone();
    cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
    cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));

    ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
    view2.setClearFlags(true, true, true);
    view2.attachScene(rootNode);

    // Setup third view
    Camera cam3 = cam.clone();
    cam3.setViewPort(0f, .5f, .5f, 1f);
    cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));

    ViewPort view3 = renderManager.createMainView("Top Left", cam3);
    view3.setClearFlags(true, true, true);
    view3.attachScene(rootNode);

    // Setup fourth view
    Camera cam4 = cam.clone();
    cam4.setViewPort(.5f, 1f, .5f, 1f);
    cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
    cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));

    ViewPort view4 = renderManager.createMainView("Top Right", cam4);
    view4.setClearFlags(true, true, true);
    view4.attachScene(rootNode);

    //test multiview for gui 
    guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f);

    // Setup second gui view
    Camera guiCam2 = guiViewPort.getCamera().clone();
    guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2);
    guiViewPort2.setClearFlags(false, false, false);
    guiViewPort2.attachScene(guiViewPort.getScenes().get(0));

}
 
Example 12
Source File: TestRenderToMemory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setupOffscreenView(){
        offCamera = new Camera(width, height);

        // create a pre-view. a view that is rendered before the main view
        offView = renderManager.createPreView("Offscreen View", offCamera);
        offView.setBackgroundColor(ColorRGBA.DarkGray);
        offView.setClearFlags(true, true, true);
        
        // this will let us know when the scene has been rendered to the 
        // frame buffer
        offView.addProcessor(this);

        // create offscreen framebuffer
        offBuffer = new FrameBuffer(width, height, 1);

        //setup framebuffer's cam
        offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
        offCamera.setLocation(new Vector3f(0f, 0f, -5f));
        offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

        //setup framebuffer's texture
//        offTex = new Texture2D(width, height, Format.RGBA8);

        //setup framebuffer to use renderbuffer
        // this is faster for gpu -> cpu copies
        offBuffer.setDepthBuffer(Format.Depth);
        offBuffer.setColorBuffer(Format.RGBA8);
//        offBuffer.setColorTexture(offTex);
        
        //set viewport to render to offscreen framebuffer
        offView.setOutputFrameBuffer(offBuffer);

        // setup framebuffer's scene
        Box boxMesh = new Box(1, 1, 1);
        Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
        offBox = new Geometry("box", boxMesh);
        offBox.setMaterial(material);

        // attach the scene to the viewport to be rendered
        offView.attachScene(offBox);
    }
 
Example 13
Source File: TestRenderToCubemap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Texture setupOffscreenView(){
    Camera offCamera = new Camera(512, 512);
 
    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);
 
    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
 
    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
 
    //setup framebuffer's texture
    TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);
 
    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setMultiTarget(true);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
    
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);
 
    // setup framebuffer's scene
    Box boxMesh = new Box( 1,1,1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);
 
    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
 
    return offTex;
}
 
Example 14
Source File: TestMultiViews.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
    // create the geometry and attach it
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teaGeom.scale(3);

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());

    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);

    // Setup first view
    viewPort.setBackgroundColor(ColorRGBA.Blue);
    cam.setViewPort(.5f, 1f, 0f, 0.5f);
    cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
    cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));

    // Setup second view
    Camera cam2 = cam.clone();
    cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
    cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));

    ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
    view2.setClearFlags(true, true, true);
    view2.attachScene(rootNode);

    // Setup third view
    Camera cam3 = cam.clone();
    cam3.setViewPort(0f, .5f, .5f, 1f);
    cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
    cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));

    ViewPort view3 = renderManager.createMainView("Top Left", cam3);
    view3.setClearFlags(true, true, true);
    view3.attachScene(rootNode);

    // Setup fourth view
    Camera cam4 = cam.clone();
    cam4.setViewPort(.5f, 1f, .5f, 1f);
    cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
    cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));

    ViewPort view4 = renderManager.createMainView("Top Right", cam4);
    view4.setClearFlags(true, true, true);
    view4.attachScene(rootNode);

    //test multiview for gui 
    guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f);

    // Setup second gui view
    Camera guiCam2 = guiViewPort.getCamera().clone();
    guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2);
    guiViewPort2.setClearFlags(false, false, false);
    guiViewPort2.attachScene(guiViewPort.getScenes().get(0));

}
 
Example 15
Source File: TestRenderToMemory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setupOffscreenView(){
        offCamera = new Camera(width, height);

        // create a pre-view. a view that is rendered before the main view
        offView = renderManager.createPreView("Offscreen View", offCamera);
        offView.setBackgroundColor(ColorRGBA.DarkGray);
        offView.setClearFlags(true, true, true);
        
        // this will let us know when the scene has been rendered to the 
        // frame buffer
        offView.addProcessor(this);

        // create offscreen framebuffer
        offBuffer = new FrameBuffer(width, height, 1);

        //setup framebuffer's cam
        offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
        offCamera.setLocation(new Vector3f(0f, 0f, -5f));
        offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

        //setup framebuffer's texture
//        offTex = new Texture2D(width, height, Format.RGBA8);

        //setup framebuffer to use renderbuffer
        // this is faster for gpu -> cpu copies
        offBuffer.setDepthBuffer(Format.Depth);
        offBuffer.setColorBuffer(Format.RGBA8);
//        offBuffer.setColorTexture(offTex);
        
        //set viewport to render to offscreen framebuffer
        offView.setOutputFrameBuffer(offBuffer);

        // setup framebuffer's scene
        Box boxMesh = new Box(Vector3f.ZERO, 1,1,1);
        Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
        offBox = new Geometry("box", boxMesh);
        offBox.setMaterial(material);

        // attach the scene to the viewport to be rendered
        offView.attachScene(offBox);
    }