Rotating objects with touch gestures

Software: Away3D 4.x

TerryMcG, Newbie
Posted: 09 January 2013 03:33 AM   Total Posts: 7

I’m placing objects in a scene that I want to rotate and spin along its y-axis with touch interactions. BTW, I’m aware of the hover camera controller that’s frequently used in the Away 4.1 examples. It’s a great feature but my intention is to have a stationary camera with 3d objects a user can spin and rotate.

I’m not too knowledgeable with 3D so I tried using a 2D solution but it doesn’t work very perfectly. The result is very jerky and unnatural. Any advice? I tried combing around for an example or answer for this but I couldn’t find anything. Thanks in advance.

private var _dragging:Boolean false;
  private var 
_oldRot:Number 0;
  private var 
_rot:Number 0;
  private var 
_acc:Number 0;
  private var 
_damp:Number .95;
  private var 
_ez:Number;
  private var 
_ex:Number;
  
  private function 
onMeshMouseMoveevent:MouseEvent3D ):void {
   
if(_dragging{
    _ex 
event.scenePosition.x;
    
_ez event.scenePosition.z;
   
}
  }
  
  
private function onMeshMouseDownevent:MouseEvent3D ):void {
   _dragging 
true;
   var 
dz:Number event.scenePosition._objectContainer.z;
   var 
dx:Number event.scenePosition._objectContainer.x;
   
_oldRot Math.atan2(-dz,dx)*180/Math.PI;
  
}
  
  
private function onMeshMouseUpevent:MouseEvent3D ):void {
   _dragging 
false;
  
}
  
  
private function onMeshMouseOutevent:MouseEvent3D ):void 
  {
   _dragging 
false;
  
}
  
  
private function onStageMouseUpevent:MouseEvent ):void 
  {
   _dragging 
false;
  
}

  
  
protected function onUpdate():void {
   
if(_objectContainer)
   
{
    
if(_dragging)
    
{
     
var dz:Number _ez _objectContainer.z;
     var 
dx:Number _ex _objectContainer.x;
     
_rot Math.atan2(-dz,dx)*180/Math.PI;
     
     
_acc = ((_rot-_oldRot)+_acc)/2;
     
_objectContainer.rotationY+= _acc;
     
_oldRot _rot;
    
}
    
else {
     _objectContainer
.rotationY+=_acc;
     
_acc*=_damp;
    
}
   }
  } 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X