Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00043 #ifndef _orxAABOX_H_
00044 #define _orxAABOX_H_
00045
00046 #include "orxInclude.h"
00047
00048 #include "math/orxVector.h"
00049
00050
00053 typedef struct __orxAABOX_t
00054 {
00055 orxVECTOR vTL;
00056 orxVECTOR vBR;
00058 } orxAABOX;
00059
00060
00061
00062
00063
00068 static orxINLINE orxAABOX * orxAABox_Reorder(orxAABOX *_pstBox)
00069 {
00070
00071 orxASSERT(_pstBox != orxNULL);
00072
00073
00074
00075
00076 if(_pstBox->vTL.fX > _pstBox->vBR.fX)
00077 {
00078 orxFLOAT fTemp;
00079
00080
00081 fTemp = _pstBox->vTL.fX;
00082 _pstBox->vTL.fX = _pstBox->vBR.fX;
00083 _pstBox->vBR.fX = fTemp;
00084 }
00085
00086
00087 if(_pstBox->vTL.fY > _pstBox->vBR.fY)
00088 {
00089 orxFLOAT fTemp;
00090
00091
00092 fTemp = _pstBox->vTL.fY;
00093 _pstBox->vTL.fY = _pstBox->vBR.fY;
00094 _pstBox->vBR.fY = fTemp;
00095 }
00096
00097
00098 if(_pstBox->vTL.fZ > _pstBox->vBR.fZ)
00099 {
00100 orxFLOAT fTemp;
00101
00102
00103 fTemp = _pstBox->vTL.fZ;
00104 _pstBox->vTL.fZ = _pstBox->vBR.fZ;
00105 _pstBox->vBR.fZ = fTemp;
00106 }
00107
00108
00109 return _pstBox;
00110 }
00111
00118 static orxINLINE orxAABOX * orxAABox_Set(orxAABOX *_pstRes, const orxVECTOR *_pvTL, const orxVECTOR *_pvBR)
00119 {
00120
00121 orxASSERT(_pstRes != orxNULL);
00122 orxASSERT(_pvTL != orxNULL);
00123 orxASSERT(_pvBR != orxNULL);
00124
00125
00126 orxVector_Copy(&(_pstRes->vTL), _pvTL);
00127 orxVector_Copy(&(_pstRes->vBR), _pvBR);
00128
00129
00130 orxAABox_Reorder(_pstRes);
00131
00132
00133 return _pstRes;
00134 }
00135
00141 static orxINLINE orxBOOL orxAABox_IsInside(const orxAABOX *_pstBox, const orxVECTOR *_pvPosition)
00142 {
00143 register orxBOOL bResult = orxFALSE;
00144
00145
00146 orxASSERT(_pstBox != orxNULL);
00147 orxASSERT(_pvPosition != orxNULL);
00148
00149
00150 if((_pvPosition->fZ >= _pstBox->vTL.fZ)
00151 && (_pvPosition->fZ <= _pstBox->vBR.fZ))
00152 {
00153
00154 if((_pvPosition->fX >= _pstBox->vTL.fX)
00155 && (_pvPosition->fX <= _pstBox->vBR.fX))
00156 {
00157
00158 if((_pvPosition->fY >= _pstBox->vTL.fY)
00159 && (_pvPosition->fY <= _pstBox->vBR.fY))
00160 {
00161
00162 bResult = orxTRUE;
00163 }
00164 }
00165 }
00166
00167
00168 return bResult;
00169 }
00170
00176 static orxINLINE orxBOOL orxAABox_TestIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
00177 {
00178 register orxBOOL bResult = orxFALSE;
00179
00180
00181 orxASSERT(_pstBox1 != orxNULL);
00182 orxASSERT(_pstBox2 != orxNULL);
00183
00184
00185 if((_pstBox2->vBR.fZ >= _pstBox1->vTL.fZ)
00186 && (_pstBox2->vTL.fZ <= _pstBox1->vBR.fZ))
00187 {
00188
00189 if((_pstBox2->vBR.fX >= _pstBox1->vTL.fX)
00190 && (_pstBox2->vTL.fX <= _pstBox1->vBR.fX))
00191 {
00192
00193 if((_pstBox2->vBR.fY >= _pstBox1->vTL.fY)
00194 && (_pstBox2->vTL.fY <= _pstBox1->vBR.fY))
00195 {
00196
00197 bResult = orxTRUE;
00198 }
00199 }
00200 }
00201
00202
00203 return bResult;
00204 }
00205
00211 static orxINLINE orxBOOL orxAABox_Test2DIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
00212 {
00213 register orxBOOL bResult = orxFALSE;
00214
00215
00216 orxASSERT(_pstBox1 != orxNULL);
00217 orxASSERT(_pstBox2 != orxNULL);
00218
00219
00220 if((_pstBox2->vBR.fX >= _pstBox1->vTL.fX)
00221 && (_pstBox2->vTL.fX <= _pstBox1->vBR.fX))
00222 {
00223
00224 if((_pstBox2->vBR.fY >= _pstBox1->vTL.fY)
00225 && (_pstBox2->vTL.fY <= _pstBox1->vBR.fY))
00226 {
00227
00228 bResult = orxTRUE;
00229 }
00230 }
00231
00232
00233 return bResult;
00234 }
00235
00241 static orxINLINE orxAABOX * orxAABox_Copy(orxAABOX *_pstDst, const orxAABOX *_pstSrc)
00242 {
00243
00244 orxASSERT(_pstDst != orxNULL);
00245 orxASSERT(_pstSrc != orxNULL);
00246
00247
00248 orxMemory_Copy(_pstDst, _pstSrc, sizeof(orxAABOX));
00249
00250
00251 return _pstDst;
00252 }
00253
00260 static orxINLINE orxAABOX * orxAABox_Move(orxAABOX *_pstRes, const orxAABOX *_pstOp, const orxVECTOR *_pvMove)
00261 {
00262
00263 orxASSERT(_pstRes != orxNULL);
00264 orxASSERT(_pstOp != orxNULL);
00265 orxASSERT(_pvMove != orxNULL);
00266
00267
00268 orxVector_Add(&(_pstRes->vTL), &(_pstOp->vTL), _pvMove);
00269 orxVector_Add(&(_pstRes->vBR), &(_pstOp->vBR), _pvMove);
00270
00271
00272 return _pstRes;
00273 }
00274
00280 static orxINLINE orxVECTOR * orxAABox_GetCenter(const orxAABOX *_pstOp, orxVECTOR *_pvRes)
00281 {
00282
00283 orxASSERT(_pstOp != orxNULL);
00284 orxASSERT(_pvRes != orxNULL);
00285
00286
00287 orxVector_Add(_pvRes, &(_pstOp->vTL), &(_pstOp->vBR));
00288 orxVector_Mulf(_pvRes, _pvRes, orx2F(0.5f));
00289
00290
00291 return _pvRes;
00292 }
00293
00294 #endif
00295