CrystalSpace

Public API Reference

csgeom/obb.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2002 by Jorrit Tyberghein
00003     Copyright (C) 2002 by Daniel Duhprey
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_OBB_H__
00021 #define __CS_OBB_H__
00022 
00030 #include "csextern.h"
00031 
00032 #include "csgeom/box.h"
00033 #include "csgeom/matrix3.h"
00034 
00035 class csVector3;
00036 class csReversibleTransform;
00037 
00042 class CS_CRYSTALSPACE_EXPORT csOBB : public csBox3
00043 {
00044 private:
00045   csMatrix3 mMat;
00046 
00047 public:
00051   csOBB () {}
00052 
00056   csOBB (const csOBB &b) : csBox3 (b), mMat (b.mMat) { }
00057 
00061   csOBB (const csBox3 &b) : csBox3 (b) { }
00062 
00070   csOBB (const csVector3 &dir1, const csVector3 &dir2,
00071         const csVector3 &dir3);
00072 
00073   void AddBoundingVertex (const csVector3 &v);
00074   csVector3 GetCorner (int corner) const; 
00075   inline const csMatrix3 &GetMatrix () const { return mMat; }
00076 
00080   float Diameter ();
00081 
00085   float Volume ();
00086 
00092   void FindOBB (const csVector3 *vertex_table, int num, float eps = 0.0);
00093 
00099   void FindOBBAccurate (const csVector3 *vertex_table, int num);
00100 };
00101 
00105 class CS_CRYSTALSPACE_EXPORT csOBBFrozen
00106 {
00107 private:
00108   csVector3 corners[8];
00109 
00110 public:
00114   inline void Copy (const csOBB& obb)
00115   {
00116     for (int i = 0 ; i < 8 ; i++)
00117     {
00118       corners[i] = obb.GetCorner (i);
00119     }
00120   }
00121 
00125   void Copy (const csOBB& obb, const csReversibleTransform& trans);
00126 
00130   csOBBFrozen ()
00131   {
00132   }
00133 
00137   csOBBFrozen (const csOBB& obb)
00138   {
00139     Copy (obb);
00140   }
00141 
00148   csOBBFrozen (const csOBB& obb, const csReversibleTransform& trans)
00149   {
00150     Copy (obb, trans);
00151   }
00152 
00156   inline const csVector3& GetCorner (int corner) const
00157   {
00158     CS_ASSERT (corner >= 0 && corner < 8);
00159     return corners[corner];
00160   }
00161 
00166   bool ProjectOBB (float fov, float sx, float sy, csBox2& sbox,
00167         float& min_z, float& max_z);
00168 };
00169 
00172 #endif // __CS_OBB_H__
00173 

Generated for Crystal Space by doxygen 1.4.6