SceneNode bounds calculation
[laserbrain_demo] / src / geom.cc
index 890d975..0a82566 100644 (file)
@@ -188,11 +188,23 @@ Box::Box()
 {
 }
 
 {
 }
 
+Box::Box(const AABox &aabox, const Mat4 &xform)
+       : xform(xform)
+{
+       min = aabox.min;
+       max = aabox.max;
+}
+
 Box::Box(const Vec3 &min, const Vec3 &max)
        : AABox(min, max)
 {
 }
 
 Box::Box(const Vec3 &min, const Vec3 &max)
        : AABox(min, max)
 {
 }
 
+Box::Box(const Vec3 &min, const Vec3 &max, const Mat4 &xform)
+       : AABox(min, max), xform(xform)
+{
+}
+
 // XXX all this shit is completely untested
 Box::Box(const Vec3 &pos, const Vec3 &vi, const Vec3 &vj, const Vec3 &vk)
 {
 // XXX all this shit is completely untested
 Box::Box(const Vec3 &pos, const Vec3 &vi, const Vec3 &vj, const Vec3 &vk)
 {
@@ -531,6 +543,35 @@ bool calc_bounding_aabox(AABox *box, const Vec3 *v, int num, const Mat4 &xform)
        return true;
 }
 
        return true;
 }
 
+bool calc_bounding_box(Box *box, const GeomObject *obj)
+{
+       switch(obj->type) {
+       case GOBJ_BOX:
+               *box = *(Box*)obj;
+               break;
+
+       case GOBJ_AABOX:
+               box->min = BOX(obj)->min;
+               box->max = BOX(obj)->max;
+               box->xform = Mat4::identity;
+               break;
+
+       case GOBJ_SPHERE:
+               {
+                       float r = SPHERE(obj)->radius;
+                       box->min = SPHERE(obj)->center - Vec3(r, r, r);
+                       box->max = SPHERE(obj)->center + Vec3(r, r, r);
+                       box->xform = Mat4::identity;
+               }
+               break;
+
+       case GOBJ_PLANE:
+       default:
+               return false;
+       }
+       return true;
+}
+
 bool intersect_sphere_sphere(Disc *result, const Sphere &a, const Sphere &b)
 {
        Vec3 dir = b.center - a.center;
 bool intersect_sphere_sphere(Disc *result, const Sphere &a, const Sphere &b)
 {
        Vec3 dir = b.center - a.center;