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_SHAPE_
00026 #define _PHYSICS_SHAPE_
00027 
00028 #include <physics/physics>
00029 #include <physics/CollisionModelProvider>
00030 #include <gfx/Visual>
00031 #include <base/Serializable>
00032 #include <base/Externalizable>
00033 
00034 #include <base/Serializer>
00035 #include <base/Transform>
00036 #include <gfx/Segment3>
00037 #include <gfx/Quad3>
00038 #include <physics/BoundingBox>
00039 #include <physics/BoundingSphere>
00040 #include <physics/MassProperties>
00041 
00042 
00043 namespace physics {
00044 
00045 class Material;
00046 
00047 
00048 class Shape : public CollisionModelProvider, 
00049               public gfx::Visual, public base::Serializable, public base::Externalizable,
00050               public base::ReferencedObject
00051 {
00052 public:
00053   Shape()
00054     : shapeHasAppearance(false) {}
00055   virtual ~Shape() {}
00056   virtual BoundingBox    getBoundingBox() const = 0;
00057   virtual BoundingSphere getBoundingSphere() const = 0;
00058   
00059   virtual bool isConvex() const = 0;
00060   virtual bool includesAppearance() const { return shapeHasAppearance; }
00061   virtual void setIncludesAppearance(bool appearanceIncluded) { shapeHasAppearance=appearanceIncluded; }
00062 
00063   virtual const MassProperties& getMassProperties(ref<const Material> material) const = 0;
00064 
00065   
00066   
00067   
00068 
00069   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const = 0;
00070 
00071 
00072   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const = 0;
00073 
00074 
00075   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const = 0;
00076   
00077 
00078   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const = 0;
00079   
00080 
00081   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const = 0;
00082    
00083    
00084 
00085   ref<Shape> createShapeFromInput(base::Externalizer& e, String format = "", Real version = 1.0);
00086   
00087 
00088   base::ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00089 
00090 protected:
00091   Shape(const Shape& s) 
00092     : shapeHasAppearance(s.shapeHasAppearance) {}
00093 
00094   
00095   static osg::Node* createOSGAxes(const base::Dimension3& dim);
00096 
00097   bool shapeHasAppearance;
00098 
00099   
00100   
00101   ref<CollisionModel> getCollisionModelFromVisual(CollisionModel::CollisionModelType modelType) const;
00102 
00103 };
00104 
00105 
00106 } 
00107 
00108 #endif