Quick Note on Local to Global in Papervision3D
Normally, if you want to get the scene coordinates of a child 3D object, use these properties:
However, if you want to get the screen coordinates of a local point other than the object’s original position (for e.g. side of a plane, some random points on a surface of a sphere…), then you have to deal with Matrix3D transform.
Don’t worry, you don’t need to understand what Matrix3D is because I don’t either :). Let’s use what people have concluded here:
If local to global is:
then global to local is:
There are 2 things to note with above conclusion:
- I have to invert method’s arguments (from what’s originally stated in the post) to get the correct conversion. I’m using PV3D 2.1
I haven’t tried the global to local method, hence I don’t guarantee it works.The global to local transform works correctly.
So here’s how I convert any local positions to global:
- var matrix: Matrix3D = Matrix3D.IDENTITY; //a recommended way to create new Matrix3D
- matrix.n14 = localX;
- matrix.n24 = localY;
- matrix.n34 = localZ;
- matrix.calculateMultiply(child.parent.world, matrix); //child must be a DisplayObject3D
- var scenePos: Number3D = new Number3D(matrix.n14, matrix.n24, matrix.n34);
If you want to convert the rotation as well, use Matrix3D.copy() to copy all transformation info from the child object. And then after calculateMultiply(), apply the matrix to your scene object with DisplayObject3D.copyTransform().
[Vietnamese Tag – Chuyển đổi tọa độ local sang global trong Papervision3D]