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 onMeshMouseMove( event:MouseEvent3D ):void {
if(_dragging) {
_ex = event.scenePosition.x;
_ez = event.scenePosition.z;
}
}
private function onMeshMouseDown( event:MouseEvent3D ):void {
_dragging = true;
var dz:Number = event.scenePosition.z - _objectContainer.z;
var dx:Number = event.scenePosition.x - _objectContainer.x;
_oldRot = Math.atan2(-dz,dx)*180/Math.PI;
}
private function onMeshMouseUp( event:MouseEvent3D ):void {
_dragging = false;
}
private function onMeshMouseOut( event:MouseEvent3D ):void
{
_dragging = false;
}
private function onStageMouseUp( event: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;
}
}
}