Advertisement
Guest User

ViewPort resizing and fpp bug

a guest
Feb 27th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.35 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2009-2012 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.post.FilterPostProcessor;
  40. import com.jme3.post.filters.BloomFilter;
  41. import com.jme3.post.ssao.SSAOFilter;
  42. import com.jme3.renderer.Camera;
  43. import com.jme3.renderer.ViewPort;
  44. import com.jme3.scene.Geometry;
  45.  
  46. public class TestMultiViews extends SimpleApplication {
  47.  
  48.         public static void main(String[] args) {
  49.                 TestMultiViews app = new TestMultiViews();
  50.                 app.start();
  51.         }
  52.  
  53.         Geometry teaGeom;
  54.  
  55.         public void simpleInitApp() {
  56.                 // create the geometry and attach it
  57.                 teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
  58.                 teaGeom.scale(3);
  59.  
  60.                 DirectionalLight dl = new DirectionalLight();
  61.                 dl.setColor(ColorRGBA.White);
  62.                 dl.setDirection(Vector3f.UNIT_XYZ.negate());
  63.  
  64.                 rootNode.addLight(dl);
  65.                 rootNode.attachChild(teaGeom);
  66.  
  67.                 // Setup first view
  68.                 viewPort.setBackgroundColor(ColorRGBA.Blue);
  69.                 cam.setViewPort(.5f, 1f, 0f, 0.5f);
  70.                 cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f));
  71.                 cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f));
  72.  
  73.                 // Setup second view
  74.                 Camera cam2 = cam.clone();
  75.                 cam2.setViewPort(0f, 0.5f, 0f, 0.5f);
  76.                 cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
  77.                 cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));
  78.  
  79.                 ViewPort view2 = renderManager.createMainView("Bottom Left", cam2);
  80.                 view2.setBackgroundColor(ColorRGBA.Red);
  81.                 view2.setClearFlags(true, true, true);
  82.                 view2.attachScene(rootNode);
  83.  
  84.                 // Setup third view
  85.                 Camera cam3 = cam.clone();
  86.                 cam3.setViewPort(0f, .5f, .5f, 1f);
  87.                 cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f));
  88.                 cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f));
  89.  
  90.                 ViewPort view3 = renderManager.createMainView("Top Left", cam3);
  91.                 view3.setBackgroundColor(ColorRGBA.Green);
  92.                 view3.setClearFlags(true, true, true);
  93.                 view3.attachScene(rootNode);
  94.  
  95.                 // Setup fourth view
  96.                 Camera cam4 = cam.clone();
  97.  
  98.                 // These three lines of code are to make view4/cam4 take up the top 40 percent of the screen
  99.                 float percentageVertical = 0.4f;
  100.                 cam4.resize(settings.getWidth(), Math.round(settings.getHeight() * percentageVertical), true);
  101.                 cam4.setViewPort(0f, 1, (1 - percentageVertical) / percentageVertical, 1 / percentageVertical);
  102.  
  103.                 // these "alternate" cases kind of help reveal whats going on with this fpp bug (0,1,0,1) sizes it correctly but its on the bottom, 0,1,.5,1.5 shifts it up but it gets clipped
  104.                 //cam4.setViewPort(0, 1, 0, 1);
  105.                 //cam4.setViewPort(0, 1, 0.5f, 1.5f);
  106.  
  107.                 cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f));
  108.                 cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f));
  109.  
  110.                 ViewPort view4 = renderManager.createMainView("Top Right", cam4);
  111.                 view4.setBackgroundColor(ColorRGBA.Yellow);
  112.                 view4.setClearFlags(true, true, true);
  113.                 view4.attachScene(rootNode);
  114.  
  115.                 FilterPostProcessor fpp2 = new FilterPostProcessor(assetManager);
  116.                 BloomFilter bloomFilter = new BloomFilter();
  117.                 fpp2.addFilter(bloomFilter);
  118.  
  119.                 view4.addProcessor(fpp2); // if you comment out this line, then my code to create a long horizontal viewport works
  120.  
  121.                 //test multiview for gui
  122.                 guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f);
  123.  
  124.                 // Setup second gui view
  125.                 Camera guiCam2 = guiViewPort.getCamera().clone();
  126.                 guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f);
  127.                 ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2);
  128.                 guiViewPort2.setClearFlags(false, false, false);
  129.                 guiViewPort2.attachScene(guiViewPort.getScenes().get(0));
  130.  
  131.         }
  132.  
  133.         @Override
  134.         public void simpleUpdate(float tpf) {
  135.                 super.simpleUpdate(tpf);
  136.  
  137.                 teaGeom.rotate(0, tpf, 0);
  138.         }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement