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