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

physics/Shape

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)1996 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: Shape 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.7 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
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   // distance computation methods
00067   
00068   /// return the shortest segment between this shape (in configuration t) and the point p (the returned segment will always end with p)
00069   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const Point3& p) const = 0;
00070 
00071   /// return the shortest segment between this shape (in configuration t) and the segment s
00072   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Segment3& s) const = 0;
00073 
00074   /// return the shortest segment between this shape (in configuration t) and the triangle t
00075   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Triangle3& tri) const = 0;
00076   
00077   /// return the shortest segment between this shape (in configuration t) and the quad q
00078   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t, const gfx::Quad3& q) const = 0;
00079   
00080   /// return the shortest segment between this shape (in configuration t1) and the shape s (in configuration t2)
00081   virtual gfx::Segment3 shortestSegmentBetween(const base::Transform& t1, ref<const Shape> s, const base::Transform& t2) const = 0;
00082    
00083    
00084   /// create a new concrete Shape (subclass) based on the next element that appears in the Input Externalizer stream
00085   ref<Shape> createShapeFromInput(base::Externalizer& e, String format = "", Real version = 1.0);
00086   
00087   /// deprecated.
00088   base::ref<CollisionModel> getCollisionModel(CollisionModel::CollisionModelType modelType) const;
00089 
00090 protected:
00091   Shape(const Shape& s) 
00092     : shapeHasAppearance(s.shapeHasAppearance) {}
00093 
00094   // create a visual of the shape's axes for debugging etc.
00095   static osg::Node* createOSGAxes(const base::Dimension3& dim);
00096 
00097   bool shapeHasAppearance;
00098 
00099   // convenience method to get a collision model from the triangles in a visual
00100   //  (if specific model for the shape is available)
00101   ref<CollisionModel> getCollisionModelFromVisual(CollisionModel::CollisionModelType modelType) const;
00102 
00103 };
00104 
00105 
00106 } // physics
00107 
00108 #endif

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