GLES20如何在平移和旋转后获取顶点的全局位置
GLES20 How to get global position of vertex after translating and rotating it
我有一个顶点(我不会 showing/rendering 在场景中)
float vertex[] = {
1.0f, 1.0f, 1.0f,
};
我有一个网格,我使用以下方法对其进行了平移和旋转:
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);
如何将这些平移和旋转应用于顶点,并在之后获得其全局位置 (x,y,z)?
使用Matrix.multiplyMV
方法:
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);
请注意,您必须向矢量添加齐次坐标才能使其生效。
我有一个顶点(我不会 showing/rendering 在场景中)
float vertex[] = {
1.0f, 1.0f, 1.0f,
};
我有一个网格,我使用以下方法对其进行了平移和旋转:
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);
如何将这些平移和旋转应用于顶点,并在之后获得其全局位置 (x,y,z)?
使用Matrix.multiplyMV
方法:
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);
请注意,您必须向矢量添加齐次坐标才能使其生效。