commit 51bcb8123eaec7034a99c74113ac800a264bcfa8
parent 5f8da39e52c2123926e38a2df10f3fb5814b0701
Author: Michael Savage <mikejsavage@gmail.com>
Date: Fri, 10 Nov 2017 21:52:47 +0200
Small cleanup
Diffstat:
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/heightmap.cc b/heightmap.cc
@@ -248,29 +248,33 @@ bool ray_vs_quadtree( const QuadTree & qt, const Ray3 & ray, float * t, v3 * xno
v3u32 maxs = v3u32( qt.heightmap.w, qt.heightmap.h, qt.nodes[ 0 ].max_z );
MinMaxu32 aabb( mins, maxs );
- return ray_vs_quadtree_node( qt, 0, aabb, ray, t, xnormal, max_dist );
-}
-
-bool segment_vs_quadtree( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ) {
+ float dont_care_t;
v3 dont_care_normal;
+ if( t == NULL )
+ t = &dont_care_t;
if( xnormal == NULL )
xnormal = &dont_care_normal;
+ return ray_vs_quadtree_node( qt, 0, aabb, ray, t, xnormal, max_dist );
+}
+
+bool segment_vs_quadtree( const QuadTree & qt, const v3 & start, const v3 & end, float * t, v3 * xnormal ) {
if( t != NULL )
*t = 1.0f;
if( start == end )
return false;
- float nt;
- float l = length( end - start );
Ray3 ray( start, normalize( end - start ) );
- bool ok = ray_vs_quadtree( qt, ray, &nt, xnormal, l );
- if( !ok || nt >= l )
+ float l = length( end - start );
+
+ float absolute_t;
+ bool ok = ray_vs_quadtree( qt, ray, &absolute_t, xnormal, l );
+ if( !ok || absolute_t >= l )
return false;
if( t != NULL )
- *t = nt / l;
+ *t = absolute_t / l;
return true;
}