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_CYLINDER_
00026 #define _PHYSICS_CYLINDER_
00027
00028 #include <physics/physics>
00029 #include <physics/ConvexShape>
00030 #include <base/Dimension3>
00031 #include <base/Point3>
00032
00033
00034 namespace physics {
00035
00036
00037 class Cylinder : virtual public ConvexShape
00038 {
00039 public:
00040 Cylinder();
00041 explicit Cylinder(Real height, Real radius=1.0);
00042 Cylinder(const Cylinder& c);
00043 virtual ~Cylinder();
00044
00045 virtual String className() const { return String("Cylinder"); }
00046
00047 Real height() const { return _height; }
00048 Real radius() const { return _radius; }
00049
00050
00051 virtual base::Object& clone() const { return *NewNamedObj(className()) Cylinder(*this); }
00052
00053 virtual BoundingBox getBoundingBox() const {
00054 return BoundingBox(gfx::Point3(-_radius,-_radius,-_height/2.0),
00055 gfx::Point3(_radius,_radius,_height/2.0));
00056 }
00057
00058 virtual BoundingSphere getBoundingSphere() const
00059 { return BoundingSphere(gfx::Point3(),Math::maximum(_radius,_height/2.0)); }
00060
00061 virtual const MassProperties& getMassProperties(ref<const Material> material) const;
00062
00063 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const;
00064 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const;
00065 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const;
00066 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const;
00067 virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const;
00068
00069
00070 virtual gfx::Point3 support(const gfx::Vector3& v) const
00071 { throw std::runtime_error(Exception("not implemented")); }
00072
00073
00074 virtual ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00075
00076
00077 virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00078 virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00079
00080 virtual void serialize(base::Serializer& s);
00081
00082
00083 virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const;
00084 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00085 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0) const
00086 { Externalizable::externalize(e,format,version); }
00087
00088 protected:
00089 osg::Node* createOSGCylinder(Visual::Attributes visualAttributes,
00090 Int slices, Int stacks) const;
00091
00092 private:
00093 Real _height;
00094 Real _radius;
00095
00096 mutable bool massPropertiesCached;
00097 mutable Real density;
00098 mutable MassProperties massProperties;
00099
00100 mutable Visual::Attributes attributes;
00101 mutable ref_ptr<osg::Node> node;
00102
00103 mutable ref<CollisionModel> collisionModel;
00104 mutable CollisionModel::CollisionModelType modelType;
00105 };
00106
00107
00108 }
00109
00110 #endif