00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef _PHYSICS_BOX_
00026 #define _PHYSICS_BOX_
00027 
00028 #include <base/ref>
00029 
00030 #include <base/Dimension3>
00031 #include <base/Serializable>
00032 #include <gfx/Segment3>
00033 #include <gfx/Triangle3>
00034 #include <gfx/Quad3>
00035 
00036 #include <physics/physics>
00037 #include <physics/ConvexShape>
00038 
00039 #include <gfx/Visual>
00040 
00041 
00042 namespace physics {
00043 
00044 
00045 class Box : virtual public ConvexShape
00046 {
00047 public:
00048   Box(Real width=1.0, Real height=1.0, Real depth=1.0);
00049   Box(const Box& b);
00050   virtual ~Box();
00051 
00052   virtual String className() const { return String("Box"); }
00053   virtual base::Object& clone() const { return *NewNamedObj(className()) Box(*this); }
00054 
00055   const base::Dimension3& dimensions() const { return dim; }
00056 
00057   
00058   virtual BoundingBox    getBoundingBox() const { return BoundingBox(-dim/2.0,dim/2.0); }
00059   virtual BoundingSphere getBoundingSphere() const { return BoundingSphere(base::Point3(),Math::maximum(dim.x,dim.y,dim.z)/2.0); }
00060   virtual const MassProperties& getMassProperties(ref<const Material> material) const;
00061 
00062   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const;
00063   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const;
00064   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const;
00065   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const;
00066   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const;
00067 
00068   
00069   virtual base::Point3 support(const base::Vector3& v) const;
00070 
00071   
00072   virtual ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00073 
00074   
00075   virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00076   virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00077 
00078   virtual void serialize(base::Serializer& s);
00079   
00080   
00081   virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const;
00082   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00083   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0) const
00084     { Externalizable::externalize(e,format,version); }
00085   
00086 protected:
00087 
00088   array<gfx::Quad3> asQuads() const;
00089   
00090 private:
00091   base::Dimension3 dim;
00092   
00093   mutable bool massPropertiesCached;
00094   mutable Real density;
00095   mutable MassProperties massProperties;
00096 
00097   mutable Visual::Attributes attributes;
00098   mutable ref_ptr<osg::Node> node;
00099 
00100   mutable ref<CollisionModel> collisionModel;
00101   mutable CollisionModel::CollisionModelType modelType;
00102 };
00103 
00104 
00105 } 
00106 
00107 #endif