X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=csrMath.h;fp=csrMath.h;h=5a55ef2b9beecca8624a6abeb9b40a71076bfb43;hp=c14234fe6f9da4a44d0278b8cfff498ffc2be8a9;hb=3e1642e28847218d89d1bec2f8b035c10359ac91;hpb=a53095e1511fecb8cc83c692e7ce7b23852fff16 diff --git a/csrMath.h b/csrMath.h index c14234f..5a55ef2 100644 --- a/csrMath.h +++ b/csrMath.h @@ -3,34 +3,28 @@ #define CSR_PIf 3.14159265358979323846264338327950288f +// Simple min/max replacements float csr_minf( float a, float b ) { - if( a < b ) - return a; - return b; + return a < b? a: b; } float csr_maxf( float a, float b ) { - if( a > b ) - return a; - return b; + return a > b? a: b; } int csr_min( int a, int b ) { - if( a < b ) - return a; - return b; + return a < b? a: b; } int csr_max( int a, int b ) { - if( a > b ) - return a; - return b; + return a > b? a: b; } +// Convert double precision vec3 into single void v3d_v3f( double a[3], float b[3] ) { b[0] = a[0]; @@ -38,6 +32,7 @@ void v3d_v3f( double a[3], float b[3] ) b[2] = a[2]; } +// Convert degrees to radians float csr_rad( float deg ) { return deg * CSR_PIf / 180.0f; @@ -491,57 +486,3 @@ double plane_polarity( double p[4], double a[3] ) -(p[0]*p[3] * p[0] + p[1]*p[3] * p[1] + p[2]*p[3] * p[2]) ; } - -// Raycasting -// ================================================================================================================== - -int csr_slabs( v3f box[2], v3f o, v3f id ) -{ - v3f t0; v3f t1; - v3f tmin; v3f tmax; - - v3_sub( box[0], o, t0 ); - v3_sub( box[1], o, t1 ); - v3_mul( t0, id, t0 ); - v3_mul( t1, id, t1 ); - - v3_minv( t0, t1, tmin ); - v3_maxv( t0, t1, tmax ); - - return v3_maxf( tmin ) <= v3_minf( tmax ); -} - -float csr_ray_tri( v3f o, v3f d, v3f v0, v3f v1, v3f v2, float *u, float *v ) -{ - float const k_cullEpsilon = 0.000001f; - - v3f v0v1; - v3f v0v2; - v3f p; - float det, inv; - - v3f tv; - v3f qv; - - v3_sub( v1, v0, v0v1 ); - v3_sub( v2, v0, v0v2 ); - v3_cross( d, v0v2, p ); - - det = v3_dot( v0v1, p ); - - if( det < k_cullEpsilon ) return -INFINITY; - - inv = 1.f / det; - - v3_sub( o, v0, tv ); - *u = v3_dot( tv, p ) * inv; - - if( *u < 0.f || *u > 1.f ) return -INFINITY; - - v3_cross( tv, v0v1, qv ); - *v = v3_dot( d, qv ) * inv; - - if( *v < 0.f || *u + *v > 1.f ) return -INFINITY; - - return v3_dot( v0v2, qv ) * inv; -}