aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-10-21 03:10:19 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-10-21 03:10:19 +0200
commit093bf0793ddfb377223d817c8290896880a9e91d (patch)
tree7b20f73533cea53b2a950f5134c8e8e00c0a5c22
parentd9e046af76a1c1ed60c5763f2c94f800c477bd95 (diff)
downloadlinmath-093bf0793ddfb377223d817c8290896880a9e91d.tar.gz
linmath-093bf0793ddfb377223d817c8290896880a9e91d.tar.xz
linmath-093bf0793ddfb377223d817c8290896880a9e91d.zip
minor stylistic changes, TODO comments added
-rw-r--r--linmath.h70
1 files changed, 37 insertions, 33 deletions
diff --git a/linmath.h b/linmath.h
index 4aa6ac4..8807e1f 100644
--- a/linmath.h
+++ b/linmath.h
@@ -277,6 +277,7 @@ static inline void mat4x4_rotate_Z(mat4x4 Q, mat4x4 M, float angle)
}
static inline void mat4x4_invert(mat4x4 T, mat4x4 M)
{
+ /* TODO: Implement a Gauss-Jordan elimination or an iterative Jacobian */
mat4x4 R;
R[0][0] = M[1][1]*(M[2][2]*M[3][3] - M[2][3]*M[3][2]) - M[2][1]*(M[1][2]*M[3][3] - M[1][3]*M[3][2]) - M[3][1]*(M[1][3]*M[2][2] - M[1][2]*M[2][3]);
R[0][1] = M[0][1]*(M[2][3]*M[3][2] - M[2][2]*M[3][3]) - M[2][1]*(M[0][3]*M[3][2] - M[0][2]*M[3][3]) - M[3][1]*(M[0][2]*M[2][3] - M[0][3]*M[2][2]);
@@ -334,34 +335,37 @@ static inline void mat4x4_ortho(mat4x4 M, float l, float r, float b, float t, fl
static inline void mat4x4_perspective(mat4x4 m, float y_fov_in_degrees, float aspect, float n, float f)
{
/* Adapted from Android's OpenGL Matrix.java. */
- float const angle_in_radians = (float) (y_fov_in_degrees * M_PI / 180.0);
- float const a = (float) (1.0 / tan(angle_in_radians / 2.0));
+ float const angle_in_radians = y_fov_in_degrees * M_PI / 180.f;
+ float const a = 1.f / tan(angle_in_radians / 2.f);
m[0][0] = a / aspect;
- m[0][1] = 0.0f;
- m[0][2] = 0.0f;
- m[0][3] = 0.0f;
+ m[0][1] = 0.f;
+ m[0][2] = 0.f;
+ m[0][3] = 0.f;
- m[1][0] = 0.0f;
+ m[1][0] = 0.f;
m[1][1] = a;
- m[1][2] = 0.0f;
- m[1][3] = 0.0f;
+ m[1][2] = 0.f;
+ m[1][3] = 0.f;
- m[2][0] = 0.0f;
- m[2][1] = 0.0f;
+ m[2][0] = 0.f;
+ m[2][1] = 0.f;
m[2][2] = -((f + n) / (f - n));
- m[2][3] = -1.0f;
+ m[2][3] = -1.f;
- m[3][0] = 0.0f;
- m[3][1] = 0.0f;
- m[3][2] = -((2.0f * f * n) / (f - n));
- m[3][3] = 0.0f;
+ m[3][0] = 0.f;
+ m[3][1] = 0.f;
+ m[3][2] = -((2.f * f * n) / (f - n));
+ m[3][3] = 0.f;
}
static inline void mat4x4_look_at(mat4x4 m, vec3 eye, vec3 center, vec3 up)
{
- /* Adapted from Android's OpenGL Matrix.java. */
- // See the OpenGL GLUT documentation for gluLookAt for a description
- // of the algorithm. We implement it in a straightforward way:
+ /* Adapted from Android's OpenGL Matrix.java. */
+ /* See the OpenGL GLUT documentation for gluLookAt for a description */
+ /* of the algorithm. We implement it in a straightforward way: */
+
+ /* TODO: The negation of of can be spared by swapping the order of
+ * operands in the following cross products in the right way. */
vec3 f;
vec3_sub(f, center, eye);
vec3_norm(f, f);
@@ -370,28 +374,28 @@ static inline void mat4x4_look_at(mat4x4 m, vec3 eye, vec3 center, vec3 up)
vec3_mul_cross(s, f, up);
vec3_norm(s, s);
- vec3 u;
- vec3_mul_cross(u, s, f);
+ vec3 t;
+ vec3_mul_cross(t, s, f);
- m[0][0] = s[0];
- m[0][1] = u[0];
+ m[0][0] = s[0];
+ m[0][1] = t[0];
m[0][2] = -f[0];
- m[0][3] = 0.0f;
+ m[0][3] = 0.f;
- m[1][0] = s[1];
- m[1][1] = u[1];
+ m[1][0] = s[1];
+ m[1][1] = t[1];
m[1][2] = -f[1];
- m[1][3] = 0.0f;
+ m[1][3] = 0.f;
- m[2][0] = s[2];
- m[2][1] = u[2];
+ m[2][0] = s[2];
+ m[2][1] = t[2];
m[2][2] = -f[2];
- m[2][3] = 0.0f;
+ m[2][3] = 0.f;
- m[3][0] = 0.0f;
- m[3][1] = 0.0f;
- m[3][2] = 0.0f;
- m[3][3] = 1.0f;
+ m[3][0] = 0.f;
+ m[3][1] = 0.f;
+ m[3][2] = 0.f;
+ m[3][3] = 1.f;
mat4x4_translate_in_place(m, -eye[0], -eye[1], -eye[2]);
}