X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fgeom.cc;h=0a82566b756e8acbcd8356c2739bfa5692fe0ec5;hp=890d9754bbc5677028ab2c426ce00eeaf58eea19;hb=ad052fc67fe4e76d2f4a01b2381a738da1708cdb;hpb=215f16e2f26cc2acc79255bab06f13452ec06ae5 diff --git a/src/geom.cc b/src/geom.cc index 890d975..0a82566 100644 --- a/src/geom.cc +++ b/src/geom.cc @@ -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, 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) { @@ -531,6 +543,35 @@ bool calc_bounding_aabox(AABox *box, const Vec3 *v, int num, const Mat4 &xform) 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;