|
@@ -21,10 +21,10 @@ Matrix* transposeMatrix(Matrix* m) {
|
|
Matrix* mulSetMatrix(Matrix* m, const Matrix* a) {
|
|
Matrix* mulSetMatrix(Matrix* m, const Matrix* a) {
|
|
for(int i = 0; i < 4; i++) {
|
|
for(int i = 0; i < 4; i++) {
|
|
Vector4 d = VECTOR4;
|
|
Vector4 d = VECTOR4;
|
|
- addSet(&d, mul(a->data + 0, m->data[i].data[0]));
|
|
|
|
- addSet(&d, mul(a->data + 1, m->data[i].data[1]));
|
|
|
|
- addSet(&d, mul(a->data + 2, m->data[i].data[2]));
|
|
|
|
- addSet(&d, mul(a->data + 3, m->data[i].data[3]));
|
|
|
|
|
|
+ addSet(&d, mul(a->data + 0, m->data[i].x));
|
|
|
|
+ addSet(&d, mul(a->data + 1, m->data[i].y));
|
|
|
|
+ addSet(&d, mul(a->data + 2, m->data[i].z));
|
|
|
|
+ addSet(&d, mul(a->data + 3, m->data[i].w));
|
|
m->data[i] = d;
|
|
m->data[i] = d;
|
|
}
|
|
}
|
|
return m;
|
|
return m;
|
|
@@ -37,18 +37,18 @@ Matrix* mulMatrix(Matrix* m, const Matrix* a, const Matrix* b) {
|
|
}
|
|
}
|
|
|
|
|
|
Vector3* mulMatrixV3(Vector3* v, const Matrix* m, const Vector3* a) {
|
|
Vector3* mulMatrixV3(Vector3* v, const Matrix* m, const Vector3* a) {
|
|
- Vector4 v4 = V(a->data[0], a->data[1], a->data[2], 1.0f);
|
|
|
|
- v->data[0] = dot(m->data + 0, &v4);
|
|
|
|
- v->data[1] = dot(m->data + 1, &v4);
|
|
|
|
- v->data[2] = dot(m->data + 2, &v4);
|
|
|
|
|
|
+ Vector4 v4 = V(a->x, a->y, a->z, 1.0f);
|
|
|
|
+ v->x = dot(m->data + 0, &v4);
|
|
|
|
+ v->y = dot(m->data + 1, &v4);
|
|
|
|
+ v->z = dot(m->data + 2, &v4);
|
|
mulSet(v, 1.0f / dot(m->data + 3, &v4));
|
|
mulSet(v, 1.0f / dot(m->data + 3, &v4));
|
|
return v;
|
|
return v;
|
|
}
|
|
}
|
|
|
|
|
|
Matrix* scaleMatrix(Matrix* m, const Vector3* v) {
|
|
Matrix* scaleMatrix(Matrix* m, const Vector3* v) {
|
|
- mulSet(m->data + 0, v->data[0]);
|
|
|
|
- mulSet(m->data + 1, v->data[1]);
|
|
|
|
- mulSet(m->data + 2, v->data[2]);
|
|
|
|
|
|
+ mulSet(m->data + 0, v->x);
|
|
|
|
+ mulSet(m->data + 1, v->y);
|
|
|
|
+ mulSet(m->data + 2, v->z);
|
|
return m;
|
|
return m;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -57,9 +57,9 @@ Matrix* scaleMatrixF(Matrix* m, float f) {
|
|
}
|
|
}
|
|
|
|
|
|
Matrix* translateMatrix(Matrix* m, const Vector3* v) {
|
|
Matrix* translateMatrix(Matrix* m, const Vector3* v) {
|
|
- translateMatrixX(m, v->data[0]);
|
|
|
|
- translateMatrixY(m, v->data[1]);
|
|
|
|
- translateMatrixZ(m, v->data[2]);
|
|
|
|
|
|
+ translateMatrixX(m, v->x);
|
|
|
|
+ translateMatrixY(m, v->y);
|
|
|
|
+ translateMatrixZ(m, v->z);
|
|
return m;
|
|
return m;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,33 +79,32 @@ Matrix* translateMatrixZ(Matrix* m, float tz) {
|
|
}
|
|
}
|
|
|
|
|
|
Matrix* translateMatrixTo(Matrix* m, const Vector3* v) {
|
|
Matrix* translateMatrixTo(Matrix* m, const Vector3* v) {
|
|
- m->data[0] = V(1.0f, 0.0f, 0.0f, v->data[0]);
|
|
|
|
- m->data[1] = V(0.0f, 1.0f, 0.0f, v->data[1]);
|
|
|
|
- m->data[2] = V(0.0f, 0.0f, 1.0f, v->data[2]);
|
|
|
|
|
|
+ m->data[0] = V(1.0f, 0.0f, 0.0f, v->x);
|
|
|
|
+ m->data[1] = V(0.0f, 1.0f, 0.0f, v->y);
|
|
|
|
+ m->data[2] = V(0.0f, 0.0f, 1.0f, v->z);
|
|
m->data[3] = V(0.0f, 0.0f, 0.0f, 1.0f);
|
|
m->data[3] = V(0.0f, 0.0f, 0.0f, 1.0f);
|
|
return m;
|
|
return m;
|
|
}
|
|
}
|
|
|
|
|
|
-static Matrix* rotate(Matrix* m, float degrees, int a, int b) {
|
|
|
|
- degrees = degreeToRadian(degrees);
|
|
|
|
- float sin = sinf(degrees);
|
|
|
|
- float cos = cosf(degrees);
|
|
|
|
|
|
+static Matrix* rotate(Matrix* m, float radians, int a, int b) {
|
|
|
|
+ float sin = sinf(radians);
|
|
|
|
+ float cos = cosf(radians);
|
|
Vector4 v = m->data[a];
|
|
Vector4 v = m->data[a];
|
|
sub(m->data + a, mul(&v, cos), mul(m->data + b, sin));
|
|
sub(m->data + a, mul(&v, cos), mul(m->data + b, sin));
|
|
add(m->data + b, mul(&v, sin), mul(m->data + b, cos));
|
|
add(m->data + b, mul(&v, sin), mul(m->data + b, cos));
|
|
return m;
|
|
return m;
|
|
}
|
|
}
|
|
|
|
|
|
-Matrix* rotateMatrixX(Matrix* m, float degrees) {
|
|
|
|
- return rotate(m, degrees, 1, 2);
|
|
|
|
|
|
+Matrix* rotateMatrixX(Matrix* m, float radians) {
|
|
|
|
+ return rotate(m, radians, 1, 2);
|
|
}
|
|
}
|
|
|
|
|
|
-Matrix* rotateMatrixY(Matrix* m, float degrees) {
|
|
|
|
- return rotate(m, -degrees, 0, 2);
|
|
|
|
|
|
+Matrix* rotateMatrixY(Matrix* m, float radians) {
|
|
|
|
+ return rotate(m, -radians, 0, 2);
|
|
}
|
|
}
|
|
|
|
|
|
-Matrix* rotateMatrixZ(Matrix* m, float degrees) {
|
|
|
|
- return rotate(m, degrees, 0, 1);
|
|
|
|
|
|
+Matrix* rotateMatrixZ(Matrix* m, float radians) {
|
|
|
|
+ return rotate(m, radians, 0, 1);
|
|
}
|
|
}
|
|
|
|
|
|
Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
|
|
Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
|
|
@@ -117,9 +116,9 @@ Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
|
|
mul(&b, q, &V(M(m, 0, 1), M(m, 1, 1), M(m, 2, 1)));
|
|
mul(&b, q, &V(M(m, 0, 1), M(m, 1, 1), M(m, 2, 1)));
|
|
mul(&c, q, &V(M(m, 0, 2), M(m, 1, 2), M(m, 2, 2)));
|
|
mul(&c, q, &V(M(m, 0, 2), M(m, 1, 2), M(m, 2, 2)));
|
|
mul(&d, q, &V(M(m, 0, 3), M(m, 1, 3), M(m, 2, 3)));
|
|
mul(&d, q, &V(M(m, 0, 3), M(m, 1, 3), M(m, 2, 3)));
|
|
- m->data[0] = V(a.data[0], b.data[0], c.data[0], d.data[0]);
|
|
|
|
- m->data[1] = V(a.data[1], b.data[1], c.data[1], d.data[1]);
|
|
|
|
- m->data[2] = V(a.data[2], b.data[2], c.data[2], d.data[2]);
|
|
|
|
|
|
+ m->data[0] = V(a.x, b.x, c.x, d.x);
|
|
|
|
+ m->data[1] = V(a.y, b.y, c.y, d.y);
|
|
|
|
+ m->data[2] = V(a.z, b.z, c.z, d.z);
|
|
return m;
|
|
return m;
|
|
}
|
|
}
|
|
|
|
|