env->ReleasePrimitiveArrayCritical(matrixB, matb, 0);
}
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI___3F_3F
(JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vector) {
float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
float* vec = (float*)env->GetPrimitiveArrayCritical(vector, 0);
env->ReleasePrimitiveArrayCritical(vector, vec, 0);
}
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVec
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI___3F_3FIII
+ (JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vectors, jint offset, jint numVecs, jint stride) {
+ float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
+ float* vec = (float*)env->GetPrimitiveArrayCritical(vectors, 0);
+ float* vecPtr = vec + offset;
+ for(int i = 0; i < numVecs; i++) {
+ matrix4_mulVec(mat, vecPtr);
+ vecPtr += stride;
+ }
+ env->ReleasePrimitiveArrayCritical(matrix, mat, 0);
+ env->ReleasePrimitiveArrayCritical(vectors, vec, 0);
+}
+
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVecJNI___3F_3F
(JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vector) {
float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
float* vec = (float*)env->GetPrimitiveArrayCritical(vector, 0);
env->ReleasePrimitiveArrayCritical(vector, vec, 0);
}
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVec
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVecJNI___3F_3FIII
+ (JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vectors, jint offset, jint numVecs, jint stride) {
+ float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
+ float* vec = (float*)env->GetPrimitiveArrayCritical(vectors, 0);
+ float* vecPtr = vec + offset;
+ for(int i = 0; i < numVecs; i++) {
+ matrix4_proj(mat, vecPtr);
+ vecPtr += stride;
+ }
+ env->ReleasePrimitiveArrayCritical(matrix, mat, 0);
+ env->ReleasePrimitiveArrayCritical(vectors, vec, 0);
+}
+
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVecJNI___3F_3F
(JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vector) {
float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
float* vec = (float*)env->GetPrimitiveArrayCritical(vector, 0);
env->ReleasePrimitiveArrayCritical(vector, vec, 0);
}
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVecJNI___3F_3FIII
+ (JNIEnv *env, jclass, jfloatArray matrix, jfloatArray vectors, jint offset, jint numVecs, jint stride) {
+ float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
+ float* vec = (float*)env->GetPrimitiveArrayCritical(vectors, 0);
+ float* vecPtr = vec + offset;
+ for(int i = 0; i < numVecs; i++) {
+ matrix4_rot(mat, vecPtr);
+ vecPtr += stride;
+ }
+ env->ReleasePrimitiveArrayCritical(matrix, mat, 0);
+ env->ReleasePrimitiveArrayCritical(vectors, vec, 0);
+}
+
JNIEXPORT jboolean JNICALL Java_com_badlogic_gdx_math_Matrix4_invJNI
(JNIEnv *env, jclass, jfloatArray matrix) {
float* mat = (float*)env->GetPrimitiveArrayCritical(matrix, 0);
* Method: mulVecJNI\r
* Signature: ([F[F)V\r
*/\r
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI___3F_3F\r
(JNIEnv *, jclass, jfloatArray, jfloatArray);\r
\r
/*\r
* Class: com_badlogic_gdx_math_Matrix4\r
- * Method: projVec\r
+ * Method: mulVecJNI\r
+ * Signature: ([F[FIII)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVecJNI___3F_3FIII\r
+ (JNIEnv *, jclass, jfloatArray, jfloatArray, jint, jint, jint);\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_math_Matrix4\r
+ * Method: projVecJNI\r
* Signature: ([F[F)V\r
*/\r
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVec\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVecJNI___3F_3F\r
(JNIEnv *, jclass, jfloatArray, jfloatArray);\r
\r
/*\r
* Class: com_badlogic_gdx_math_Matrix4\r
- * Method: rotVec\r
+ * Method: projVecJNI\r
+ * Signature: ([F[FIII)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_projVecJNI___3F_3FIII\r
+ (JNIEnv *, jclass, jfloatArray, jfloatArray, jint, jint, jint);\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_math_Matrix4\r
+ * Method: rotVecJNI\r
* Signature: ([F[F)V\r
*/\r
-JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVec\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVecJNI___3F_3F\r
(JNIEnv *, jclass, jfloatArray, jfloatArray);\r
\r
/*\r
* Class: com_badlogic_gdx_math_Matrix4\r
+ * Method: rotVecJNI\r
+ * Signature: ([F[FIII)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rotVecJNI___3F_3FIII\r
+ (JNIEnv *, jclass, jfloatArray, jfloatArray, jint, jint, jint);\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_math_Matrix4\r
* Method: invJNI\r
* Signature: ([F)Z\r
*/\r
\r
public static native void mulJNI(float[] mata, float[] matb);\r
public static native void mulVecJNI(float[] mat, float[] vec);\r
- public static native void projVec(float[] mat, float[] vec);\r
- public static native void rotVec(float[] mat, float[] vec);\r
+ public static native void mulVecJNI(float[] mat, float[] vecs, int offset, int numVecs, int stride);\r
+ public static native void projVecJNI(float[] mat, float[] vec);\r
+ public static native void projVecJNI(float[] mat, float[] vec, int offset, int numVecs, int stride);\r
+ public static native void rotVecJNI(float[] mat, float[] vec);\r
+ public static native void rotVecJNI(float[] mat, float[] vec, int offset, int numVecs, int stride);\r
public static native boolean invJNI(float[] values);\r
public static native float detJNI(float[] values);\r
}\r
package com.badlogic.gdx.tests;\r
\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.math.Matrix4;\r
import com.badlogic.gdx.math.Vector3;\r
import com.badlogic.gdx.tests.utils.GdxTest;\r
Matrix4 mat3 = new Matrix4();\r
Vector3 vec = new Vector3(1, 2, 3);\r
float[] fvec = {1, 2, 3};\r
+ float[] fvecs = { 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0 };\r
\r
mat1.setToRotation(0, 1, 0, 45);\r
mat2.setToRotation(1, 0, 0, 45);\r
\r
vec.mul(mat1);\r
Matrix4.mulVecJNI(mat1.val, fvec);\r
+ Matrix4.mulVecJNI(mat1.val, fvecs, 0, 3, 5);\r
check(vec, fvec);\r
+ check(vec, fvecs, 3, 5);\r
\r
vec.prj(mat1);\r
- Matrix4.projVec(mat1.val, fvec);\r
+ Matrix4.projVecJNI(mat1.val, fvec);\r
+ Matrix4.projVecJNI(mat1.val, fvecs, 0, 3, 5);\r
check(vec, fvec);\r
+ check(vec, fvecs, 3, 5);\r
\r
vec.rot(mat1);\r
- Matrix4.rotVec(mat1.val, fvec);\r
+ Matrix4.rotVecJNI(mat1.val, fvec);\r
+ Matrix4.rotVecJNI(mat1.val, fvecs, 0, 3, 5);\r
check(vec, fvec);\r
+ check(vec, fvecs, 3, 5);\r
\r
if(mat1.det() != Matrix4.detJNI(mat1.val)) throw new GdxRuntimeException("det doesn't work");\r
\r
mat1.mul(mat2);\r
Matrix4.mulJNI(mat3.val, mat2.val);\r
check(mat1, mat3);\r
+ \r
+ bench();\r
+ }\r
+ \r
+ private void bench() {\r
+ Matrix4 mata = new Matrix4();\r
+ Matrix4 matb = new Matrix4();\r
+ \r
+ long start = System.nanoTime();\r
+ for(int i = 0; i < 1000000; i++) {\r
+ mata.mul(matb);\r
+ }\r
+ Gdx.app.log("MatrixJNITest", "java mul took: " + (System.nanoTime() - start) / 1000000000.0f);\r
+ \r
+ start = System.nanoTime();\r
+ for(int i = 0; i < 1000000; i++) {\r
+ Matrix4.mulJNI(mata.val, matb.val);\r
+ }\r
+ Gdx.app.log("MatrixJNITest", "jni mul took: " + (System.nanoTime() - start) / 1000000000.0f);\r
}\r
\r
private void check(Vector3 vec, float[] fvec) {\r
if(vec.x != fvec[0] || vec.y != fvec[1] || vec.z != fvec[2]) throw new GdxRuntimeException("vectors are not equal");\r
}\r
\r
+ private void check(Vector3 vec, float[] fvec, int numVecs, int stride) {\r
+ int offset = 0;\r
+ for(int i = 0; i < numVecs; i++) {\r
+ if(vec.x != fvec[0] || vec.y != fvec[1] || vec.z != fvec[2]) throw new GdxRuntimeException("vectors are not equal");\r
+ }\r
+ }\r
+ \r
private void check(Matrix4 mat1, Matrix4 mat2) {\r
for(int i = 0; i < 16; i++) {\r
if(mat1.val[i] != mat2.val[i]) throw new GdxRuntimeException("matrices not equal");\r