Followers 0

# Matrix to vector?

## 2 posts in this topic

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

##### Share on other sites
Apply the Transformation you constructed to the origin (0,0,0,1)?

This is the same as just taking the last row and dividing the first three components (x,y,z) by the last. Edited by japro
1

##### Share on other sites
Wow, yeah that was crazy easy. I cross-referenced Wikipedia on [url="http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection"]Perspective projection matrices[/url], 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]
0

## Create an account

Register a new account