new maths functions
authorhgn <hgodden00@gmail.com>
Mon, 30 May 2022 23:01:03 +0000 (00:01 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 30 May 2022 23:01:03 +0000 (00:01 +0100)
src/vg/vg.h
src/vg/vg_m.h
vg_compiler.sh

index 681930af4cd2f7c32140c891adf9c6ae9edd6a38..22351ea0253249b92f54218ba841802c34669ab6 100644 (file)
@@ -1,5 +1,8 @@
 /* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
 
+#ifndef VG_HEADER_H
+#define VG_HEADER_H
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <dirent.h>
@@ -303,3 +306,5 @@ void vg_projection_update(void)
  */
 u32 NvOptimusEnablement = 0x00000001;
 int AmdPowerXpressRequestHighPerformance = 1;
+
+#endif
index 7a5a7c22aa11caa4448bf81a938595eca2bbefd0..a61c6f0565575a442a98fa43fb675b3ef2edb834 100644 (file)
@@ -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;
index a27da4ae00509e05e67850040f471289255dabce..9a60b3df574405b94f3c86aec4ab8583c7839d43 100755 (executable)
@@ -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"