Help: Can’t get OrthographicLens to zoom properly at all

Software: Away3D 4.x

BobWarfield, Newbie
Posted: 23 January 2013 11:39 PM   Total Posts: 19

I’ve got an app that allows multiple views of the same scene, though not simultaneously.  It allows me to switch between Perspective and Orthographic lenses.  My problem is the Ortho lens is just behaving bizarrely.

The scene I am rendering contains a grid, similar to what CAD/CAM programs have.  Here is the grid rendered via PerspectiveLens:

http://www.cnccookbook.com/img/GWizard/bozon/PerspGrid.jpg

Pretty simple.  Now here is the initial view with an Ortho lens:

http://www.cnccookbook.com/img/GWizard/bozon/OrthoNoZoom.jpg

Something to note is that if we zoom the perspective image to a similar scale, the Segments comprising the grid are not nearly so thick.  Zooming is accomplished by moving the camera closer using “moveForward”.

Now here is where it gets really wonky.  Zoom is hooked up to the mouse wheel.  Works great in Perspective.  If we zoom in on that grid with the Ortho lens we get this:

http://www.cnccookbook.com/img/GWizard/bozon/OrthoZoomed.jpg

The wires get fatter but the squares stay exactly the same size. 

What the heck gives?  Why doesn’t it zoom?  Why are the squares not getting larger instead of the wires?

Here is the code I use to change the lenses, it’s pretty simple:

public function setProjection( p:String ):void
  {
  if (thisProjection != p) {
 
  if (p == PARALLEL_PROJ && USE_ORTHO_LENS) {
   
    // Note: We make the big leap of faith that a perspective lens was properly initialized before we got here!

    // Wondering what the best value for PROJECTION_HEIGHT is.
    // 23 gives same _ymax as Perspective lens.  Without it, we pick a much different value by default.  But 23 is way too zoomed in.
    // Very large values seem to help, but there’s still weirdness in using them. 10,000 is close. Tutorials use view.height, and that is also
    // not helpful—makes the minor grid lines disappear for some reason.
    var PROJECTION_HEIGHT:Number = 10000; // view.height;
    view.camera.lens = new OrthographicLens(PROJECTION_HEIGHT);
    view.camera.lens.far = cameraViewDistance;
   
    log.debug(“OrthographicLens”);
  } else {
   
    view.camera.lens = new PerspectiveLens();
    (view.camera.lens as PerspectiveLens).fieldOfView = INIT_ZOOM;
    view.camera.lens.far = cameraViewDistance;
   
    log.debug(“PerspectiveLens”);
  }
 
  // assert: Caller take care of these afterward:
  // view.camera.moveTo(camX, camY, camZ);
  // view.camera.lookAt( new Vector3D(camLookX, camLookY, camLookZ), camUpAxis );
  }
 
  thisProjection = p; 
  }

I have experimented with other values for the projectionHeight argument to set up the lens and it’s only effect seems to be that at some point with smaller values such as view.height, we lose the minor grid squares and just see the axes.

I’m using Away3D 4.x, the latest shipping version of 4.0, circa June/July 2012, not 4.1 alpha.

Sure could use help to make this work, thanks in advance!

Best,

BW

   

laurent, Newbie
Posted: 24 January 2013 12:22 PM   Total Posts: 29   [ # 1 ]

Hi,

Which code you use to make the zoom in ortho mode?

In orthographic projection, making the camera go closer to an object doesn’t make it zoom.

The projection is independent of the distance from the object to the camera.

   

BobWarfield, Newbie
Posted: 24 January 2013 02:14 PM   Total Posts: 19   [ # 2 ]

Really?

If the projection is independent of the distance, how do we zoom?

   

laurent, Newbie
Posted: 24 January 2013 02:34 PM   Total Posts: 29   [ # 3 ]

Yes really, that’s the principle of orthographic projection which keeps parallel lines.


If you look at this image: http://chestofbooks.com/crafts/machinery/Shop-Practice-V2/images/Body-and-Its-Projection.png

Then imagine you move the paper away from the object, then your projection will be the same. The paper=your camera so you move it along the same axis, nothing will happen.

You need to reduce the field of view / view volume to give a feeling of zooming in… Not sure which parameter to use in away3D as I have only done it in OpenGL.

Try it then let us know!

 

 

 

   

BobWarfield, Newbie
Posted: 24 January 2013 02:44 PM   Total Posts: 19   [ # 4 ]

“scale” will do it, but that’s painful.  The whole point here is to be able to view the same scene through either perspective or orthographic projection, and to have that view zoom, pan, and rotate. 

Given one lens that requires the camera to move and one that uses the “scale” property, it’s really inelegant since you have to implement it two different ways now depending on the lens.

I’ll investigate how well using scale with Perspective works and see whether I can switch both to use scale.  Will let you know.

Cheers,

BW

   

laurent, Newbie
Posted: 24 January 2013 02:48 PM   Total Posts: 29   [ # 5 ]

I don’t think using scale is the proper way to do it: you should modify only the camera.

Have you tried to modify the corner points of the lens frustum? If you get them closer, then you will zoom.

I think that’s the clean way of doing it…

   

BobWarfield, Newbie
Posted: 24 January 2013 03:26 PM   Total Posts: 19   [ # 6 ]

I can vary projectionHeight on the Ortho lens and achieve the same effect as camera.scale.  Changing it results in changes to the frustum points.

What is the advantage you’re perceiving for modifying the frustum points instead of camera.scale?

Either way means zooming is radically different for Ortho vs Perspective. 

Two things I wish Away3D did a lot better:

1.  Make these two lenses interchangeable.  All these flaming hoops to make them act the same are artifacts of the underlying implementation and not any desired end result at the API level.  In this respect, doing away with the old “zoom” property of Away3D 3.x was not desirable as it could’ve been used as a decent abstraction to help establish this equivalence.  Another alternative would be to rewrite the Ortho lens so zoom by camera distance works.  I have no idea how to do that but the idea of a parallel projection that zooms is certainly common out in the graphics world.

2.  Provide a “Zoom Extents” entry.  A lot of my kvetching about this is because I’ve had to implement Zoom Extents which will auto-scale so the desired objects I designate fill the window.  It’s a really common function and I can’t believe I’m the first to have to build it for Away3D, but it is a pain to get right.  Lack of #1 means there will have to be two implementations of Zoom Extents.

Really, the framework should do both, but if it did either one (and did it well for either lens!), my work would be radically simplified.

Cheers,

BW

   

laurent, Newbie
Posted: 24 January 2013 04:18 PM   Total Posts: 29   [ # 7 ]
BobWarfield - 24 January 2013 03:26 PM

What is the advantage you’re perceiving for modifying the frustum points instead of camera.scale?

 

Sorry, I thought you were talking about scaling 3D objects themselves.

Only drawback I can see in using scale is that your near & far plane values will be changed so you may have a lot of clipping when you zoom too much.

I am not sure away3d handle camera scale that way but if you start encountering
clipping issues, that’s where you need to look at…

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X