Heya! I've got a tree of objects, each with their own transformation matrices relative to their parent object. Give an object anywhere in the tree, I'd like to find it's absolute position from the origin. This is simple enough: I walk down the tree, applying each transform along the way, 'till I hit the object in question. The resultant matrix gives the absolute transformation matrix.

What's the best way to turn this in to a vector that is the position relative to the origin? I have bounding boxes around each element, and I'd like to use this to find collisions.

I may be making this more complicated than I need to...

**0**

2 replies to this topic

Sponsor:

###
#3
Members - Reputation: **102**

Posted 22 June 2012 - 09:21 PM

Wow, yeah that was crazy easy. I cross-referenced Wikipedia on Perspective projection matrices, your simple suggestion + Wikipedia made it obvious. Here's what I ended up with:

[source lang="java"] public static Matrix4f fromVector(Vector3f vector) { Matrix4f matrix = new Matrix4f(); matrix.m30 = vector.x; matrix.m31 = vector.y; matrix.m32 = vector.z; matrix.m33 = 1; return matrix; } public static Vector3f toVector(Matrix4f matrix, Vector3f vector) { vector.x = matrix.m30; vector.y = matrix.m31; vector.z = matrix.m32; return vector; } public static void mul(Matrix4f left, Vector3f right, Vector3f result) { Matrix4f matrix = fromVector(right); Matrix4f.mul(left, matrix, matrix); toVector(matrix, result); }[/source]

[source lang="java"] public static Matrix4f fromVector(Vector3f vector) { Matrix4f matrix = new Matrix4f(); matrix.m30 = vector.x; matrix.m31 = vector.y; matrix.m32 = vector.z; matrix.m33 = 1; return matrix; } public static Vector3f toVector(Matrix4f matrix, Vector3f vector) { vector.x = matrix.m30; vector.y = matrix.m31; vector.z = matrix.m32; return vector; } public static void mul(Matrix4f left, Vector3f right, Vector3f result) { Matrix4f matrix = fromVector(right); Matrix4f.mul(left, matrix, matrix); toVector(matrix, result); }[/source]