X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_m.h;h=090c4873ed723ad90244e8786842d047fa808a32;hb=a4784e4980beaf0dda620572fa1b2b6e4706cb11;hp=8b354d697f442b03d4c943aac878c11b7829ef36;hpb=51a168e586d5cb911b95dc9e9037421452b4cb8c;p=vg.git diff --git a/vg_m.h b/vg_m.h index 8b354d6..090c487 100644 --- a/vg_m.h +++ b/vg_m.h @@ -710,6 +710,16 @@ static inline void m2x2_create_rotation( m2x2f a, f32 theta ) a[1][1] = c; } +static inline void m2x2_mulv( m2x2f m, v2f v, v2f d ) +{ + v2f res; + + res[0] = m[0][0]*v[0] + m[1][0]*v[1]; + res[1] = m[0][1]*v[0] + m[1][1]*v[1]; + + v2_copy( res, d ); +} + /* * ----------------------------------------------------------------------------- * Section 4.b 3x3 matrices @@ -1194,8 +1204,7 @@ static void m4x3_decompose( m4x3f m, v3f co, v4f q, v3f s ) m3x3_q( rot, q ); } -static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point ) -{ +static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point ){ v3f v; m4x3_mulv( m, point, v ); @@ -1203,26 +1212,19 @@ static void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point ) v3_maxv( box[1], v, box[1] ); } -static void m4x3_transform_aabb( m4x3f m, boxf box ) -{ +static void m4x3_expand_aabb_aabb( m4x3f m, boxf boxa, boxf boxb ){ v3f a; v3f b; - - v3_copy( box[0], a ); - v3_copy( box[1], b ); - v3_fill( box[0], INFINITY ); - v3_fill( box[1], -INFINITY ); - - m4x3_expand_aabb_point( m, box, (v3f){ a[0], a[1], a[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ a[0], b[1], a[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], a[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ b[0], a[1], a[2] } ); - - m4x3_expand_aabb_point( m, box, (v3f){ a[0], a[1], b[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ a[0], b[1], b[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], b[2] } ); - m4x3_expand_aabb_point( m, box, (v3f){ b[0], a[1], b[2] } ); + v3_copy( boxb[0], a ); + v3_copy( boxb[1], b ); + m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], a[1], a[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], b[1], a[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], b[1], a[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], a[1], a[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], a[1], b[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ a[0], b[1], b[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], b[1], b[2] } ); + m4x3_expand_aabb_point( m, boxa, (v3f){ b[0], a[1], b[2] } ); } - static inline void m4x3_lookat( m4x3f m, v3f pos, v3f target, v3f up ) { v3f dir; @@ -1457,8 +1459,7 @@ static int box_within( boxf greater, boxf lesser ) return 0; } -static inline void box_init_inf( boxf box ) -{ +static inline void box_init_inf( boxf box ){ v3_fill( box[0], INFINITY ); v3_fill( box[1], -INFINITY ); } @@ -1545,7 +1546,7 @@ int plane_intersect2( v4f a, v4f b, v3f p, v3f n ) static int plane_segment( v4f plane, v3f a, v3f b, v3f co ) { f32 d0 = v3_dot( a, plane ) - plane[3], - d1 = v3_dot( b, plane ) - plane[3]; + d1 = v3_dot( b, plane ) - plane[3]; if( d0*d1 < 0.0f ) { @@ -1567,6 +1568,17 @@ static inline f64 plane_polarity( f64 p[4], f64 a[3] ) ; } +static f32 ray_plane( v4f plane, v3f co, v3f dir ){ + f32 d = v3_dot( plane, dir ); + if( fabsf(d) > 1e-6f ){ + v3f v0; + v3_muls( plane, plane[3], v0 ); + v3_sub( v0, co, v0 ); + return v3_dot( v0, plane ) / d; + } + else return INFINITY; +} + /* * ----------------------------------------------------------------------------- * Section 5.c Closest point functions