| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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
    00079   inline const csMatrix3 &GetMatrix () const
    00080   { return mMat; }
    00081
    00085   inline csMatrix3 &GetMatrix ()
    00086   { return mMat; }
    00087
    00088
    00092   float Diameter ();
    00093
    00097   float Volume ();
    00098
    00104   void FindOBB (const csVector3 *vertex_table, int num, float eps = 0.0);
    00105
    00111   void FindOBBAccurate (const csVector3 *vertex_table, int num);
    00112 };
    00113
    00117 class CS_CRYSTALSPACE_EXPORT csOBBFrozen
    00118 {
    00119 private:
    00120   csVector3 corners[8];
    00121
    00122 public:
    00126   inline void Copy (const csOBB& obb)
    00127   {
    00128     for (int i = 0 ; i < 8 ; i++)
    00129     {
    00130       corners[i] = obb.GetCorner (i);
    00131     }
    00132   }
    00133
    00137   void Copy (const csOBB& obb, const csReversibleTransform& trans);
    00138
    00142   csOBBFrozen ()
    00143   {
    00144   }
    00145
    00149   csOBBFrozen (const csOBB& obb)
    00150   {
    00151     Copy (obb);
    00152   }
    00153
    00160   csOBBFrozen (const csOBB& obb, const csReversibleTransform& trans)
    00161   {
    00162     Copy (obb, trans);
    00163   }
    00164
    00168   inline const csVector3& GetCorner (int corner) const
    00169   {
    00170     CS_ASSERT (corner >= 0 && corner < 8);
    00171     return corners[corner];
    00172   }
    00173
    00178   bool ProjectOBB (float fov, float sx, float sy, csBox2& sbox,
    00179         float& min_z, float& max_z);
    00180 };
    00181
    00184 #endif // __CS_OBB_H__
    00185