问题
I am developing an OpenGL ES 2.0 android application, by porting the code from an renderscript created application. In renderscript this function is used:
float4 rsMatrixMultiply(rs_matrix4x4 *m, float3 in);
Does anyone knows what exactly this function does and how it is implemented, because I need to use it in my OpenGL application using Java.
回答1:
This does standard matrix multiplication between the matrix 'm' and the vector 'in'. The result is placed back in 'm'. In order to multiply the 4x4 matrix with a vector of size 3, this function behaves as if the vector were float4 with a value of 1 for the w dimension.
For the documentation around this function, take a look here: http://developer.android.com/reference/renderscript/rs__matrix_8rsh.html
Below is the actual code from rs_core.c of the AOSP:
extern float4 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix4x4 *m, float3 in) {
float4 ret;
ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + m->m[12];
ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + m->m[13];
ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + m->m[14];
ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + m->m[15];
return ret;
}
来源:https://stackoverflow.com/questions/8271502/renderscript-rsmatrixmultiply-function