After playing around a bit, I’ve discovered that the effect seems to be caused by using a perspective lens on the camera. However, an ortho lense causes a different type of distortion. I’m hoping for a happy medium. I’m attaching screenshots of a cube from (nearly) side view and the top, as well as my code in order to hopefully clarify what I mean.
package
{
import away3d.cameras.lenses.FreeMatrixLens;
import away3d.cameras.lenses.LensBase;
import away3d.cameras.lenses.OrthographicOffCenterLens;
import away3d.cameras.lenses.PerspectiveLens;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Vector3D;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import away3d.cameras.Camera3D;
import away3d.controllers.HoverController;
import away3d.cameras.lenses.OrthographicLens;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.lights.PointLight;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
import away3d.entities.Mesh;
public class Main extends Sprite
{
//engine variables
private var scene:Scene3D;
private var camera:Camera3D;
private var view:View3D;
private var cameraController:HoverController;
//light objects
private var pointLight:PointLight;
private var lightPicker:StaticLightPicker;
//mesh
private var mesh:Mesh;
private var cube:CubeGeometry = new CubeGeometry(100, 100, 100, 1, 1, 1, false);
//material
private var cubeMaterial:ColorMaterial;
//navigation variables
private var move:Boolean = false;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var tiltSpeed:Number = 2;
private var panSpeed:Number = 2;
private var distanceSpeed:Number = 2;
private var tiltIncrement:Number = 0;
private var panIncrement:Number = 0;
private var distanceIncrement:Number = 0;
public function Main():void
{
init();
}
private function init():void
{
initEngine();
initLights();
initMaterials();
initObjects();
initListeners();
}
private function initEngine():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
view = new View3D();
view.forceMouseMove = true;
scene = view.scene;
camera = view.camera;
//setup controller to be used on the camera
cameraController = new HoverController(camera, null, 180, 20, 320, 5);
addChild(view);
}
private function initLights():void
{
//create a light for the camera
pointLight = new PointLight();
scene.addChild(pointLight);
lightPicker = new StaticLightPicker([pointLight]);
}
private function initMaterials():void
{
// locator materials
cubeMaterial = new ColorMaterial( 0xFF0000 );
cubeMaterial.lightPicker = lightPicker;
}
private function initObjects():void
{
mesh = new Mesh(cube, cubeMaterial);
scene.addChild(mesh);
}
private function initListeners():void
{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
view.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
view.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
private function onEnterFrame(event:Event):void
{
if (move) {
cameraController.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;
cameraController.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
pointLight.position = camera.position;
view.render();
}
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = cameraController.panAngle;
lastTiltAngle = cameraController.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = true;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onMouseUp(event:MouseEvent):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onStageMouseLeave(event:Event):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onResize(event:Event = null):void
{
view.width = stage.stageWidth;
view.height = stage.stageHeight;
}
}
}