goat3dgfx
diff src/geom.cc @ 23:0ac499409edd
added misisng header file in goat3dgfx.h
added contains() function in geom
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 25 Feb 2014 23:47:48 +0200 |
parents | 7d6b667821cf |
children |
line diff
1.1 --- a/src/geom.cc Sat Dec 28 06:48:23 2013 +0200 1.2 +++ b/src/geom.cc Tue Feb 25 23:47:48 2014 +0200 1.3 @@ -49,6 +49,12 @@ 1.4 error_log("Sphere::intersection undefined\n"); 1.5 } 1.6 1.7 +bool Sphere::contains(const Vector3 &pt) const 1.8 +{ 1.9 + float dist_sq = (pt - center).length_sq(); 1.10 + return dist_sq <= radius * radius; 1.11 +} 1.12 + 1.13 bool Sphere::intersect(const Ray &ray, HitPoint *hit) const 1.14 { 1.15 float a = dot_product(ray.dir, ray.dir); 1.16 @@ -136,6 +142,13 @@ 1.17 } 1.18 } 1.19 1.20 +bool AABox::contains(const Vector3 &pt) const 1.21 +{ 1.22 + return pt.x >= min.x && pt.x <= max.x && 1.23 + pt.y >= min.y && pt.y <= max.y && 1.24 + pt.z >= min.z && pt.z <= max.z; 1.25 +} 1.26 + 1.27 bool AABox::intersect(const Ray &ray, HitPoint *hit) const 1.28 { 1.29 Vector3 param[2] = {min, max}; 1.30 @@ -235,6 +248,11 @@ 1.31 error_log("Plane::set_intersection undefined\n"); 1.32 } 1.33 1.34 +bool Plane::contains(const Vector3 &pt) const 1.35 +{ 1.36 + return false; // TODO: maybe define containment as half-space containment? 1.37 +} 1.38 + 1.39 bool Plane::intersect(const Ray &ray, HitPoint *hit) const 1.40 { 1.41 float ndotdir = dot_product(normal, ray.dir);