0

Please could someone confirm that the following "supposed constraint" is correct?...

In order to render a three.js orthographic camera to a viewport (and to avoid distortion) the camera's frustum left,right,bottom and top planes must define a frontal frustum face (ocWidth, ocHeight) whose aspect ratio (width/height) is the same as the aspect ratio of the viewport?

In the following example the camera width and height are set first and then the viewport height is constrained by the desired viewport width and the given camera aspect ratio. (An alternative approach would be to set the viewport width and height first and then constrain the camera height to the desired camera width and the given viewport aspect ratio.)

//Orthographic Camera

ocWidth  = 99000; //... World Units
ocHeight = 33000; //... World Units

var myCamera = new THREE.OrthographicCamera( 
   ocWidth  / - 2, ocWidth  / 2, 
   ocHeight / 2, ocHeight / - 2,
   NEAR = 1, FAR = 1000 );
 
oc_aspect_ratio = ocWidth / ocHeight; 

//Viewport

vp_aspect_ratio = oc_aspect_ratio; 
vpXwidth = 800; //... pixels
vpYheight =  vpXwidth /vp_aspect_ratio;  //... pixels, to ensure no distortion

vpXmin = -vpXwidth  /2; vpXmax = vpXwidth  /2; //... pixels
vpYmin = -vpYheight /2; vpYmax = vpYheight /2; //... pixels
        
myRenderer.setViewport( vpXmin, vpYmin, vpXwidth, vpYheight );  

Thus (in general) the width and height of the RENDERER are irrelevant as far as the orthographic camera is concerned (The exception is when the effective viewport fills the entire renderer, which is the default if no viewport is explicitly defined. In this case the renderer aspect ratio must match the camera aspect ratio).

I have studied

Community
  • 1
  • 1
steveOw
  • 879
  • 12
  • 41
  • First, see http://stackoverflow.com/questions/17558085/three-js-orthographic-camera/17567292#17567292 and make sure you understand what the orthographic camera parameters represent. World units are not pixels, unless you are rendering to a texture. – WestLangley Mar 14 '15 at 22:12
  • @WestLangley. Yes I saw that Q&A. I am clear about difference between world units and pixels. Your answer states:<<>>. But no info about *Viewports* (which can have different aspect ratio to renderer). – steveOw Mar 15 '15 at 22:54
  • In your use case, are the units of `X_Width` pixels? If so, why are you passing pixels to your camera constructor? Are you rendering a scene, or a full-screen quad? What are the world units of your scene? – WestLangley Mar 16 '15 at 01:36
  • @WestLangley. Ah I see my code example was ambiguous. I have re-written text and code example to clarify. I am rendering a small viewport within a larger full screen which will display other viewports of various rectangular shapes and sizes (reporting different scenes/cameras). All viewports use the same renderer. Scene/World units are metres, kilometres, furlongs whatever, (not pixels!) – steveOw Mar 16 '15 at 11:17

1 Answers1

2

If you are rendering your scene with an orthographic camera, and you wish to prevent distortion of the rendered scene, you need to set your viewport aspect ratio to match the aspect ratio of the camera's frustum.

WestLangley
  • 102,557
  • 10
  • 276
  • 276