Distance/zoom on HoverController

Software: Away3D 4.x

DinkMcDinkleman, Newbie
Posted: 14 March 2012 06:26 PM   Total Posts: 30

So after some searching here and amongst the interwebs, I’m unable to understand how the HoverController works.

It’s great for my needs, but when tilting the distance from camera to object seems to increase when above or below the object and decrease when viewing from the front.

I hope that makes sense.  I am uncertain which property is actually changing - but I’d like to make it so the distance stays the same.  Is there a built-in way to do that?

Thank you

   

DinkMcDinkleman, Newbie
Posted: 16 March 2012 04:17 AM   Total Posts: 30   [ # 1 ]

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(100100100111false);
  
  
//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(cameranull180203205);
   
   
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 ColorMaterial0xFF0000 );
   
cubeMaterial.lightPicker lightPicker;
  
}
  
  
private function initObjects():void
  {
   mesh 
= new Mesh(cubecubeMaterial);
   
scene.addChild(mesh);
  
}
  
  
private function initListeners():void
  {
   addEventListener
(Event.ENTER_FRAMEonEnterFrame);
   
view.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
view.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
stage.addEventListener(Event.RESIZEonResize);
   
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_LEAVEonStageMouseLeave);
  
}
  
  
private function onMouseUp(event:MouseEvent):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
private function onStageMouseLeave(event:Event):void
  {
   move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
private function onResize(event:Event null):void
  {
   view
.width stage.stageWidth;
   
view.height stage.stageHeight;
  
}
  
 }
 

 

   

DinkMcDinkleman, Newbie
Posted: 16 March 2012 04:43 AM   Total Posts: 30   [ # 2 ]

Adding the bottom line, changing the yFactor, seems to have done the trick, although I can’t explain why or how that might affect other objects.

Is there anyone that knows what I am trying to say and can provide an explanation to a n00b like me?

//setup controller to be used on the camera
 
cameraController = new HoverController(cameranull180203205);
   
 
//setting the y factor to 1 keeps objects from appearing distorted
 
cameraController.yFactor 1

Thanks!

Also - thank you to the Away3D team for providing something so awesome!

 

   

C., Newbie
Posted: 29 March 2012 09:42 AM   Total Posts: 9   [ # 3 ]

Hey,

I have no explanation to this as well but I felt like saying thank you for providing your workaround with the yFactor. Worked fine for me with no noticeable sideeffects so far.

Thanks! smile

 

   

Ontheronix, Jr. Member
Posted: 16 October 2012 12:53 PM   Total Posts: 37   [ # 4 ]

Works for me too, thanks!

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X