Reputation: 6702
Has anyone got a bit of code I can use to change the center point DisplayObjects rotate around in a 3D space? I need it to work with rotationX, rotationY and rotationZ. I know theres a workaround of wrapping every object in aother sprite and offsetting the x & y positions but I'd much prefer a math solution.
As an example of the problem, this code should make a star shape:
var a=new Sprite()
addChild(a)
a.graphics.lineStyle(0,0xFF0000)
a.graphics.moveTo(10,10)
a.graphics.drawRect(100,100,100,100)
var b=new Sprite()
addChild(b)
b.graphics.lineStyle(0,0)
b.graphics.moveTo(10,10)
b.graphics.drawRect(100,100,100,100)
b.rotationZ=45
...
UPDATE: Thanks to Alex for the tip, I've posted a reusable solution here :)
Upvotes: 2
Views: 4691
Reputation: 4934
You need to be using a Matrix3D object, and applying that to a DisplayObject instances transform property. You need to define the DisplayObject's z property first before you can apply the 4x4 3DMatrix transformations.
So something like:
myObject.z = 1;
myObject.transform.matrix3D.appendTranslation(10,10,0);
myObject.transform.matrix3D.appendRotation(1, Vector3D.Y_AXIS);
myObject.transform.matrix3D.appendTranslation(-10,-10,0);
From: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix3D.html
Hope it helps :)
Upvotes: 3