Blender  V2.59
BOP_BBox.h
Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (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.
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 Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #ifndef BOP_BBOX_H
00034 #define BOP_BBOX_H
00035 
00036 #include "MT_Point3.h"
00037 #include "BOP_MathUtils.h"
00038 
00039 #define BOP_MAX(a, b) ((a > b) ? a : b)
00040 #define BOP_MIN(a, b) ((a < b) ? a : b)
00041 #define BOP_ABS(a) ((a < 0) ? -(a) : a)
00042 
00043 class BOP_BBox
00044 {
00045 public:
00046         MT_Scalar m_minX;
00047         MT_Scalar m_minY;
00048         MT_Scalar m_minZ;
00049         MT_Scalar m_maxX;
00050         MT_Scalar m_maxY;
00051         MT_Scalar m_maxZ;
00052         MT_Scalar m_centerX;
00053         MT_Scalar m_centerY;
00054         MT_Scalar m_centerZ;
00055         MT_Scalar m_extentX;
00056         MT_Scalar m_extentY;
00057         MT_Scalar m_extentZ;
00058         
00059 public:
00060         BOP_BBox();
00061         BOP_BBox(const MT_Point3& p1,const MT_Point3& p2,const MT_Point3& p3);
00062         inline void add(const MT_Point3& p)
00063         {
00064                 m_minX = BOP_MIN(m_minX,p[0]);
00065                 m_minY = BOP_MIN(m_minY,p[1]);
00066                 m_minZ = BOP_MIN(m_minZ,p[2]);
00067                 m_maxX = BOP_MAX(m_maxX,p[0]);
00068                 m_maxY = BOP_MAX(m_maxY,p[1]);
00069                 m_maxZ = BOP_MAX(m_maxZ,p[2]);
00070         };
00071 
00072         inline const MT_Scalar getCenterX() const {return m_centerX;};
00073         inline const MT_Scalar getCenterY() const {return m_centerY;};
00074         inline const MT_Scalar getCenterZ() const {return m_centerZ;};
00075 
00076         inline const MT_Scalar getExtentX() const {return m_extentX;};
00077         inline const MT_Scalar getExtentY() const {return m_extentY;};
00078         inline const MT_Scalar getExtentZ() const {return m_extentZ;};
00079         
00080         inline void compute() {
00081                 m_extentX = (m_maxX-m_minX)/2.0f;
00082                 m_extentY = (m_maxY-m_minY)/2.0f;
00083                 m_extentZ = (m_maxZ-m_minZ)/2.0f;
00084                 m_centerX = m_minX+m_extentX;
00085                 m_centerY = m_minY+m_extentY;
00086                 m_centerZ = m_minZ+m_extentZ;
00087         };
00088 
00089         inline const bool intersect(const BOP_BBox& b) const {
00090           return (!((BOP_comp(m_maxX,b.m_minX)<0) || (BOP_comp(b.m_maxX,m_minX)<0) ||
00091                     (BOP_comp(m_maxY,b.m_minY)<0) || (BOP_comp(b.m_maxY,m_minY)<0) ||
00092                     (BOP_comp(m_maxZ,b.m_minZ)<0) || (BOP_comp(b.m_maxZ,m_minZ)<0)));
00093         };
00094         
00095         
00096 };
00097 
00098 #endif