orx  stable
Portable Game Engine
orxAABox.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2017 Orx-Project
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  *
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  * misrepresented as being the original software.
20  *
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  */
24 
43 #ifndef _orxAABOX_H_
44 #define _orxAABOX_H_
45 
46 #include "orxInclude.h"
47 
48 #include "math/orxVector.h"
49 
50 
53 typedef struct __orxAABOX_t
54 {
58 } orxAABOX;
59 
60 
61 /* *** AABox inlined functions *** */
62 
63 
68 static orxINLINE orxAABOX * orxAABox_Reorder(orxAABOX *_pstBox)
69 {
70  /* Checks */
71  orxASSERT(_pstBox != orxNULL);
72 
73  /* Reorders coordinates so as to have upper left & bottom right box corners */
74 
75  /* X coord */
76  if(_pstBox->vTL.fX > _pstBox->vBR.fX)
77  {
78  orxFLOAT fTemp;
79 
80  /* Swaps */
81  fTemp = _pstBox->vTL.fX;
82  _pstBox->vTL.fX = _pstBox->vBR.fX;
83  _pstBox->vBR.fX = fTemp;
84  }
85 
86  /* Y coord */
87  if(_pstBox->vTL.fY > _pstBox->vBR.fY)
88  {
89  orxFLOAT fTemp;
90 
91  /* Swaps */
92  fTemp = _pstBox->vTL.fY;
93  _pstBox->vTL.fY = _pstBox->vBR.fY;
94  _pstBox->vBR.fY = fTemp;
95  }
96 
97  /* Z coord */
98  if(_pstBox->vTL.fZ > _pstBox->vBR.fZ)
99  {
100  orxFLOAT fTemp;
101 
102  /* Swaps */
103  fTemp = _pstBox->vTL.fZ;
104  _pstBox->vTL.fZ = _pstBox->vBR.fZ;
105  _pstBox->vBR.fZ = fTemp;
106  }
107 
108  /* Done! */
109  return _pstBox;
110 }
111 
118 static orxINLINE orxAABOX * orxAABox_Set(orxAABOX *_pstRes, const orxVECTOR *_pvTL, const orxVECTOR *_pvBR)
119 {
120  /* Checks */
121  orxASSERT(_pstRes != orxNULL);
122  orxASSERT(_pvTL != orxNULL);
123  orxASSERT(_pvBR != orxNULL);
124 
125  /* Sets values */
126  orxVector_Copy(&(_pstRes->vTL), _pvTL);
127  orxVector_Copy(&(_pstRes->vBR), _pvBR);
128 
129  /* Reorders corners */
130  orxAABox_Reorder(_pstRes);
131 
132  /* Done! */
133  return _pstRes;
134 }
135 
141 static orxINLINE orxBOOL orxAABox_IsInside(const orxAABOX *_pstBox, const orxVECTOR *_pvPosition)
142 {
143  register orxBOOL bResult = orxFALSE;
144 
145  /* Checks */
146  orxASSERT(_pstBox != orxNULL);
147  orxASSERT(_pvPosition != orxNULL);
148 
149  /* Z intersected? */
150  if((_pvPosition->fZ >= _pstBox->vTL.fZ)
151  && (_pvPosition->fZ <= _pstBox->vBR.fZ))
152  {
153  /* X intersected? */
154  if((_pvPosition->fX >= _pstBox->vTL.fX)
155  && (_pvPosition->fX <= _pstBox->vBR.fX))
156  {
157  /* Y intersected? */
158  if((_pvPosition->fY >= _pstBox->vTL.fY)
159  && (_pvPosition->fY <= _pstBox->vBR.fY))
160  {
161  /* Intersects */
162  bResult = orxTRUE;
163  }
164  }
165  }
166 
167  /* Done! */
168  return bResult;
169 }
170 
176 static orxINLINE orxBOOL orxAABox_TestIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
177 {
178  register orxBOOL bResult = orxFALSE;
179 
180  /* Checks */
181  orxASSERT(_pstBox1 != orxNULL);
182  orxASSERT(_pstBox2 != orxNULL);
183 
184  /* Z intersected? */
185  if((_pstBox2->vBR.fZ >= _pstBox1->vTL.fZ)
186  && (_pstBox2->vTL.fZ <= _pstBox1->vBR.fZ))
187  {
188  /* X intersected? */
189  if((_pstBox2->vBR.fX >= _pstBox1->vTL.fX)
190  && (_pstBox2->vTL.fX <= _pstBox1->vBR.fX))
191  {
192  /* Y intersected? */
193  if((_pstBox2->vBR.fY >= _pstBox1->vTL.fY)
194  && (_pstBox2->vTL.fY <= _pstBox1->vBR.fY))
195  {
196  /* Intersects */
197  bResult = orxTRUE;
198  }
199  }
200  }
201 
202  /* Done! */
203  return bResult;
204 }
205 
211 static orxINLINE orxBOOL orxAABox_Test2DIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
212 {
213  register orxBOOL bResult = orxFALSE;
214 
215  /* Checks */
216  orxASSERT(_pstBox1 != orxNULL);
217  orxASSERT(_pstBox2 != orxNULL);
218 
219  /* X intersected? */
220  if((_pstBox2->vBR.fX >= _pstBox1->vTL.fX)
221  && (_pstBox2->vTL.fX <= _pstBox1->vBR.fX))
222  {
223  /* Y intersected? */
224  if((_pstBox2->vBR.fY >= _pstBox1->vTL.fY)
225  && (_pstBox2->vTL.fY <= _pstBox1->vBR.fY))
226  {
227  /* Intersects */
228  bResult = orxTRUE;
229  }
230  }
231 
232  /* Done! */
233  return bResult;
234 }
235 
241 static orxINLINE orxAABOX * orxAABox_Copy(orxAABOX *_pstDst, const orxAABOX *_pstSrc)
242 {
243  /* Checks */
244  orxASSERT(_pstDst != orxNULL);
245  orxASSERT(_pstSrc != orxNULL);
246 
247  /* Copies it */
248  orxMemory_Copy(_pstDst, _pstSrc, sizeof(orxAABOX));
249 
250  /* Done! */
251  return _pstDst;
252 }
253 
260 static orxINLINE orxAABOX * orxAABox_Move(orxAABOX *_pstRes, const orxAABOX *_pstOp, const orxVECTOR *_pvMove)
261 {
262  /* Checks */
263  orxASSERT(_pstRes != orxNULL);
264  orxASSERT(_pstOp != orxNULL);
265  orxASSERT(_pvMove != orxNULL);
266 
267  /* Updates result */
268  orxVector_Add(&(_pstRes->vTL), &(_pstOp->vTL), _pvMove);
269  orxVector_Add(&(_pstRes->vBR), &(_pstOp->vBR), _pvMove);
270 
271  /* Done! */
272  return _pstRes;
273 }
274 
280 static orxINLINE orxVECTOR * orxAABox_GetCenter(const orxAABOX *_pstOp, orxVECTOR *_pvRes)
281 {
282  /* Checks */
283  orxASSERT(_pstOp != orxNULL);
284  orxASSERT(_pvRes != orxNULL);
285 
286  /* Gets box center */
287  orxVector_Add(_pvRes, &(_pstOp->vTL), &(_pstOp->vBR));
288  orxVector_Mulf(_pvRes, _pvRes, orx2F(0.5f));
289 
290  /* Done! */
291  return _pvRes;
292 }
293 
294 #endif /* _orxAABOX_H_ */
295 
static orxINLINE orxVECTOR * orxVector_Mulf(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, orxFLOAT _fOp2)
Definition: orxVector.h:189
static orxINLINE orxAABOX * orxAABox_Copy(orxAABOX *_pstDst, const orxAABOX *_pstSrc)
Definition: orxAABox.h:241
static orxINLINE orxAABOX * orxAABox_Set(orxAABOX *_pstRes, const orxVECTOR *_pvTL, const orxVECTOR *_pvBR)
Definition: orxAABox.h:118
#define orxTRUE
Definition: orxType.h:186
orxFLOAT fY
Definition: orxVector.h:68
static orxINLINE orxBOOL orxAABox_TestIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
Definition: orxAABox.h:176
orxVECTOR vTL
Definition: orxAABox.h:55
#define orxFALSE
Definition: orxType.h:185
orxFLOAT fX
Definition: orxVector.h:60
orxVECTOR vBR
Definition: orxAABox.h:56
static orxINLINE orxVECTOR * orxVector_Add(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition: orxVector.h:145
orxFLOAT fZ
Definition: orxVector.h:76
static orxINLINE orxBOOL orxAABox_IsInside(const orxAABOX *_pstBox, const orxVECTOR *_pvPosition)
Definition: orxAABox.h:141
static orxINLINE orxVECTOR * orxAABox_GetCenter(const orxAABOX *_pstOp, orxVECTOR *_pvRes)
Definition: orxAABox.h:280
static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition: orxMemory.h:159
static orxINLINE orxAABOX * orxAABox_Reorder(orxAABOX *_pstBox)
Definition: orxAABox.h:68
static orxINLINE orxAABOX * orxAABox_Move(orxAABOX *_pstRes, const orxAABOX *_pstOp, const orxVECTOR *_pvMove)
Definition: orxAABox.h:260
static orxINLINE orxBOOL orxAABox_Test2DIntersection(const orxAABOX *_pstBox1, const orxAABOX *_pstBox2)
Definition: orxAABox.h:211
#define orxASSERT(TEST,...)
Definition: orxDebug.h:298
static orxINLINE orxVECTOR * orxVector_Copy(orxVECTOR *_pvDst, const orxVECTOR *_pvSrc)
Definition: orxVector.h:126

Generated for orx by doxygen 1.5.6