That's Cool..Did this code is support for Away3d? (I mean not lite version)
Thanks Kapom On Mon, Nov 2, 2009 at 8:52 AM, mogg <[email protected]> wrote: > Okay.. forget all the previous... I finally have a clue... > > Rob, thank you for being correct... yet again! > > Here are the corrected methods as Rob already demonstrated.... and > thank you for the "sceneMatrix3D" now that I understand it. > > > public function Local3DtoGlobal3D(localVector3D:Vector3D, > o3D:Object3D):Vector3D > { > var globalVect:Vector3D; > > var matrix:Matrix3D = o3D.sceneMatrix3D.clone(); > globalVect = matrix.transformVector(localVector3D); > > return globalVect; > > } > > public function Global3DtoLocal3D(GlobalVector3D:Vector3D, > o3D:Object3D):Vector3D > { > var localVect:Vector3D; > var matrix:Matrix3D = o3D.sceneMatrix3D.clone(); > matrix.invert(); > > localVect = matrix.transformVector(GlobalVector3D); > > return localVect; > } > > On Nov 1, 4:55 pm, mogg <[email protected]> wrote: > > To test this I'm using an OnMouseDown event on the loaded models > > inside their ObjectContainer3D. > > > > I then place a "local" sphere in the ObjectContainer3D. > > I then place a "global" sphere in the view.scene. > > > > Here is my test code: > > > > // local sphere > > var sphr:Sphere = new Sphere(new ColorMaterial(0xFF00FF,0.5), > > 5,8,6,true); > > // global sphere > > var sphr2:Sphere = new Sphere(new ColorMaterial(0x00FF00,0.5), > > 2,8,6,true); > > > > // convert global mouse3D event to local > > var localVec3D:Vector3D = Global3DtoLocal3D(event.scenePosition,o3d); > > // convert it back again from local to global (test) > > var globalVec3D:Vector3D = Local3DtoGlobal3D(localVec3D,o3d); > > > > objcont.addChild(sphr); // (local point) > > sphr.x = localVec3D.x; > > sphr.y = localVec3D.y; > > sphr.z = localVec3D.z; > > > > _lastSphere = sphr; > > view.scene.addChild(sphr2); // green (global point) > > sphr2.x = globalVec3D.x; > > sphr2.y = globalVec3D.y; > > sphr2.z = globalVec3D.z; > > > > On Nov 1, 4:27 pm, mogg <[email protected]> wrote: > > > > > > > > > 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; > > > > > }- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > -- http://www.kapom.com
