I wanted to share my Global3D to Local3D and
Local3D to Global3D methods I have working for Away3Dlite.
These are working perfectly for my object tree.
I'm using Away3Dlite trunk:Away3D/trunk/fp10/Away3DLite/src
These two methods do assume the following object tree.
View.scene
-ObjectContainer3D (non-mesh container for rotation help)
--Object3D (my loaded model inside the above ObjectContainer3D).
Every model I load I first add an ObjectContainer3D to the view.scene
and then I add my loaded model into this new ObjectContainer3D.
The purpose of the nested objects is to provide
"pitch","roll"...etc...
Here are the methods. (please note that I had to swap the rotationZ
and rotationY AXIS in the Global3DtoLocal3D method. Not sure why but
it is the only way I was able to get this to work (a bug maybe? or I'm
just way off track and it works anyway). These work well no matter how
I seem to rotate the Outer container or the inner model itself.
public function Local3DtoGlobal3D(localVector3D:Vector3D,
o3D:Object3D):Vector3D
{
var globalVect:Vector3D;
var parent:Object3D = o3D.parent as Object3D;
var matrix:Matrix3D = parent.transform.matrix3D.clone();
globalVect = matrix.transformVector(localVector3D);
return globalVect;
}
public function Global3DtoLocal3D(GlobalVector3D:Vector3D,
o3D:Object3D):Vector3D
{
var localVect:Vector3D;
var parent:Object3D = o3D.parent as Object3D;
var matrix:Matrix3D = o3D.transform.matrix3D.clone();
matrix.appendRotation(-o3D.rotationX,Vector3D.X_AXIS);
matrix.appendRotation(-o3D.rotationZ,Vector3D.Y_AXIS);
matrix.appendRotation(-o3D.rotationY,Vector3D.Z_AXIS);
var matrix2:Matrix3D = parent.transform.matrix3D.clone();
matrix.append(matrix2);
matrix.invert();
localVect = matrix.transformVector(GlobalVector3D);
return localVect;
}