From eab2a12beb019cb845af816a6de88c074f88f9bd Mon Sep 17 00:00:00 2001 From: hgn Date: Tue, 31 May 2022 00:01:03 +0100 Subject: [PATCH] new maths functions --- src/vg/vg.h | 5 +++++ src/vg/vg_m.h | 28 ++++++++++++++++++++++++++-- vg_compiler.sh | 12 ++++++------ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/vg/vg.h b/src/vg/vg.h index 681930a..22351ea 100644 --- a/src/vg/vg.h +++ b/src/vg/vg.h @@ -1,5 +1,8 @@ /* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */ +#ifndef VG_HEADER_H +#define VG_HEADER_H + #include #include #include @@ -303,3 +306,5 @@ void vg_projection_update(void) */ u32 NvOptimusEnablement = 0x00000001; int AmdPowerXpressRequestHighPerformance = 1; + +#endif diff --git a/src/vg/vg_m.h b/src/vg/vg_m.h index 7a5a7c2..a61c6f0 100644 --- a/src/vg/vg_m.h +++ b/src/vg/vg_m.h @@ -767,6 +767,21 @@ static inline void m4x3_transform_aabb( m4x3f m, boxf box ) m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], b[2] } ); } +static inline void m4x3_lookat( m4x3f m, v3f pos, v3f target, v3f up ) +{ + v3f dir; + v3_sub( target, pos, dir ); + v3_normalize( dir ); + + v3_negate( dir, m[2] ); + + v3_cross( up, m[2], m[0] ); + v3_normalize( m[0] ); + + v3_cross( m[2], m[0], m[1] ); + v3_copy( pos, m[3] ); +} + /* * Matrix 4x4 */ @@ -956,6 +971,15 @@ static inline void q_mul( v4f q, v4f q1, v4f d ) v4_copy( t, d ); } +static inline void q_normalize( v4f q ) +{ + float s = 1.0f/ sqrtf(v4_dot(q,q)); + q[0] *= s; + q[1] *= s; + q[2] *= s; + q[3] *= s; +} + static inline void q_inv( v4f q, v4f d ) { float s = 1.0f / v4_dot(q,q); @@ -971,9 +995,9 @@ static inline void q_m3x3( v4f q, m3x3f d ) l = v4_length(q), s = l > 0.0f? 2.0f/l: 0.0f, - xx = s*q[0]*q[0], xy = s*q[0]*q[2], wx = s*q[3]*q[0], + xx = s*q[0]*q[0], xy = s*q[0]*q[1], wx = s*q[3]*q[0], yy = s*q[1]*q[1], yz = s*q[1]*q[2], wy = s*q[3]*q[1], - zz = s*q[2]*q[2], xz = s*q[2]*q[2], wz = s*q[3]*q[2]; + zz = s*q[2]*q[2], xz = s*q[0]*q[2], wz = s*q[3]*q[2]; d[0][0] = 1.0f - yy - zz; d[1][1] = 1.0f - xx - zz; diff --git a/vg_compiler.sh b/vg_compiler.sh index a27da4a..9a60b3d 100755 --- a/vg_compiler.sh +++ b/vg_compiler.sh @@ -65,7 +65,7 @@ target_os_windows(){ target_platform_include="" if [ $opt_release = true ]; then - target_opts="-O3" + target_opts="-O3 -DVG_RELEASE" else target_opts="-ggdb3" fi @@ -73,7 +73,7 @@ target_os_windows(){ target_os_linux(){ target_ext="" - target_compiler="gcc" + target_compiler="clang" target_libs="-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lm -pthread -lXi -ldl" target_libs_steam="-lsteam_api" #target_platform_include="-include $vg_root/platformutils/force_link_glibc_2.23.h" @@ -82,9 +82,9 @@ target_os_linux(){ target_steam_api="libsteam_api.so" target_miniaudio="$vg_root/dep/dr_soft/miniaudio_linux.o" if [ $opt_release = true ]; then - target_opts="-O3" + target_opts="-O3 -DVG_RELEASE" else - target_opts="-O1 -fsanitize=address -ggdb3 -fno-omit-frame-pointer" + target_opts="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer" fi } @@ -95,7 +95,7 @@ precompile_x(){ fi sources="$1" output="-o $2" - cmd="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include + cmd="$target_compiler $target_standard $target_opts $target_platform_include -c $sources $output" @@ -120,7 +120,7 @@ compile_x(){ steam_part="$opt_steam $target_libs_steam" fi - warnings="-Wall -Wstrict-aliasing=3 -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable" + warnings="-Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable" sources="$1 $vg_root/dep/glad/glad.c $target_miniaudio" output="-o $2$target_ext" -- 2.25.1