summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/math.c3
-rw-r--r--src/math/math.h1
-rw-r--r--src/math/matrix.c12
-rw-r--r--src/math/vec3.c4
4 files changed, 16 insertions, 4 deletions
diff --git a/src/math/math.c b/src/math/math.c
index 4cca29e..7d731f8 100644
--- a/src/math/math.c
+++ b/src/math/math.c
@@ -5,14 +5,13 @@ char printbuffer[2048] = { 0 };
float rsqrt(float number) {
long i;
float x2, y;
- const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
- y = y * (threehalfs - (x2 * y * y));
+ y = y * (1.5F - (x2 * y * y));
return y;
}
diff --git a/src/math/math.h b/src/math/math.h
index 4498920..90c7521 100644
--- a/src/math/math.h
+++ b/src/math/math.h
@@ -211,6 +211,7 @@ void mat4_zero(Mat4* out);
void mat4_setidentity(Mat4* out);
void mat4_setfrustum(float l, float r, float b, float t, float n, float f, Mat4* out);
void mat4_setperspective(float fov, float aspect, float near, float far, Mat4* out);
+void mat4_setortho(float l, float r, float b, float t, float n, float f, Mat4* out);
void mat4_setscale(float kx, float ky, float kz, Mat4* out);
void mat4_setposition(float x, float y, float z, Mat4* out);
void mat4_setrotatez(float angle, Mat4* out);
diff --git a/src/math/matrix.c b/src/math/matrix.c
index 458f432..15a194d 100644
--- a/src/math/matrix.c
+++ b/src/math/matrix.c
@@ -61,6 +61,18 @@ void mat4_setidentity(Mat4* out) {
out->e33 = 1;
}
+void mat4_setortho(float l, float r, float b, float t, float n, float f, Mat4* out) {
+ ssr_assert(out);
+ mat4_zero(out);
+ out->e00 = 2 / (r - l);
+ out->e03 = -(r + l) / (r - l);
+ out->e11 = 2 / (t - b);
+ out->e13 = -(t + b) / (t - b);
+ out->e22 = -2 / (f - n);
+ out->e23 = -(f + n) / (f - n);
+ out->e33 = 1;
+}
+
void mat4_setfrustum(float l, float r, float b, float t, float n, float f, Mat4* out) {
ssr_assert(out);
mat4_zero(out);
diff --git a/src/math/vec3.c b/src/math/vec3.c
index 4d77b96..4ca8519 100644
--- a/src/math/vec3.c
+++ b/src/math/vec3.c
@@ -96,8 +96,8 @@ void vec3_multiply(Vec3* v1, Vec3* v2, Quat* out) {
void vec3_normalize(Vec3* v, Vec3* out) {
ssr_assert(v && out);
- //float mag = rsqrt(v->x * v->x + v->y * v->y + v->z * v->z);
- float mag = 1.f / vec3_magnitude(v);
+ float mag = rsqrt(v->x * v->x + v->y * v->y + v->z * v->z);
+ //float mag = 1.f / vec3_magnitude(v);
out->x = v->x * mag;
out->y = v->y * mag;
out->z = v->z * mag;