|
|
8bc1f1 |
|
|
|
8bc1f1 |
#include "private.h"
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
// matrix
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4Identity(double *r) {
|
|
|
8bc1f1 |
r[ 0] = 1; r[ 1] = 0; r[ 2] = 0; r[ 3] = 0;
|
|
|
8bc1f1 |
r[ 4] = 0; r[ 5] = 1; r[ 6] = 0; r[ 7] = 0;
|
|
|
8bc1f1 |
r[ 8] = 0; r[ 9] = 0; r[10] = 1; r[11] = 0;
|
|
|
8bc1f1 |
r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4Translation(double *r, double x, double y, double z) {
|
|
|
8bc1f1 |
r[ 0] = 1; r[ 1] = 0; r[ 2] = 0; r[ 3] = 0;
|
|
|
8bc1f1 |
r[ 4] = 0; r[ 5] = 1; r[ 6] = 0; r[ 7] = 0;
|
|
|
8bc1f1 |
r[ 8] = 0; r[ 9] = 0; r[10] = 1; r[11] = 0;
|
|
|
8bc1f1 |
r[12] = x; r[13] = y; r[14] = z; r[15] = 1;
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4Scale(double *r, double x, double y, double z) {
|
|
|
8bc1f1 |
r[ 0] = x; r[ 1] = 0; r[ 2] = 0; r[ 3] = 0;
|
|
|
8bc1f1 |
r[ 4] = 0; r[ 5] = y; r[ 6] = 0; r[ 7] = 0;
|
|
|
8bc1f1 |
r[ 8] = 0; r[ 9] = 0; r[10] = z; r[11] = 0;
|
|
|
8bc1f1 |
r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4RotationZ(double *r, double a) {
|
|
|
8bc1f1 |
double s = sin(a);
|
|
|
8bc1f1 |
double c = cos(a);
|
|
|
8bc1f1 |
r[ 0] = c; r[ 1] = s; r[ 2] = 0; r[ 3] = 0;
|
|
|
8bc1f1 |
r[ 4] =-s; r[ 5] = c; r[ 6] = 0; r[ 7] = 0;
|
|
|
8bc1f1 |
r[ 8] = 0; r[ 9] = 0; r[10] = 1; r[11] = 0;
|
|
|
8bc1f1 |
r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4MultVec(double *r, const double *m, const double *v) {
|
|
|
8bc1f1 |
r[0] = v[0]*m[0] + v[1]*m[4] + v[2]*m[ 8] + v[3]*m[12];
|
|
|
8bc1f1 |
r[1] = v[0]*m[1] + v[1]*m[5] + v[2]*m[ 9] + v[3]*m[13];
|
|
|
8bc1f1 |
r[2] = v[0]*m[2] + v[1]*m[6] + v[2]*m[10] + v[3]*m[14];
|
|
|
8bc1f1 |
r[3] = v[0]*m[3] + v[1]*m[7] + v[2]*m[11] + v[3]*m[15];
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
void heliMatrix4Mult(double *r, const double *a, const double *b) {
|
|
|
8bc1f1 |
heliMatrix4MultVec(r + 0, a, b + 0);
|
|
|
8bc1f1 |
heliMatrix4MultVec(r + 4, a, b + 4);
|
|
|
8bc1f1 |
heliMatrix4MultVec(r + 8, a, b + 8);
|
|
|
8bc1f1 |
heliMatrix4MultVec(r + 12, a, b + 12);
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
int heliMatrix4Invert(double *r, const double *m) {
|
|
|
8bc1f1 |
r[ 0] = m[ 5]*(m[10]*m[15] - m[11]*m[14]) + m[ 6]*(m[11]*m[13] - m[ 9]*m[15]) + m[ 7]*(m[ 9]*m[14] - m[10]*m[13]);
|
|
|
8bc1f1 |
r[ 4] = m[ 4]*(m[11]*m[14] - m[10]*m[15]) + m[ 6]*(m[ 8]*m[15] - m[11]*m[12]) + m[ 7]*(m[10]*m[12] - m[ 8]*m[14]);
|
|
|
8bc1f1 |
r[ 8] = m[ 4]*(m[ 9]*m[15] - m[11]*m[13]) + m[ 5]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 7]*(m[ 8]*m[13] - m[ 9]*m[12]);
|
|
|
8bc1f1 |
r[12] = m[ 4]*(m[10]*m[13] - m[ 9]*m[14]) + m[ 5]*(m[ 8]*m[14] - m[10]*m[12]) + m[ 6]*(m[ 9]*m[12] - m[ 8]*m[13]);
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
double det = m[ 0]*r[0] + m[ 1]*r[4] + m[ 2]*r[8] + m[ 3]*r[12];
|
|
|
812e27 |
if (fabs(det) <= HELI_PRECISION_SQR*HELI_PRECISION) {
|
|
|
8bc1f1 |
memset(r, 0, sizeof(*r)*16);
|
|
|
8bc1f1 |
return FALSE;
|
|
|
8bc1f1 |
}
|
|
|
8bc1f1 |
det = 1/det;
|
|
|
8bc1f1 |
r[ 0] *= det;
|
|
|
8bc1f1 |
r[ 4] *= det;
|
|
|
8bc1f1 |
r[ 8] *= det;
|
|
|
8bc1f1 |
r[12] *= det;
|
|
|
8bc1f1 |
|
|
|
8bc1f1 |
r[ 1] = det*(m[ 1]*(m[11]*m[14] - m[10]*m[15]) + m[ 2]*(m[ 9]*m[15] - m[11]*m[13]) + m[ 3]*(m[10]*m[13] - m[ 9]*m[14]));
|
|
|
8bc1f1 |
r[ 5] = det*(m[ 0]*(m[10]*m[15] - m[11]*m[14]) + m[ 2]*(m[11]*m[12] - m[ 8]*m[15]) + m[ 3]*(m[ 8]*m[14] - m[10]*m[12]));
|
|
|
8bc1f1 |
r[ 9] = det*(m[ 0]*(m[11]*m[13] - m[ 9]*m[15]) + m[ 1]*(m[ 8]*m[15] - m[11]*m[12]) + m[ 3]*(m[ 9]*m[12] - m[ 8]*m[13]));
|
|
|
8bc1f1 |
r[13] = det*(m[ 0]*(m[ 9]*m[14] - m[10]*m[13]) + m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