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_SPHERE_
00026 #define _PHYSICS_SPHERE_
00027
00028 #include <base/base>
00029 #include <physics/ConvexShape>
00030 #include <base/Dimension3>
00031
00032
00033 namespace physics {
00034
00035
00036 class Sphere : virtual public ConvexShape
00037 {
00038 public:
00039 Sphere();
00040 explicit Sphere(Real radius);
00041 Sphere(const Sphere& s);
00042 virtual ~Sphere();
00043
00044 virtual String className() const { return String("Sphere"); }
00045
00046 Real radius() const { return _radius; }
00047
00048
00049 virtual base::Object& clone() const { return *NewNamedObj(className()) Sphere(*this); }
00050 virtual BoundingBox getBoundingBox() const { return BoundingBox(-gfx::Point3(_radius,_radius,_radius), gfx::Point3(_radius,_radius,_radius)); }
00051 virtual BoundingSphere getBoundingSphere() const { return BoundingSphere(gfx::Point3(),_radius); }
00052 virtual const MassProperties& getMassProperties(ref<const Material> material) const;
00053
00054 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const;
00055 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const;
00056 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const;
00057 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const;
00058 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const;
00059
00060
00061 virtual base::Point3 support(const base::Vector3& v) const;
00062
00063
00064 virtual ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00065
00066
00067 virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00068 virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00069
00070 virtual void serialize(base::Serializer& s);
00071
00072
00073 virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const;
00074 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00075 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0) const
00076 { Externalizable::externalize(e,format,version); }
00077
00078 protected:
00079 osg::Node* createOSGSphere(Visual::Attributes visualAttributes, Int slices) const;
00080
00081 private:
00082 Real _radius;
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