transparent-cube

Minimal cross-platform native/wasm graphics example.
git clone git://git.amin.space/transparent-cube.git
Log | Files | Refs | README | LICENSE

commit f5d97777de27fb08bcec02fd3b29410947826312
parent 1b0b3c87b211bf9c1f5f7262f8bb280feb18be5f
Author: amin <dev@aminmesbah.com>
Date:   Sat, 15 Jun 2019 22:17:30 +0000

Remove unused math functions

FossilOrigin-Name: c93a274622d3079f8594f00373fbed7fffe817c1b2069be4d312609490db89c4
Diffstat:
Msrc/glmth.c | 259+------------------------------------------------------------------------------
Msrc/glmth.h | 2+-
2 files changed, 2 insertions(+), 259 deletions(-)

diff --git a/src/glmth.c b/src/glmth.c @@ -3,7 +3,7 @@ #include <stdio.h> #include <stdlib.h> -m4 glmth_m4_init_id() +m4 glmth_m4_init_id(void) { m4 m = { 0 }; m.E[0][0] = 1.0f; @@ -14,17 +14,6 @@ m4 glmth_m4_init_id() } -void glmth_m4_print(m4 m) -{ - printf("[\n"); - printf(" %f, %f, %f, %f\n", m.E[0][0], m.E[0][1], m.E[0][2], m.E[0][3]); - printf(" %f, %f, %f, %f\n", m.E[1][0], m.E[1][1], m.E[1][2], m.E[1][3]); - printf(" %f, %f, %f, %f\n", m.E[2][0], m.E[2][1], m.E[2][2], m.E[2][3]); - printf(" %f, %f, %f, %f\n", m.E[3][0], m.E[3][1], m.E[3][2], m.E[3][3]); - printf("]\n"); -} - - f32 *glmth_m4_valueptr(m4 m) { f32 *values = malloc(sizeof(m4)); @@ -38,22 +27,6 @@ f32 *glmth_m4_valueptr(m4 m) } -bool glmth_m4m4_eq(m4 mat1, m4 mat2) -{ - for (u8 i = 0; i < 4; ++i) - { - for (u8 j = 0; j < 4; ++j) - { - if (mat1.E[i][j] != mat2.E[i][j]) - { - return false; - } - } - } - return true; -} - - m4 glmth_m4m4_m(m4 mat1, m4 mat2) { m4 r = { @@ -81,58 +54,17 @@ m4 glmth_m4m4_m(m4 mat1, m4 mat2) } -v4 glmth_m4v4_m(m4 m, v4 v) -{ - v4 r = { - .x = (m.E[0][0] * v.x) + (m.E[0][1] * v.y) + (m.E[0][2] * v.z) + (m.E[0][3] * v.w), - .y = (m.E[1][0] * v.x) + (m.E[1][1] * v.y) + (m.E[1][2] * v.z) + (m.E[1][3] * v.w), - .z = (m.E[2][0] * v.x) + (m.E[2][1] * v.y) + (m.E[2][2] * v.z) + (m.E[2][3] * v.w), - .w = (m.E[3][0] * v.x) + (m.E[3][1] * v.y) + (m.E[3][2] * v.z) + (m.E[3][3] * v.w), - }; - return r; -} - - -v3 glmth_v3_cross(v3 vec1, v3 vec2) -{ - v3 r = { - .x = (vec1.y * vec2.z) - (vec1.z * vec2.y), - .y = (vec1.z * vec2.x) - (vec1.x * vec2.z), - .z = (vec1.x * vec2.y) - (vec1.y * vec2.x), - }; - return r; -} - - v3 glmth_v3_init(f32 x, f32 y, f32 z) { v3 v = { .x = x, .y = y, .z = z }; return v; } -v3 glmth_v3_init_f(f32 f) -{ - return glmth_v3_init(f, f, f); -} - f32 glmth_v3_length(v3 v) { return sqrtf((v.x * v.x) + (v.y * v.y) + (v.z * v.z)); } -v3 glmth_v3f_m(v3 v, f32 s) -{ - v3 r = { .x = v.x * s, .y = v.y * s, .z = v.z * s }; - return r; -} - -v3 glmth_v3_negate(v3 v) -{ - v3 r = { .x = -v.x, .y = -v.y, .z = -v.z }; - return r; -} - - v3 glmth_v3_normalize(v3 v) { f32 l = glmth_v3_length(v); @@ -140,132 +72,11 @@ v3 glmth_v3_normalize(v3 v) return r; } - -void glmth_v3_print(v3 v) -{ - printf("( %f, %f, %f )\n", v.x, v.y, v.z); -} - - -v3 glmth_v3_a(v3 vec1, v3 vec2) -{ - v3 r = { - .x = vec1.x + vec2.x, - .y = vec1.y + vec2.y, - .z = vec1.z + vec2.z - }; - return r; -} - - -v3 glmth_v3_s(v3 vec1, v3 vec2) -{ - return glmth_v3_a(vec1, glmth_v3_negate(vec2)); -} - - -void glmth_v4_print(v4 v) -{ - printf("( %f, %f, %f, %f )\n", v.x, v.y, v.z, v.w); -} - - -bool glmth_v4v4_eq(v4 vec1, v4 vec2) -{ - for (u8 i = 0; i < 4; ++i) - { - if (vec1.E[i] != vec2.E[i]) - { - return false; - } - } - return true; -} - - -void glmth_clampf(float *f, float min, float max) -{ - if (*f < min) - { - *f = min; - } - else if (*f > max) - { - *f = max; - } -} - - -f32 glmth_deg(f32 rad) -{ - return rad * (180.0f / M_PI); -} - - -float glmth_lerpf(float f, float min, float max) -{ - assert(f >= 0.0f && f <= 1.0f); - return (1.0f - f) * min + f * max; -} - - f32 glmth_rad(f32 deg) { return deg * (M_PI / 180.0f); } - -m4 glmth_rotate_x(m4 m, f32 rad) -{ - f32 c = cosf(rad); - f32 s = sinf(rad); - - m4 r = glmth_m4_init_id(); - - r.E[1][1] = c; - r.E[1][2] = -s; - - r.E[2][1] = s; - r.E[2][2] = c; - - return glmth_m4m4_m(m, r); -} - - -m4 glmth_rotate_y(m4 m, f32 rad) -{ - f32 c = cosf(rad); - f32 s = sinf(rad); - - m4 r = glmth_m4_init_id(); - - r.E[0][0] = c; - r.E[0][2] = s; - - r.E[2][0] = -s; - r.E[2][2] = c; - - return glmth_m4m4_m(m, r); -} - - -m4 glmth_rotate_z(m4 m, f32 rad) -{ - f32 c = cosf(rad); - f32 s = sinf(rad); - - m4 r = glmth_m4_init_id(); - - r.E[0][0] = c; - r.E[0][1] = -s; - - r.E[1][0] = s; - r.E[1][1] = c; - - return glmth_m4m4_m(m, r); -} - - m4 glmth_rotate(m4 m, f32 rad, v3 axis) { axis = glmth_v3_normalize(axis); @@ -290,17 +101,6 @@ m4 glmth_rotate(m4 m, f32 rad, v3 axis) return glmth_m4m4_m(m, r); } - -m4 glmth_scale(m4 m, v3 v) -{ - m4 r = glmth_m4_init_id(); - r.E[0][0] = v.x; - r.E[1][1] = v.y; - r.E[2][2] = v.z; - return glmth_m4m4_m(m, r); -} - - m4 glmth_translate(m4 m, v3 v) { m4 r = glmth_m4_init_id(); @@ -310,39 +110,6 @@ m4 glmth_translate(m4 m, v3 v) return glmth_m4m4_m(m, r); } - -m4 glmth_projection_ortho(f32 left, f32 right, f32 bottom, f32 top, f32 near, f32 far) -{ - assert(left != right); - assert(bottom != top); - assert(near != far); - - m4 r = glmth_m4_init_id(); - - r.E[0][0] = 2.0f / (right - left); - r.E[0][1] = 0.0f; - r.E[0][2] = 0.0f; - r.E[0][3] = -(right + left) / (right - left); - - r.E[1][0] = 0.0f; - r.E[1][1] = 2.0f / (top - bottom); - r.E[1][2] = 0.0f; - r.E[1][3] = -(top + bottom) / (top - bottom); - - r.E[2][0] = 0.0f; - r.E[2][1] = 0.0f; - r.E[2][2] = -2.0f / (far - near); - r.E[2][3] = -(far + near) / (far - near); - - r.E[3][0] = 0.0f; - r.E[3][1] = 0.0f; - r.E[3][2] = 0.0f; - r.E[3][3] = 1.0f; - - return r; -} - - m4 glmth_projection_perspective(f32 left, f32 right, f32 bottom, f32 top, f32 near, f32 far) { assert(left != right); @@ -374,7 +141,6 @@ m4 glmth_projection_perspective(f32 left, f32 right, f32 bottom, f32 top, f32 ne return r; } - m4 glmth_projection_perspective_fov(f32 fovy, f32 aspect, f32 near, f32 far) { f32 half_height = tanf(fovy / 2.0f) * near; @@ -386,26 +152,3 @@ m4 glmth_projection_perspective_fov(f32 fovy, f32 aspect, f32 near, f32 far) return glmth_projection_perspective(left, right, bottom, top, near, far); } - - -m4 glmth_camera_look_at(v3 camera_pos, v3 camera_target, v3 up) -{ - v3 camera_direction = glmth_v3_normalize(glmth_v3_s(camera_pos, camera_target)); - v3 camera_right = glmth_v3_normalize(glmth_v3_cross(up, camera_direction)); - v3 camera_up = glmth_v3_cross(camera_direction, camera_right); - - m4 look = glmth_m4_init_id(); - look.E[0][0] = camera_right.x; - look.E[0][1] = camera_right.y; - look.E[0][2] = camera_right.z; - - look.E[1][0] = camera_up.x; - look.E[1][1] = camera_up.y; - look.E[1][2] = camera_up.z; - - look.E[2][0] = camera_direction.x; - look.E[2][1] = camera_direction.y; - look.E[2][2] = camera_direction.z; - - return glmth_m4m4_m(look, glmth_translate(glmth_m4_init_id(), glmth_v3_negate(camera_pos))); -} diff --git a/src/glmth.h b/src/glmth.h @@ -92,7 +92,7 @@ typedef struct } m4; -m4 glmth_m4_init_id(); +m4 glmth_m4_init_id(void); void glmth_m4_print(m4 m); f32 *glmth_m4_valueptr(m4 m); bool glmth_m4m4_eq(m4 mat1, m4 mat2);