Sign in to follow this  
Nubsy

Ortho camera

Recommended Posts

Hello all!

 

I'm trying, for fun, to recreate the 2D/3D environment from the game Fez. My roommate was playing it, and I thought it was awesome.

 

My problem is that I don't quite understand what's going on with the ortho camera.

 

So I've created a free camera, and set the mode to BABYLON.Camera.ORTHOGRAPHIC_CAMERA:

camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 0, 0), scene);camera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;

And the camera view is flat on, like it should be. Except the cubes (drawn from/at the origin) I've made are really far away. The camera doesn't need to zoom at all, but it does need to be closer. 

 

I'm finding that there's not a whole lot of information about the ortho mode, other than there is an ortho mode. I guess I'm just looking for some basic info or examples using the orthographic mode.

 

Thanks! 

Share this post


Link to post
Share on other sites

Hi there !

 

For an orthographic camera, you need to specify these values :

camera.orthoTop;camera.orthoBottom;camera.orthoLeft;camera.orthoRight;

Here is an example : http://www.babylonjs.com/playground/#JLPAE

 

These values are the coordinates of a square representing the space displayed in your camera. If you want to zoom in, just reduce these values.

 

Cheers, 

Share this post


Link to post
Share on other sites
9 hours ago, guzuomuse said:

@Temechon,can u tell me how to specify these values? i really need these. thank you!!!

If you have a sphere with a diameter of 10 units, you have to use an ortho value of 5 to make it exactly fit to the view.

camera.orthoTop = 5; //5 units to the top
camera.orthoBottom = -5; //5 units to the bottom
camera.orthoLeft = -5;  //5 units to the left
camera.orthoRight = 5; //5 units to the right

Share this post


Link to post
Share on other sites
On 5/5/2018 at 1:14 AM, Kesshi said:

If you have a sphere with a diameter of 10 units, you have to use an ortho value of 5 to make it exactly fit to the view.

camera.orthoTop = 5; //5 units to the top
camera.orthoBottom = -5; //5 units to the bottom
camera.orthoLeft = -5;  //5 units to the left
camera.orthoRight = 5; //5 units to the right

I went ahead and did this anyway as in my 4:3 aspect-ratio game, attempting to remake Mario in BabylonJS, but is it correct that I should scale my horizontal & vertical properties based on the same aspect ratio? like instead of 8:8, I use 8:6 like this?  

   
    var orthographicScaleX = 8;
    var orthographicScaleY = 6;
    this.camera.orthoTop = orthographicScaleY;
    this.camera.orthoBottom = -orthographicScaleY;
    this.camera.orthoLeft = -orthographicScaleX;
    this.camera.orthoRight = orthographicScaleX;
 
Edited by Kerihobo
code sample was making my question unclear.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.