Set camera back to original position

Software: Away3D 3.x

TParis, Newbie
Posted: 17 January 2012 05:22 PM   Total Posts: 5

Hi Folks,

I’m a programmer for the USAF and my background is in PHP and ASP development.  I’ve recently been assigned to a new unit that does flash development so I have about a year’s experience learning ActionScript 3.

Here’s my problem:

I’m writing a 3D surgical instruments application that had a 3D model of a tool.  User can pan, tilt, zoom in, zoom out, move left, move right.  However, I want to have descriptions of the image to the left of the 3d clipped window.  When the user clicks on a description, for example “pointed tounge”, I was the 3d object to rotate and zoom in on that specific part.

The only way I can conceive to do this is to bring the camera to a specific point and calculate the rotation based on that.  However, when I use the pan and tilt, I cannot figure out how to get my camera back to where it started.  Here is my code:

package
{
    import away3d
.cameras.*;
    
import away3d.containers.Scene3D;
    
import away3d.containers.View3D;
    
import away3d.core.base.Object3D;
    
import away3d.core.math.Number3D;
    
import away3d.core.render.Renderer;
    
import away3d.events.Loader3DEvent;
 
import away3d.lights.PointLight3D;
 
import flash.events.MouseEvent;
    
import away3d.loaders.Loader3D;
    
import away3d.loaders.Obj;
    
import away3d.loaders.Max3DS;
    
import flash.display.Sprite;
    
import flash.events.Event;
 
import caurina.transitions.*
 
import caurina.transitions.properties.*
 
import away3d.lights.PointLight3D;
 
    public class 
Globe extends Sprite
    {
 
        
protected var _scene:Scene3D;
        protected var 
_view:View3D;
        protected var 
_camera:Camera3D;
        protected var 
_loader:Loader3D;
        protected var 
_loaderTank:Loader3D;
        protected var 
_mesh:Object3D;
  protected var 
_light:PointLight3D;
  
  
// variables
  
var move:Boolean false;
  var 
lastPanAngle:Number;
  var 
lastTiltAngle:Number;
  var 
lastMouseX:Number;
  var 
lastMouseY:Number;
 
        public function 
Globe()
        
{
            initAway
();
        
}
 
        
private function initAway():void
        {
   _camera 
= new Camera3D({ zoom:2focus:200});
   
_camera.pan(-26);
   
_camera.tilt(20);
   
//_camera.hover();
   
lastPanAngle = -26;
   
lastTiltAngle 20;
   
   
            
_scene = new Scene3D();
   
 
            
_view = new View3D{ x:230y:300scene:_scenecamera:_camerarenderer:Renderer.CORRECT_Z_ORDER } );
            
addChild_view );
   
_view.clipping.maxX 200;
   
_view.clipping.maxY 80;
   
_view.clipping.minX = -200;
   
_view.clipping.minY = -270;
 
            
_loader Max3DS.load"ST_1.3DS"{   bothsides:true } );
            
_loader.addOnSuccessonObjLoad );
   
   
_light = new PointLight3D{ x:300y:100z:100,brightness:250ambient:.5diffuse:.5specular:1 } );
   
//_scene.addLight(_light);
   
_scene.addChild(_light);
            
//_loaderTank = Obj.load( "Instrument_ENT.obj", { scaling:.5, bothsides:true } );
            //_loaderTank.addOnSuccess( onObjLoad );
        
}
 
        
private function onObjLoade:Loader3DEvent ):void
        {
            _mesh 
e.loader.handle;
            
_mesh.scaleX 10;
            
_mesh.scaleY 10;
            
_mesh.scaleZ 10;
   
_mesh.rotationX=90;
   
_mesh.rotationY=-90;
   
   
//_mesh.rotationX = 90;
 
            
_scene.addChild_mesh );
 
 
    
//Event Listeners
            
addEventListenerEvent.ENTER_FRAMEonRender );
   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.addEventListener(MouseEvent.MOUSE_DOWNMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPMouseUp);
   
   
btnLeft.addEventListener(MouseEvent.MOUSE_DOWNstartLeftTurn);
   
btnRight.addEventListener(MouseEvent.MOUSE_DOWNstartRightTurn);
   
btnUp.addEventListener(MouseEvent.MOUSE_DOWNstartUpTurn);
   
btnDown.addEventListener(MouseEvent.MOUSE_DOWNstartDownTurn);
   
btnZoomIn.addEventListener(MouseEvent.MOUSE_DOWNstartZoomIn);
   
btnZoomOut.addEventListener(MouseEvent.MOUSE_DOWNstartZoomOut);
   
btnCenter.addEventListener(MouseEvent.MOUSE_DOWNCenterCamera);
   
   
//Tweener.addTween(_mesh,{rotationY:100,time:100});
        
}
 
        
private function onRendere:Event ):void
        {
            
//_mesh.rotationY += 5;
 
            
_view.render();
        
}
  
  
//Left Turn
  
private function startLeftTurn(e:MouseEvent):void
  {
   btnLeft
.removeEventListener(MouseEvent.MOUSE_DOWNstartLeftTurn);
   
btnLeft.addEventListener(MouseEvent.MOUSE_UPstopLeftTurn);
   
btnLeft.addEventListener(Event.ENTER_FRAMEturnLeft);
   
  
}
  
  
private function stopLeftTurn(e:MouseEvent):void
  {
   btnLeft
.addEventListener(MouseEvent.MOUSE_DOWNstartLeftTurn);
   
btnLeft.removeEventListener(MouseEvent.MOUSE_UPstopLeftTurn);
   
btnLeft.removeEventListener(Event.ENTER_FRAMEturnLeft);
  
}
  
  
private function turnLeft(e:Event):void
  {
   _camera
.pan(-2);
   
lastPanAngle -= 2;
  
}
  
  
function MouseDown(event:MouseEvent):void
  {
   lastMouseX 
stage.mouseX;
   
lastMouseY stage.mouseY;
   
move true;
  
}
  
  
function MouseUp(event:MouseEvent):void
  {
   move 
false;
  
}
  
  
function onEnterFrame(e:Event):void
  {
   
// rerender viewport
   
var cameraSpeed:Number 0.3// Approximately same speed as mouse movement.
   
if (move{
    _camera
.pan(cameraSpeed*(stage.mouseX lastMouseX));
    
lastPanAngle += cameraSpeed*(stage.mouseX lastMouseX);
    
_camera.tilt(cameraSpeed*(stage.mouseY lastMouseY));
    
lastTiltAngle += cameraSpeed*(stage.mouseY lastMouseY);
   
}
   
//_camera.hover();
   
_view.render();
   
   
//trace(lastPanAngle + "," + lastTiltAngle);
      
  
}
  
  
public function CenterCamera(e:Event{
   _camera
.0;
   
_camera.0;
   
_camera.0;
   
_camera.lookAt(new Number3D(0,0,0));
   
_camera.pan(-26);
   
_camera.tilt(20);
   
_camera.zoom 2;
   
_camera.position.normalize(1);
  
}

 
    }
 
   

TParis, Newbie
Posted: 17 January 2012 05:24 PM   Total Posts: 5   [ # 1 ]

I cut out a lot of the repetitive code, but you can imagine that many of the buttons are similar to btnLeft and turnLeft objects/functions.  Need help!

   

TParis, Newbie
Posted: 18 January 2012 04:59 PM   Total Posts: 5   [ # 2 ]

I figured it out…


_camera.rotateTo(0,0,0);

   

Avatar
Matse, Sr. Member
Posted: 18 January 2012 06:07 PM   Total Posts: 149   [ # 3 ]

An easy way to control camera rotation is to use one container per axis and a camera class, not much time right now but something like :

_controllerX = new ObjectContainer3D();
 
_controllerY = new ObjectContainer3D();
        
_controllerZ = new ObjectContainer3D();
 
_controllerX.addChild(_controllerY);
 
_controllerY.addChild(_controllerZ);
        
_controllerZ.addChild(_camera

rotate controllerX on X axis etc : no need for maths with this setup smile

   

TParis, Newbie
Posted: 18 January 2012 07:02 PM   Total Posts: 5   [ # 4 ]

That’s well beyond what I know.  I’ve have all of 20 hours experience on any sort of 3d engine (no prior training).

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X