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

physics/OBBCollisionDetector

Go to the documentation of this file.
00001 /****************************************************************************
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: OBBCollisionDetector 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _PHYSICS_OBBCOLLISIONDETECTOR_
00026 #define _PHYSICS_OBBCOLLISIONDETECTOR_
00027 
00028 #include <physics/physics>
00029 #include <base/array>
00030 #include <physics/CollisionDetector>
00031 #include <physics/OBBCollisionModel>
00032 #include <base/Vector3>
00033 #include <base/Matrix3>
00034 #include <gfx/Triangle3>
00035 #include <vector>
00036 
00037 
00038 namespace physics {
00039 
00040 
00041 class OBBCollisionDetector : public CollisionDetector
00042 {
00043 public:
00044   OBBCollisionDetector() 
00045     : collisionDetectionEnabled(true) {}
00046 
00047   virtual String className() const { return String("OBBCollisionDetector"); }
00048 
00049   virtual CollisionModel::CollisionModelType getType() const
00050     { return CollisionModel::OBBModel; }
00051 
00052 
00053   virtual bool collision(ref<const Solid> solid1, ref<const Solid> solid2, CollisionQueryType queryType);
00054   
00055   
00056   virtual bool collisionEnable(bool enabled) 
00057     {
00058       bool oldEnable = collisionDetectionEnabled;
00059       collisionDetectionEnabled=enabled; 
00060       return oldEnable;
00061     }
00062   
00063 
00064   Int numBoxTests;
00065   Int numTriTests;
00066   
00067 protected:
00068   bool collisionDetectionEnabled;
00069   
00070   base::Vector3 i1,i2,i3;
00071   base::Matrix3 Bf;
00072   base::Matrix3 mR;
00073   base::Vector3 mT;
00074   Real ms;
00075   
00076   std::vector<std::pair<gfx::Triangle3,gfx::Triangle3> > contacts;
00077   
00078   bool firstContact;
00079   
00080   void Collide(const base::Matrix3& R1, const base::Vector3& T1, 
00081                ref<const OBBCollisionModel> model1,
00082                const base::Matrix3& R2, const base::Vector3& T2, 
00083                ref<const OBBCollisionModel> model2,
00084                CollisionQueryType queryType);
00085   void Collide(const base::Matrix3& R1, const base::Vector3& T1, Real s1, 
00086                ref<const OBBCollisionModel> model1,
00087                const base::Matrix3& R2, const base::Vector3& T2, Real s2, 
00088                ref<const OBBCollisionModel> model2,
00089                CollisionQueryType queryType);
00090   
00091   void collideRecursive(const OBBCollisionModel::OBB& b1, 
00092                         const OBBCollisionModel::OBB& b2,
00093                         const base::Matrix3& R, const base::Vector3& T, double s);
00094   
00095   void triContact(const OBBCollisionModel::OBB& b1, const OBBCollisionModel::OBB& b2);
00096   bool triContact(const base::Vector3& P1, const base::Vector3& P2, const gfx::Vector3& P3,
00097                   const base::Point3& Q1, const base::Point3& Q2, const gfx::Point3& Q3);
00098   bool project6(const Vector3& ax, 
00099                 const Vector3& p1, const Vector3& p2, const Vector3& p3,
00100                 const Vector3& q1, const Vector3& q2, const Vector3& q3) const;
00101   Int OBBDisjoint(const base::Matrix3& B, const base::Vector3& T,
00102                   const base::Vector3& a, const base::Vector3& b);
00103 
00104 
00105   
00106   class OBBCollisionState : public CollisionState
00107   {
00108   public:
00109     OBBCollisionState(ref<const Solid> solid1, ref<const Solid> solid2)
00110       : CollisionState(solid1, solid2) {}
00111     virtual ~OBBCollisionState() {}
00112 
00113     virtual String className() const { return String("OBBCollisionState"); }
00114     
00115   };
00116   
00117   virtual ref<CollisionState> newCollisionState(ref<const Solid> solid1, ref<const Solid> solid2) const
00118     { return ref<CollisionState>(NewNamedObj("OBBSollisionState") OBBCollisionState(solid1,solid2)); }
00119 
00120   
00121   // temporaries
00122   base::Vector3 p1, p2, p3, q1, q2, q3, e1, e2, e3, f1, f2, f3,
00123     g1, g2, g3, h1, h2, h3, n1, m1, z,
00124     ef11, ef12, ef13, ef21, ef22, ef23, ef31, ef32, ef33;
00125   
00126 };
00127 
00128 
00129 } // physics
00130 
00131 #endif

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