Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

physics/Cone

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2003 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: Cone 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.4 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _PHYSICS_CONE_
00026 #define _PHYSICS_CONE_
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 Cone : virtual public ConvexShape
00038 {
00039 public:
00040   Cone();
00041   explicit Cone(Real height, Real radius=1.0);
00042   Cone(const Cone& c);
00043   virtual ~Cone();
00044   
00045   virtual String className() const { return String("Cone"); }
00046   
00047   Real height() const { return _height; }
00048   Real radius() const { return _radius; }
00049   
00050   // Shape
00051   virtual base::Object& clone() const { return *NewNamedObj(className()) Cone(*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   // ConvexShape
00071   virtual gfx::Point3 support(const gfx::Vector3& v) const
00072     { throw std::runtime_error(Exception("not implemented")); }
00073 
00074   // Collidable
00075   virtual ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00076 
00077   // Visual
00078   virtual bool visualTypeSupported(VisualType type) const { return (type==OSGVisual); }
00079   virtual osg::Node* createOSGVisual(Attributes visualAttributes=0) const;
00080 
00081   virtual void serialize(base::Serializer& s);
00082   
00083   // Externalizable
00084   virtual bool formatSupported(String format, Real version = 1.0, ExternalizationType type = IO) const;
00085   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00086   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0) const
00087     { Externalizable::externalize(e,format,version); }
00088 
00089 protected:
00090   osg::Node* createOSGCone(Visual::Attributes visualAttributes,
00091                                Int slices, Int stacks) const;
00092 
00093 private:
00094   Real _height;
00095   Real _radius;
00096 
00097   mutable bool massPropertiesCached;
00098   mutable Real density;
00099   mutable MassProperties massProperties;
00100 
00101   mutable Visual::Attributes attributes;
00102   mutable ref_ptr<osg::Node> node;
00103 
00104   mutable ref<CollisionModel> collisionModel;
00105   mutable CollisionModel::CollisionModelType modelType;
00106 };
00107 
00108 
00109 } // physics
00110 
00111 #endif

Generated on Thu Jul 29 15:56:22 2004 for OpenSim by doxygen 1.3.6