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_TORUS_
00026 #define _PHYSICS_TORUS_
00027
00028 #include <base/base>
00029 #include <physics/ComplexShape>
00030 #include <base/Dimension3>
00031
00032
00033
00034
00035 namespace physics {
00036
00037
00038 class Torus : virtual public ComplexShape
00039 {
00040 public:
00041 explicit Torus(Real innerRadius=0.5, Real outerRadius=1.0);
00042 Torus(const Torus& t);
00043 virtual ~Torus();
00044
00045 virtual String className() const { return String("Torus"); }
00046
00047 Real innerRadius() const { return _innerRadius; }
00048 Real outerRadius() const { return _outerRadius; }
00049
00050
00051 virtual base::Object& clone() const { return *NewNamedObj(className()) Torus(*this); }
00052 virtual BoundingBox getBoundingBox() const
00053 {
00054 Real minor = (_outerRadius-_innerRadius)/2.0;
00055 return BoundingBox(-gfx::Point3(_outerRadius,minor,_outerRadius),gfx::Point3(_outerRadius,minor,_outerRadius));
00056 }
00057 virtual BoundingSphere getBoundingSphere() const { return BoundingSphere(gfx::Point3(),_outerRadius); }
00058
00059 virtual const MassProperties& getMassProperties(ref<const Material> material) const;
00060
00061 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const;
00062 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const;
00063 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const;
00064 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const;
00065 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const;
00066
00067
00068 virtual ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00069
00070
00071 virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00072 virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00073
00074 virtual void serialize(base::Serializer& s);
00075
00076 protected:
00077 osg::Node* createOSGTorus(Visual::Attributes visualAttributes, Int sides, Int rings) const;
00078
00079
00080 private:
00081 Real _innerRadius;
00082 Real _outerRadius;
00083
00084 mutable bool massPropertiesCached;
00085 mutable Real density;
00086 mutable MassProperties massProperties;
00087
00088 mutable Visual::Attributes attributes;
00089 mutable ref_ptr<osg::Node> node;
00090
00091 mutable ref<CollisionModel> collisionModel;
00092 mutable CollisionModel::CollisionModelType modelType;
00093 };
00094
00095
00096 }
00097
00098 #endif