1

I have a UI with Three.js that have 1 perspectiveCamera and 3 OrthogonalCameras. I use viewports for render the cameras. So I have fours regions. The figure below show my situation.

enter image description here

I wish zooming or resizing these regions.

The fragment of code that i have is :

function setCamera(x, y, z) {

Screen_Width = window.innerWidth, Screen_Height = window.innerHeight;
View_Angle = 45, ASPECT = Screen_Width / Screen_Height, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera(View_Angle, ASPECT, NEAR, FAR);
camera.position.set(x, y, z);
camera.lookAt(scene.position);
scene.add(camera);
}

function setOtherCameras() {

Screen_Width = window.innerWidth, Screen_Width = window.innerHeight;

topCamera = new THREE.OrthographicCamera(
            Screen_Width / -4, // Left
            Screen_Width / 4, // Right
            Screen_Width / 4, // Top
            Screen_Width / -4, // Bottom
            -5000, // Near 
            10000); // Far -- enough to see the skybox
topCamera.up = new THREE.Vector3(0, 0, -1);
topCamera.lookAt(new THREE.Vector3(0, -1, 0));
scene.add(topCamera);

frontCamera = new THREE.OrthographicCamera(
            Screen_Width / -4, Screen_Width / 4,
            Screen_Width / 4, Screen_Width / -4, -5000, 10000);
frontCamera.lookAt(new THREE.Vector3(0, 0, -1));
scene.add(frontCamera);

sideCamera = new THREE.OrthographicCamera(
            Screen_Width / -4, Screen_Width / 4,
            Screen_Width / 4, Screen_Width / -4, -5000, 10000);
sideCamera.lookAt(new THREE.Vector3(1, 0, 0));
scene.add(sideCamera);
}

function render() {
   updateGrid();
   updateImages();

   var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
   // setViewport parameters: lower_left_x, lower_left_y, viewport_width, viewport_height
   renderer.setViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
   renderer.clear();

   var left,bottom,width,height;
   var zoomValue = 1;

   renderCamera(1, //left
                 0.25 * SCREEN_HEIGHT + 1,  //bottom
                 SCREEN_WIDTH - 260, //width
                 SCREEN_HEIGHT - 1, //height
                 camera, zoomValue, false, true);

   // upper right corner
   renderCamera(1, //left
                 1, //bottom
                 1/3 * SCREEN_WIDTH - 260/3 - 1, //width
                 0.25 * SCREEN_HEIGHT - 1, //height
                 topCamera, zoomValue, true, true);

   // lower left corner
   renderCamera(1/3 * SCREEN_WIDTH - 260/3 + 1, //left
                 1, 1/3 * SCREEN_WIDTH - 260/3 - 1, //width
                 0.25 * SCREEN_HEIGHT - 1, //height
                 sideCamera, zoomValue, true, true);

   // lower right corner    
   renderCamera(2/3 * SCREEN_WIDTH - 2*260/3 + 1, //left
                 1, 1/3 * SCREEN_WIDTH - 260/3 - 1, //width
                 0.25 * SCREEN_HEIGHT - 1, //height
                 frontCamera, zoomValue, true, true);

}

function renderCamera(left, bottom, width, height, cam, zoomValue,     
    zooming, enableScissor) {
   renderer.setViewport(left,bottom,width,height);
   renderer.setScissor(left,bottom,width,height);
   renderer.enableScissorTest (enableScissor);
   cam.aspect = width/height;
   if (zooming) cam.zoom = zoomValue;
   cam.updateProjectionMatrix();
   renderer.render(scene, cam);  
}
user3410517
  • 295
  • 3
  • 18
  • To start, have a look at [this post](http://stackoverflow.com/a/17567292/1461008) about the orthographic camera constructor parameters. – WestLangley Dec 17 '15 at 17:07
  • @WestLangley, please could you be more specific about the information of the post? How i can modify the code shown above. Thanks – user3410517 Dec 18 '15 at 11:12

0 Answers0