Free rotation in world space

Software: Away3D 3.x

Fab4ce, Jr. Member
Posted: 27 July 2011 09:09 PM   Total Posts: 44

Hi all,

i ask myself how to rotate an object3D freely, without gimbal lock (wikipedia)

There is written:

Adding a fourth rotational axis can solve the problem of gimbal lock, but it requires the outermost ring to be actively driven so that it stays 90 degrees out of alignment with the innermost axis (the flywheel shaft). ...

You have the free rotation in any 3D Modeling software.
Anyone has an example in Away3D ?

   

Fab4ce, Jr. Member
Posted: 08 August 2011 02:03 PM   Total Posts: 44   [ # 1 ]

Hi all,

it seems quite complicated to solve this. I know that it is a lot easier to rotate the camera around an object without gimbal lock.
But this doesn´t solve my situation because i have a few objects in a row and i want to handle each of them seperatly.

So i found this post 360 Camera rotation which moves the camera. (not good for me)

but i also got this solution (which worked until 3.5) with MatrixAway3D

import away3d.core.base.Object3D;
    
import away3d.core.math.Matrix3D;
    
import away3d.containers.View3D;
    
import away3d.primitives.Cone;
    
import away3d.materials.WireframeMaterial;
     
    
//mouse
    
var mDown:Boolean=false;
    var 
mDownPos:Point=new Point();
     
    
//setup scene
    
var myObject:Object3D = new Cone({name:"Cone1",
                       
segmentsH:5,
                       
segmentsW:20,
                       
height:250,
                       
material:new WireframeMaterial(0xff000000)});
     
     
    
//setup view
    
var view:View3D=new View3D();
    
view.scene.addChild(myObject);
    
view.camera.transform.tz=-2000;
    
view.x=stage.stageWidth/2;
    
view.y=stage.stageHeight/2;
     
     
    
//setup stage
    
this.addChild(view);
    
stage.frameRate=120;
    
stage.addEventListener(MouseEvent.MOUSE_DOWN,mousehandler);
    
stage.addEventListener(MouseEvent.MOUSE_UP,mousehandler);
    
stage.addEventListener(Event.ENTER_FRAMEmainloop);
     
     
    
//watch mouse up/down
    
function mousehandler(event:MouseEvent){
        mDown
=(event.type==MouseEvent.MOUSE_DOWN);
        
mDownPos=getMousePos();
    
}
     
     
    
//get current mouse position
    
function getMousePos():Point{
        
return new Point(this.mouseX,this.mouseY);
    
}
     
     
    
//mainloop
    
function mainloop(event:Event){
        
var mdiff:Point=getMousePos().subtract(mDownPos);
        if(
mDown)rotateMatrix(myObject,-(mdiff.x)/4000,-(mdiff.y)/4000);
        
view.render();
    
}
     
     
    
//dolly rotation
    
function rotateMatrix(object:Object3Dx:Numbery:Number):void{
        
var rot1:Matrix3D=new Matrix3D();   
        var 
rot2:Matrix3D=new Matrix3D();   
        
rot1.rotationMatrix(0,1,0,x);     
        
rot2.rotationMatrix(1,0,0,y);
        
rot1.multiply(rot1rot2);
        
rot1.multiply(rot1,object.transform);
        
object.transform rot1;
    

Noone has an idea how to make it work in Away 3.6 or even in 4.0 ?

   

Felix af Ekenstam, Newbie
Posted: 15 October 2011 11:36 AM   Total Posts: 7   [ # 2 ]

Hi,
I have been researching this for a looong time, trying to understand quaternions, now I just came up with the most simple solution to avoid gimbal lock:

var m:Matrix3D=myObject.transform
m.appendRotation(rotX, new Vector3D(0,0,1))
m.appendRotation(rotY, new Vector3D(1,0,0))
myObject.transform=m

By manipulating the matrix instead of changing the rotationX solves it..

It does behave strange if the object is not at position (0,0,0) though. My solution to that was just to put it inside a containing object and move that one instead. There is probably a better solution to that, like changing the pivot point or something.

I work in away3d 4, Broomstick.

   

Fab4ce, Jr. Member
Posted: 16 October 2011 05:57 PM   Total Posts: 44   [ # 3 ]

Hi,

thanks a lot for your answer. I was also waiting and searching for the answer for a long time. And suddenly about 1 week ago i got the same answer from someone else. It works good. My recommendation to avoid this strange behavior with the pivot: I save the position of the object, then set it to 0,0,0, followed by the matrix transformation and i end with reposition it to where it was.

Happy Rotating !! smile

   

Fab4ce, Jr. Member
Posted: 24 October 2011 11:04 AM   Total Posts: 44   [ # 4 ]

hey Felix,

did you find any solution to have a smooth easing with that? I can´t get it as smooth as TweenMax does.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X