1 #include <com.badlogic.gdx.math.Matrix4.h> 2 3 //@line:1157 4 5 #include <memory.h> 6 #include <stdio.h> 7 #include <string.h> 8 9 #define M00 0 10 #define M01 4 11 #define M02 8 12 #define M03 12 13 #define M10 1 14 #define M11 5 15 #define M12 9 16 #define M13 13 17 #define M20 2 18 #define M21 6 19 #define M22 10 20 #define M23 14 21 #define M30 3 22 #define M31 7 23 #define M32 11 24 #define M33 15 25 26 static inline void matrix4_mul(float* mata, float* matb) { 27 float tmp[16]; 28 tmp[M00] = mata[M00] * matb[M00] + mata[M01] * matb[M10] + mata[M02] * matb[M20] + mata[M03] * matb[M30]; 29 tmp[M01] = mata[M00] * matb[M01] + mata[M01] * matb[M11] + mata[M02] * matb[M21] + mata[M03] * matb[M31]; 30 tmp[M02] = mata[M00] * matb[M02] + mata[M01] * matb[M12] + mata[M02] * matb[M22] + mata[M03] * matb[M32]; 31 tmp[M03] = mata[M00] * matb[M03] + mata[M01] * matb[M13] + mata[M02] * matb[M23] + mata[M03] * matb[M33]; 32 tmp[M10] = mata[M10] * matb[M00] + mata[M11] * matb[M10] + mata[M12] * matb[M20] + mata[M13] * matb[M30]; 33 tmp[M11] = mata[M10] * matb[M01] + mata[M11] * matb[M11] + mata[M12] * matb[M21] + mata[M13] * matb[M31]; 34 tmp[M12] = mata[M10] * matb[M02] + mata[M11] * matb[M12] + mata[M12] * matb[M22] + mata[M13] * matb[M32]; 35 tmp[M13] = mata[M10] * matb[M03] + mata[M11] * matb[M13] + mata[M12] * matb[M23] + mata[M13] * matb[M33]; 36 tmp[M20] = mata[M20] * matb[M00] + mata[M21] * matb[M10] + mata[M22] * matb[M20] + mata[M23] * matb[M30]; 37 tmp[M21] = mata[M20] * matb[M01] + mata[M21] * matb[M11] + mata[M22] * matb[M21] + mata[M23] * matb[M31]; 38 tmp[M22] = mata[M20] * matb[M02] + mata[M21] * matb[M12] + mata[M22] * matb[M22] + mata[M23] * matb[M32]; 39 tmp[M23] = mata[M20] * matb[M03] + mata[M21] * matb[M13] + mata[M22] * matb[M23] + mata[M23] * matb[M33]; 40 tmp[M30] = mata[M30] * matb[M00] + mata[M31] * matb[M10] + mata[M32] * matb[M20] + mata[M33] * matb[M30]; 41 tmp[M31] = mata[M30] * matb[M01] + mata[M31] * matb[M11] + mata[M32] * matb[M21] + mata[M33] * matb[M31]; 42 tmp[M32] = mata[M30] * matb[M02] + mata[M31] * matb[M12] + mata[M32] * matb[M22] + mata[M33] * matb[M32]; 43 tmp[M33] = mata[M30] * matb[M03] + mata[M31] * matb[M13] + mata[M32] * matb[M23] + mata[M33] * matb[M33]; 44 memcpy(mata, tmp, sizeof(float) * 16); 45 } 46 47 static inline float matrix4_det(float* val) { 48 return val[M30] * val[M21] * val[M12] * val[M03] - val[M20] * val[M31] * val[M12] * val[M03] - val[M30] * val[M11] 49 * val[M22] * val[M03] + val[M10] * val[M31] * val[M22] * val[M03] + val[M20] * val[M11] * val[M32] * val[M03] - val[M10] 50 * val[M21] * val[M32] * val[M03] - val[M30] * val[M21] * val[M02] * val[M13] + val[M20] * val[M31] * val[M02] * val[M13] 51 + val[M30] * val[M01] * val[M22] * val[M13] - val[M00] * val[M31] * val[M22] * val[M13] - val[M20] * val[M01] * val[M32] 52 * val[M13] + val[M00] * val[M21] * val[M32] * val[M13] + val[M30] * val[M11] * val[M02] * val[M23] - val[M10] * val[M31] 53 * val[M02] * val[M23] - val[M30] * val[M01] * val[M12] * val[M23] + val[M00] * val[M31] * val[M12] * val[M23] + val[M10] 54 * val[M01] * val[M32] * val[M23] - val[M00] * val[M11] * val[M32] * val[M23] - val[M20] * val[M11] * val[M02] * val[M33] 55 + val[M10] * val[M21] * val[M02] * val[M33] + val[M20] * val[M01] * val[M12] * val[M33] - val[M00] * val[M21] * val[M12] 56 * val[M33] - val[M10] * val[M01] * val[M22] * val[M33] + val[M00] * val[M11] * val[M22] * val[M33]; 57 } 58 59 static inline bool matrix4_inv(float* val) { 60 float tmp[16]; 61 float l_det = matrix4_det(val); 62 if (l_det == 0) return false; 63 tmp[M00] = val[M12] * val[M23] * val[M31] - val[M13] * val[M22] * val[M31] + val[M13] * val[M21] * val[M32] - val[M11] 64 * val[M23] * val[M32] - val[M12] * val[M21] * val[M33] + val[M11] * val[M22] * val[M33]; 65 tmp[M01] = val[M03] * val[M22] * val[M31] - val[M02] * val[M23] * val[M31] - val[M03] * val[M21] * val[M32] + val[M01] 66 * val[M23] * val[M32] + val[M02] * val[M21] * val[M33] - val[M01] * val[M22] * val[M33]; 67 tmp[M02] = val[M02] * val[M13] * val[M31] - val[M03] * val[M12] * val[M31] + val[M03] * val[M11] * val[M32] - val[M01] 68 * val[M13] * val[M32] - val[M02] * val[M11] * val[M33] + val[M01] * val[M12] * val[M33]; 69 tmp[M03] = val[M03] * val[M12] * val[M21] - val[M02] * val[M13] * val[M21] - val[M03] * val[M11] * val[M22] + val[M01] 70 * val[M13] * val[M22] + val[M02] * val[M11] * val[M23] - val[M01] * val[M12] * val[M23]; 71 tmp[M10] = val[M13] * val[M22] * val[M30] - val[M12] * val[M23] * val[M30] - val[M13] * val[M20] * val[M32] + val[M10] 72 * val[M23] * val[M32] + val[M12] * val[M20] * val[M33] - val[M10] * val[M22] * val[M33]; 73 tmp[M11] = val[M02] * val[M23] * val[M30] - val[M03] * val[M22] * val[M30] + val[M03] * val[M20] * val[M32] - val[M00] 74 * val[M23] * val[M32] - val[M02] * val[M20] * val[M33] + val[M00] * val[M22] * val[M33]; 75 tmp[M12] = val[M03] * val[M12] * val[M30] - val[M02] * val[M13] * val[M30] - val[M03] * val[M10] * val[M32] + val[M00] 76 * val[M13] * val[M32] + val[M02] * val[M10] * val[M33] - val[M00] * val[M12] * val[M33]; 77 tmp[M13] = val[M02] * val[M13] * val[M20] - val[M03] * val[M12] * val[M20] + val[M03] * val[M10] * val[M22] - val[M00] 78 * val[M13] * val[M22] - val[M02] * val[M10] * val[M23] + val[M00] * val[M12] * val[M23]; 79 tmp[M20] = val[M11] * val[M23] * val[M30] - val[M13] * val[M21] * val[M30] + val[M13] * val[M20] * val[M31] - val[M10] 80 * val[M23] * val[M31] - val[M11] * val[M20] * val[M33] + val[M10] * val[M21] * val[M33]; 81 tmp[M21] = val[M03] * val[M21] * val[M30] - val[M01] * val[M23] * val[M30] - val[M03] * val[M20] * val[M31] + val[M00] 82 * val[M23] * val[M31] + val[M01] * val[M20] * val[M33] - val[M00] * val[M21] * val[M33]; 83 tmp[M22] = val[M01] * val[M13] * val[M30] - val[M03] * val[M11] * val[M30] + val[M03] * val[M10] * val[M31] - val[M00] 84 * val[M13] * val[M31] - val[M01] * val[M10] * val[M33] + val[M00] * val[M11] * val[M33]; 85 tmp[M23] = val[M03] * val[M11] * val[M20] - val[M01] * val[M13] * val[M20] - val[M03] * val[M10] * val[M21] + val[M00] 86 * val[M13] * val[M21] + val[M01] * val[M10] * val[M23] - val[M00] * val[M11] * val[M23]; 87 tmp[M30] = val[M12] * val[M21] * val[M30] - val[M11] * val[M22] * val[M30] - val[M12] * val[M20] * val[M31] + val[M10] 88 * val[M22] * val[M31] + val[M11] * val[M20] * val[M32] - val[M10] * val[M21] * val[M32]; 89 tmp[M31] = val[M01] * val[M22] * val[M30] - val[M02] * val[M21] * val[M30] + val[M02] * val[M20] * val[M31] - val[M00] 90 * val[M22] * val[M31] - val[M01] * val[M20] * val[M32] + val[M00] * val[M21] * val[M32]; 91 tmp[M32] = val[M02] * val[M11] * val[M30] - val[M01] * val[M12] * val[M30] - val[M02] * val[M10] * val[M31] + val[M00] 92 * val[M12] * val[M31] + val[M01] * val[M10] * val[M32] - val[M00] * val[M11] * val[M32]; 93 tmp[M33] = val[M01] * val[M12] * val[M20] - val[M02] * val[M11] * val[M20] + val[M02] * val[M10] * val[M21] - val[M00] 94 * val[M12] * val[M21] - val[M01] * val[M10] * val[M22] + val[M00] * val[M11] * val[M22]; 95 96 float inv_det = 1.0f / l_det; 97 val[M00] = tmp[M00] * inv_det; 98 val[M01] = tmp[M01] * inv_det; 99 val[M02] = tmp[M02] * inv_det; 100 val[M03] = tmp[M03] * inv_det; 101 val[M10] = tmp[M10] * inv_det; 102 val[M11] = tmp[M11] * inv_det; 103 val[M12] = tmp[M12] * inv_det; 104 val[M13] = tmp[M13] * inv_det; 105 val[M20] = tmp[M20] * inv_det; 106 val[M21] = tmp[M21] * inv_det; 107 val[M22] = tmp[M22] * inv_det; 108 val[M23] = tmp[M23] * inv_det; 109 val[M30] = tmp[M30] * inv_det; 110 val[M31] = tmp[M31] * inv_det; 111 val[M32] = tmp[M32] * inv_det; 112 val[M33] = tmp[M33] * inv_det; 113 return true; 114 } 115 116 static inline void matrix4_mulVec(float* mat, float* vec) { 117 float x = vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]; 118 float y = vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]; 119 float z = vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]; 120 vec[0] = x; 121 vec[1] = y; 122 vec[2] = z; 123 } 124 125 static inline void matrix4_proj(float* mat, float* vec) { 126 float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + vec[2] * mat[M32] + mat[M33]); 127 float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]) * inv_w; 128 float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]) * inv_w; 129 float z = (vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]) * inv_w; 130 vec[0] = x; 131 vec[1] = y; 132 vec[2] = z; 133 } 134 135 static inline void matrix4_rot(float* mat, float* vec) { 136 float x = vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02]; 137 float y = vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12]; 138 float z = vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22]; 139 vec[0] = x; 140 vec[1] = y; 141 vec[2] = z; 142 } 143 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mul(JNIEnv* env, jclass clazz, jfloatArray obj_mata, jfloatArray obj_matb) { 144 float* mata = (float*)env->GetPrimitiveArrayCritical(obj_mata, 0); 145 float* matb = (float*)env->GetPrimitiveArrayCritical(obj_matb, 0); 146 147 148 //@line:1303 149 150 matrix4_mul(mata, matb); 151 152 env->ReleasePrimitiveArrayCritical(obj_mata, mata, 0); 153 env->ReleasePrimitiveArrayCritical(obj_matb, matb, 0); 154 155 } 156 157 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVec___3F_3F(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vec) { 158 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 159 float* vec = (float*)env->GetPrimitiveArrayCritical(obj_vec, 0); 160 161 162 //@line:1313 163 164 matrix4_mulVec(mat, vec); 165 166 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 167 env->ReleasePrimitiveArrayCritical(obj_vec, vec, 0); 168 169 } 170 171 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_mulVec___3F_3FIII(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vecs, jint offset, jint numVecs, jint stride) { 172 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 173 float* vecs = (float*)env->GetPrimitiveArrayCritical(obj_vecs, 0); 174 175 176 //@line:1328 177 178 float* vecPtr = vecs + offset; 179 for(int i = 0; i < numVecs; i++) { 180 matrix4_mulVec(mat, vecPtr); 181 vecPtr += stride; 182 } 183 184 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 185 env->ReleasePrimitiveArrayCritical(obj_vecs, vecs, 0); 186 187 } 188 189 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_prj___3F_3F(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vec) { 190 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 191 float* vec = (float*)env->GetPrimitiveArrayCritical(obj_vec, 0); 192 193 194 //@line:1342 195 196 matrix4_proj(mat, vec); 197 198 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 199 env->ReleasePrimitiveArrayCritical(obj_vec, vec, 0); 200 201 } 202 203 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_prj___3F_3FIII(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vecs, jint offset, jint numVecs, jint stride) { 204 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 205 float* vecs = (float*)env->GetPrimitiveArrayCritical(obj_vecs, 0); 206 207 208 //@line:1357 209 210 float* vecPtr = vecs + offset; 211 for(int i = 0; i < numVecs; i++) { 212 matrix4_proj(mat, vecPtr); 213 vecPtr += stride; 214 } 215 216 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 217 env->ReleasePrimitiveArrayCritical(obj_vecs, vecs, 0); 218 219 } 220 221 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rot___3F_3F(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vec) { 222 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 223 float* vec = (float*)env->GetPrimitiveArrayCritical(obj_vec, 0); 224 225 226 //@line:1371 227 228 matrix4_rot(mat, vec); 229 230 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 231 env->ReleasePrimitiveArrayCritical(obj_vec, vec, 0); 232 233 } 234 235 JNIEXPORT void JNICALL Java_com_badlogic_gdx_math_Matrix4_rot___3F_3FIII(JNIEnv* env, jclass clazz, jfloatArray obj_mat, jfloatArray obj_vecs, jint offset, jint numVecs, jint stride) { 236 float* mat = (float*)env->GetPrimitiveArrayCritical(obj_mat, 0); 237 float* vecs = (float*)env->GetPrimitiveArrayCritical(obj_vecs, 0); 238 239 240 //@line:1386 241 242 float* vecPtr = vecs + offset; 243 for(int i = 0; i < numVecs; i++) { 244 matrix4_rot(mat, vecPtr); 245 vecPtr += stride; 246 } 247 248 env->ReleasePrimitiveArrayCritical(obj_mat, mat, 0); 249 env->ReleasePrimitiveArrayCritical(obj_vecs, vecs, 0); 250 251 } 252 253 static inline jboolean wrapped_Java_com_badlogic_gdx_math_Matrix4_inv 254 (JNIEnv* env, jclass clazz, jfloatArray obj_values, float* values) { 255 256 //@line:1398 257 258 return matrix4_inv(values); 259 260 } 261 262 JNIEXPORT jboolean JNICALL Java_com_badlogic_gdx_math_Matrix4_inv(JNIEnv* env, jclass clazz, jfloatArray obj_values) { 263 float* values = (float*)env->GetPrimitiveArrayCritical(obj_values, 0); 264 265 jboolean JNI_returnValue = wrapped_Java_com_badlogic_gdx_math_Matrix4_inv(env, clazz, obj_values, values); 266 267 env->ReleasePrimitiveArrayCritical(obj_values, values, 0); 268 269 return JNI_returnValue; 270 } 271 272 static inline jfloat wrapped_Java_com_badlogic_gdx_math_Matrix4_det 273 (JNIEnv* env, jclass clazz, jfloatArray obj_values, float* values) { 274 275 //@line:1406 276 277 return matrix4_det(values); 278 279 } 280 281 JNIEXPORT jfloat JNICALL Java_com_badlogic_gdx_math_Matrix4_det(JNIEnv* env, jclass clazz, jfloatArray obj_values) { 282 float* values = (float*)env->GetPrimitiveArrayCritical(obj_values, 0); 283 284 jfloat JNI_returnValue = wrapped_Java_com_badlogic_gdx_math_Matrix4_det(env, clazz, obj_values, values); 285 286 env->ReleasePrimitiveArrayCritical(obj_values, values, 0); 287 288 return JNI_returnValue; 289 } 290 291