Home | History | Annotate | Download | only in renderer
      1 /*
      2  * Copyright (c) 2009-2010 jMonkeyEngine
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      9  * * Redistributions of source code must retain the above copyright
     10  *   notice, this list of conditions and the following disclaimer.
     11  *
     12  * * Redistributions in binary form must reproduce the above copyright
     13  *   notice, this list of conditions and the following disclaimer in the
     14  *   documentation and/or other materials provided with the distribution.
     15  *
     16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
     17  *   may be used to endorse or promote products derived from this software
     18  *   without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 package jme3test.renderer;
     33 
     34 import com.jme3.app.SimpleApplication;
     35 import com.jme3.light.DirectionalLight;
     36 import com.jme3.math.ColorRGBA;
     37 import com.jme3.math.Quaternion;
     38 import com.jme3.math.Vector3f;
     39 import com.jme3.renderer.Camera;
     40 import com.jme3.renderer.ViewPort;
     41 import com.jme3.scene.Geometry;
     42 
     43 public class TestMultiViews extends SimpleApplication {
     44 
     45     public static void main(String[] args) {
     46         TestMultiViews app = new TestMultiViews();
     47         app.start();
     48     }
     49 
     50     public void simpleInitApp() {
     51         // create the geometry and attach it
     52         Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
     53         teaGeom.scale(3);
     54 
     55         DirectionalLight dl = new DirectionalLight();
     56         dl.setColor(ColorRGBA.White);
     57         dl.setDirection(Vector3f.UNIT_XYZ.negate());
     58 
     59         rootNode.addLight(dl);
     60         rootNode.attachChild(teaGeom);
     61 
     62         // Setup first view
     63         viewPort.setBackgroundColor(ColorRGBA.Blue);
     64         cam.setViewPort(.5f, 1f, 0f, 0.5f);
     65         cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
     66         cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));
     67 
     68         // Setup second view
     69         Camera cam2 = cam.clone();
     70         cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
     71         cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
     72         cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));
     73 
     74         ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
     75         view2.setClearFlags(true, true, true);
     76         view2.attachScene(rootNode);
     77 
     78         // Setup third view
     79         Camera cam3 = cam.clone();
     80         cam3.setViewPort(0f, .5f, .5f, 1f);
     81         cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
     82         cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
     83 
     84         ViewPort view3 = renderManager.createMainView("Top Left", cam3);
     85         view3.setClearFlags(true, true, true);
     86         view3.attachScene(rootNode);
     87 
     88         // Setup fourth view
     89         Camera cam4 = cam.clone();
     90         cam4.setViewPort(.5f, 1f, .5f, 1f);
     91         cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
     92         cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));
     93 
     94         ViewPort view4 = renderManager.createMainView("Top Right", cam4);
     95         view4.setClearFlags(true, true, true);
     96         view4.attachScene(rootNode);
     97 
     98         //test multiview for gui
     99         guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f);
    100 
    101         // Setup second gui view
    102         Camera guiCam2 = guiViewPort.getCamera().clone();
    103         guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f);
    104         ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2);
    105         guiViewPort2.setClearFlags(false, false, false);
    106         guiViewPort2.attachScene(guiViewPort.getScenes().get(0));
    107 
    108     }
    109 }
    110