actionscript-3stage3d

Formula to convert Local coordinates to world coordinates


Can someone give me the formula? I have a vector3d which represents the position of a vertex in local coordinates, I have a Matrix3d that represents the rotation and position of the object which this vertex is part of it's geometry, how do I convert the local position of this vertex to the coordinates of the world?


Solution

  • now it's working, I had a problem with keeping the original vertex3d, and I played with the order and this is working, thank you very much, here is the code, I did have to use m2.invert(); here is the code:

    var m3d:Matrix3D = new Matrix3D();      
    obj.Transform.copyToMatrix3D(m3d);
    var m2:Matrix3D = new Matrix3D();
    m2.append(m3d);
    m2.invert();
    m2.prependTranslation(obj.BoundingBox[i].x,obj.BoundingBox[i].y,obj.BoundingBox[i].z);
    obj.BoundingBox[i] = new Vector3D(m2.position.x,m2.position.y,m2.position.z);
    

    in fact as I did it in the first place was also OK:

    var m3d:Matrix3D = new Matrix3D();      
    obj.Transform.copyToMatrix3D(m3d);
    m3d.invert();
    obj.BoundingBox[i] = m3d.transformVector(obj.BoundingBox[i]);
    

    The only thing I was missing was the invert(); and I wish I knew what it is for... Some people told me I have to append (or prepend) the object matrix and then the world matrix, which makes sense, but adding the world matrix only caused me problems, while the invert(); made it good, but why?

    Vesper, you are the one suggested it, thanks but why?

    I know why, someone experienced gave me the answer: the camera shows everything mirrored, when you go left the world seems to be moving right, so you need to invert.