Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

vhdAxisAlignedBox.h

00001 00002 // Copyright : Sebastien Schertenleib 00003 // : VRLab-EPFL 00004 // 00005 // Email :Sebastien.Schertenleib@epfl.ch 00006 // 00007 // This source code is a part of the Game Programming Gems 5 Source Code 00008 // 00009 // Permission to copy, modify, reproduce or redistribute this source code is 00010 // granted provided the above copyright notice is retained in the resulting 00011 // source code. 00012 // 00013 // This file is provided 'as is' with no expressed or implied warranty. 00014 // The author accepts no liability if it causes any damage to your computer. 00015 // 00016 // Do expect bugs. 00017 // Please let me know of any bugs/mods/improvements. 00018 // and I will try to fix/incorporate them into this file. 00019 // Enjoy! 00020 // 00022 00023 00024 #ifndef VHDAXISALIGNEDBOX_H 00025 #define VHDAXISALIGNEDBOX_H 00026 00027 00028 #include "vhdVector3.h" 00029 00030 00031 00045 class vhdAxisAlignedBox 00046 { 00047 00048 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00049 // non-STATIC SECTION: 00050 // non-static field and method declarations specific to 00051 // the particular class being defined 00052 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00053 00054 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00055 // 00056 // protected fields 00057 // 00058 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00059 00060 protected: 00061 vhdVector3 _vecMinimum; 00062 vhdVector3 _vecMaximum; 00063 bool _bNull; 00064 00065 vhdVector3 _vecCorners[8]; 00066 00067 00068 00069 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00070 // 00071 // Constructor & Destructor 00072 // 00073 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00074 public: 00075 vhdAxisAlignedBox() 00076 { 00077 // Default to null box 00078 setExtents(-0.5, -0.5, -0.5,0.5, 0.5, 0.5 ); 00079 _bNull = true; 00080 } 00081 vhdAxisAlignedBox(float mx, float my, float mz,float Mx, float My, float Mz ) 00082 { 00083 setExtents( mx, my, mz, Mx, My, Mz ); 00084 } 00085 00086 00087 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00088 // 00089 // protected methods 00090 // 00091 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00092 00093 protected: 00094 00095 00098 void _updateCorners(void) 00099 { 00100 // The order of these items is, using right-handed co-ordinates: 00101 // Minimum Z face, starting with Min(all), then anticlockwise 00102 // around face (looking onto the face) 00103 // Maximum Z face, starting with Max(all), then anticlockwise 00104 // around face (looking onto the face) 00105 _vecCorners[0] = _vecMinimum; 00106 _vecCorners[1].x = _vecMinimum.x; _vecCorners[1].y = _vecMaximum.y; _vecCorners[1].z = _vecMinimum.z; 00107 _vecCorners[2].x = _vecMaximum.x; _vecCorners[2].y = _vecMaximum.y; _vecCorners[2].z = _vecMinimum.z; 00108 _vecCorners[3].x = _vecMaximum.x; _vecCorners[3].y = _vecMinimum.y; _vecCorners[3].z = _vecMinimum.z; 00109 00110 _vecCorners[4] = _vecMaximum; 00111 _vecCorners[5].x = _vecMinimum.x; _vecCorners[5].y = _vecMaximum.y; _vecCorners[5].z = _vecMaximum.z; 00112 _vecCorners[6].x = _vecMinimum.x; _vecCorners[6].y = _vecMinimum.y; _vecCorners[6].z = _vecMaximum.z; 00113 _vecCorners[7].x = _vecMaximum.x; _vecCorners[7].y = _vecMinimum.y; _vecCorners[7].z = _vecMaximum.z; 00114 } 00115 00116 00117 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00118 // 00119 // public methods 00120 // 00121 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00122 00123 public: 00124 00125 00131 inline vhdVector3 getMinimum(void) const 00132 { 00133 return _vecMinimum; 00134 } 00135 00142 inline vhdVector3 getMaximum(void) const 00143 { 00144 return _vecMaximum; 00145 } 00146 00147 00148 00159 inline void setExtents(float mx, float my, float mz,float Mx, float My, float Mz ) 00160 { 00161 _bNull = false; 00162 00163 _vecMinimum.x = mx; 00164 _vecMinimum.y = my; 00165 _vecMinimum.z = mz; 00166 00167 _vecMaximum.x = Mx; 00168 _vecMaximum.y = My; 00169 _vecMaximum.z = Mz; 00170 00171 _updateCorners(); 00172 } 00173 00174 00175 00176 friend std::ostream& operator<<( std::ostream& o, vhdAxisAlignedBox aab ) 00177 { 00178 o << "vhdAxisAlignedBox(min=" << aab._vecMinimum << ", max=" << aab._vecMaximum; 00179 o << ", corners="; 00180 for (int i = 0; i < 7; ++i) 00181 { 00182 o << aab._vecCorners[i] << ", "; 00183 } 00184 o << aab._vecCorners[7] << ")"; 00185 return o; 00186 } 00187 00188 }; 00189 00190 00191 00192 #endif

Generated on Sun Oct 3 16:32:22 2004 for vhdABTTree by doxygen 1.3.8