Ronan Dejhero Ronan Dejhero - 3 months ago 8x
Android Question

GLES20 How to get global position of vertex after translating and rotating it

I have a vertex (Which i will not be showing/rendering in the scene)

float vertex[] = {
1.0f, 1.0f, 1.0f,

And i have a mesh, which i have translated and rotated using:

Matrix.translateM(World.mModelMatrix, tmOffset, globalPositionX, globalPositionY, globalPositionZ);

Matrix.rotateM(World.mModelMatrix, rmOffset, globalRotationZ, 0, 0, 1);
Matrix.rotateM(World.mModelMatrix, rmOffset, globalRotationY, 0, 1, 0);
Matrix.rotateM(World.mModelMatrix, rmOffset, globalRotationX, 1, 0, 0);

How can apply those translations and rotations to the vertex, and get its global position (x,y,z) after?


Use the Matrix.multiplyMV method:

float vertex[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float result[] = { 0.0f, 0.0f, 0.0f, 0.0f };

Matrix.multiplyMV(result, 0, matrix, 0, vertex, 0);

Note, that you will have to add a homogeneous coordinate to your vector to make it work.