orx 1.16
Portable Game Engine
Loading...
Searching...
No Matches
orxVector.h
Go to the documentation of this file.
1/* Orx - Portable Game Engine
2 *
3 * Copyright (c) 2008- 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
32
41
42
43#ifndef _orxVECTOR_H_
44#define _orxVECTOR_H_
45
46#include "orxInclude.h"
47
48#include "debug/orxDebug.h"
49#include "memory/orxMemory.h"
50#include "math/orxMath.h"
51
52
53#ifdef __orxGCC__
54
55 #pragma GCC diagnostic push
56 #pragma GCC diagnostic ignored "-Wpragmas"
57 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
58
59#endif /* __orxGCC__ */
60
61
64typedef struct __orxVECTOR_t
65{
67 union
68 {
69 orxFLOAT fX;
70 orxFLOAT fRho;
71 orxFLOAT fR;
72 orxFLOAT fH;
73 };
74
75 union
76 {
77 orxFLOAT fY;
78 orxFLOAT fTheta;
79 orxFLOAT fG;
80 orxFLOAT fS;
81 };
82
83 union
84 {
85 orxFLOAT fZ;
86 orxFLOAT fPhi;
87 orxFLOAT fB;
88 orxFLOAT fL;
89 orxFLOAT fV;
90 };
91
92} orxVECTOR;
93
94
95/* *** Vector inlined functions *** */
96
97
105static orxINLINE orxVECTOR * orxVector_Set(orxVECTOR *_pvVec, orxFLOAT _fX, orxFLOAT _fY, orxFLOAT _fZ)
106{
107 /* Checks */
108 orxASSERT(_pvVec != orxNULL);
109
110 /* Stores values */
111 _pvVec->fX = _fX;
112 _pvVec->fY = _fY;
113 _pvVec->fZ = _fZ;
114
115 /* Done ! */
116 return _pvVec;
117}
118
124static orxINLINE orxVECTOR * orxVector_SetAll(orxVECTOR *_pvVec, orxFLOAT _fValue)
125{
126 /* Done ! */
127 return(orxVector_Set(_pvVec, _fValue, _fValue, _fValue));
128}
129
135static orxINLINE orxVECTOR * orxVector_Copy(orxVECTOR *_pvDst, const orxVECTOR *_pvSrc)
136{
137 /* Checks */
138 orxASSERT(_pvDst != orxNULL);
139 orxASSERT(_pvSrc != orxNULL);
140
141 /* Copies it */
142 orxMemory_Copy(_pvDst, _pvSrc, sizeof(orxVECTOR));
143
144 /* Done! */
145 return _pvDst;
146}
147
154static orxINLINE orxVECTOR * orxVector_Add(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
155{
156 /* Checks */
157 orxASSERT(_pvRes != orxNULL);
158 orxASSERT(_pvOp1 != orxNULL);
159 orxASSERT(_pvOp2 != orxNULL);
160
161 /* Adds all */
162 _pvRes->fX = _pvOp1->fX + _pvOp2->fX;
163 _pvRes->fY = _pvOp1->fY + _pvOp2->fY;
164 _pvRes->fZ = _pvOp1->fZ + _pvOp2->fZ;
165
166 /* Done! */
167 return _pvRes;
168}
169
176static orxINLINE orxVECTOR * orxVector_Sub(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
177{
178 /* Checks */
179 orxASSERT(_pvRes != orxNULL);
180 orxASSERT(_pvOp1 != orxNULL);
181 orxASSERT(_pvOp2 != orxNULL);
182
183 /* Adds all */
184 _pvRes->fX = _pvOp1->fX - _pvOp2->fX;
185 _pvRes->fY = _pvOp1->fY - _pvOp2->fY;
186 _pvRes->fZ = _pvOp1->fZ - _pvOp2->fZ;
187
188 /* Done! */
189 return _pvRes;
190}
191
198static orxINLINE orxVECTOR * orxVector_Mulf(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, orxFLOAT _fOp2)
199{
200 /* Checks */
201 orxASSERT(_pvRes != orxNULL);
202 orxASSERT(_pvOp1 != orxNULL);
203
204 /* Muls all */
205 _pvRes->fX = _pvOp1->fX * _fOp2;
206 _pvRes->fY = _pvOp1->fY * _fOp2;
207 _pvRes->fZ = _pvOp1->fZ * _fOp2;
208
209 /* Done! */
210 return _pvRes;
211}
212
219static orxINLINE orxVECTOR * orxVector_Mul(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
220{
221 /* Checks */
222 orxASSERT(_pvRes != orxNULL);
223 orxASSERT(_pvOp1 != orxNULL);
224 orxASSERT(_pvOp2 != orxNULL);
225
226 /* Muls all */
227 _pvRes->fX = _pvOp1->fX * _pvOp2->fX;
228 _pvRes->fY = _pvOp1->fY * _pvOp2->fY;
229 _pvRes->fZ = _pvOp1->fZ * _pvOp2->fZ;
230
231 /* Done! */
232 return _pvRes;
233}
234
241static orxINLINE orxVECTOR * orxVector_Divf(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, orxFLOAT _fOp2)
242{
243 orxFLOAT fRecCoef;
244
245 /* Checks */
246 orxASSERT(_pvRes != orxNULL);
247 orxASSERT(_pvOp1 != orxNULL);
248 orxASSERT(_fOp2 != orxFLOAT_0);
249
250 /* Gets reciprocal coef */
251 fRecCoef = orxFLOAT_1 / _fOp2;
252
253 /* Muls all */
254 _pvRes->fX = _pvOp1->fX * fRecCoef;
255 _pvRes->fY = _pvOp1->fY * fRecCoef;
256 _pvRes->fZ = _pvOp1->fZ * fRecCoef;
257
258 /* Done! */
259 return _pvRes;
260}
261
268static orxINLINE orxVECTOR * orxVector_Div(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
269{
270 /* Checks */
271 orxASSERT(_pvRes != orxNULL);
272 orxASSERT(_pvOp1 != orxNULL);
273 orxASSERT(_pvOp2 != orxNULL);
274
275 /* Divs all */
276 _pvRes->fX = _pvOp1->fX / _pvOp2->fX;
277 _pvRes->fY = _pvOp1->fY / _pvOp2->fY;
278 _pvRes->fZ = _pvOp1->fZ / _pvOp2->fZ;
279
280 /* Done! */
281 return _pvRes;
282}
283
290static orxINLINE orxVECTOR * orxVector_Mod(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
291{
292 /* Checks */
293 orxASSERT(_pvRes != orxNULL);
294 orxASSERT(_pvOp1 != orxNULL);
295 orxASSERT(_pvOp2 != orxNULL);
296
297 /* Modulos all */
298 _pvRes->fX = orxMath_Mod(_pvOp1->fX, _pvOp2->fX);
299 _pvRes->fY = orxMath_Mod(_pvOp1->fY, _pvOp2->fY);
300 _pvRes->fZ = orxMath_Mod(_pvOp1->fZ, _pvOp2->fZ);
301
302 /* Done! */
303 return _pvRes;
304}
305
312static orxINLINE orxVECTOR * orxVector_Pow(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
313{
314 /* Checks */
315 orxASSERT(_pvRes != orxNULL);
316 orxASSERT(_pvOp1 != orxNULL);
317 orxASSERT(_pvOp2 != orxNULL);
318
319 /* Powers all */
320 _pvRes->fX = orxMath_Pow(_pvOp1->fX, _pvOp2->fX);
321 _pvRes->fY = orxMath_Pow(_pvOp1->fY, _pvOp2->fY);
322 _pvRes->fZ = orxMath_Pow(_pvOp1->fZ, _pvOp2->fZ);
323
324 /* Done! */
325 return _pvRes;
326}
327
335static orxINLINE orxVECTOR * orxVector_Lerp(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2, orxFLOAT _fOp)
336{
337 /* Checks */
338 orxASSERT(_pvRes != orxNULL);
339 orxASSERT(_pvOp1 != orxNULL);
340 orxASSERT(_pvOp2 != orxNULL);
341
342 /* Lerps all*/
343 _pvRes->fX = orxLERP(_pvOp1->fX, _pvOp2->fX, _fOp);
344 _pvRes->fY = orxLERP(_pvOp1->fY, _pvOp2->fY, _fOp);
345 _pvRes->fZ = orxLERP(_pvOp1->fZ, _pvOp2->fZ, _fOp);
346
347 /* Done! */
348 return _pvRes;
349}
350
360static orxINLINE orxVECTOR * orxVector_Remap(orxVECTOR *_pvRes, const orxVECTOR *_pvA1, const orxVECTOR *_pvB1, const orxVECTOR *_pvA2, const orxVECTOR *_pvB2, const orxVECTOR *_pvV)
361{
362 /* Checks */
363 orxASSERT(_pvRes != orxNULL);
364 orxASSERT(_pvA1 != orxNULL);
365 orxASSERT(_pvB1 != orxNULL);
366 orxASSERT(_pvA2 != orxNULL);
367 orxASSERT(_pvB2 != orxNULL);
368 orxASSERT(_pvV != orxNULL);
369
370 /* Remaps all*/
371 _pvRes->fX = orxREMAP(_pvA1->fX, _pvB1->fX, _pvA2->fX, _pvB2->fX, _pvV->fX);
372 _pvRes->fY = orxREMAP(_pvA1->fY, _pvB1->fY, _pvA2->fY, _pvB2->fY, _pvV->fY);
373 _pvRes->fZ = orxREMAP(_pvA1->fZ, _pvB1->fZ, _pvA2->fZ, _pvB2->fZ, _pvV->fZ);
374
375 /* Done! */
376 return _pvRes;
377}
378
385static orxINLINE orxVECTOR * orxVector_Min(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
386{
387 /* Checks */
388 orxASSERT(_pvRes != orxNULL);
389 orxASSERT(_pvOp1 != orxNULL);
390 orxASSERT(_pvOp2 != orxNULL);
391
392 /* Gets all mins */
393 _pvRes->fX = orxMIN(_pvOp1->fX, _pvOp2->fX);
394 _pvRes->fY = orxMIN(_pvOp1->fY, _pvOp2->fY);
395 _pvRes->fZ = orxMIN(_pvOp1->fZ, _pvOp2->fZ);
396
397 /* Done! */
398 return _pvRes;
399}
400
407static orxINLINE orxVECTOR * orxVector_Max(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
408{
409 /* Checks */
410 orxASSERT(_pvRes != orxNULL);
411 orxASSERT(_pvOp1 != orxNULL);
412 orxASSERT(_pvOp2 != orxNULL);
413
414 /* Gets all maxs */
415 _pvRes->fX = orxMAX(_pvOp1->fX, _pvOp2->fX);
416 _pvRes->fY = orxMAX(_pvOp1->fY, _pvOp2->fY);
417 _pvRes->fZ = orxMAX(_pvOp1->fZ, _pvOp2->fZ);
418
419 /* Done! */
420 return _pvRes;
421}
422
430static orxINLINE orxVECTOR * orxVector_Clamp(orxVECTOR *_pvRes, const orxVECTOR *_pvOp, const orxVECTOR *_pvMin, const orxVECTOR *_pvMax)
431{
432 /* Checks */
433 orxASSERT(_pvRes != orxNULL);
434 orxASSERT(_pvOp != orxNULL);
435 orxASSERT(_pvMin != orxNULL);
436 orxASSERT(_pvMax != orxNULL);
437
438 /* Gets all clamped values */
439 _pvRes->fX = orxCLAMP(_pvOp->fX, _pvMin->fX, _pvMax->fX);
440 _pvRes->fY = orxCLAMP(_pvOp->fY, _pvMin->fY, _pvMax->fY);
441 _pvRes->fZ = orxCLAMP(_pvOp->fZ, _pvMin->fZ, _pvMax->fZ);
442
443 /* Done! */
444 return _pvRes;
445}
446
452static orxINLINE orxVECTOR * orxVector_Abs(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
453{
454 /* Checks */
455 orxASSERT(_pvRes != orxNULL);
456 orxASSERT(_pvOp != orxNULL);
457
458 /* Negates all */
459 _pvRes->fX = orxMath_Abs(_pvOp->fX);
460 _pvRes->fY = orxMath_Abs(_pvOp->fY);
461 _pvRes->fZ = orxMath_Abs(_pvOp->fZ);
462
463 /* Done! */
464 return _pvRes;
465}
466
472static orxINLINE orxVECTOR * orxVector_Neg(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
473{
474 /* Checks */
475 orxASSERT(_pvRes != orxNULL);
476 orxASSERT(_pvOp != orxNULL);
477
478 /* Negates all */
479 _pvRes->fX = -(_pvOp->fX);
480 _pvRes->fY = -(_pvOp->fY);
481 _pvRes->fZ = -(_pvOp->fZ);
482
483 /* Done! */
484 return _pvRes;
485}
486
492static orxINLINE orxVECTOR * orxVector_Rec(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
493{
494 /* Checks */
495 orxASSERT(_pvRes != orxNULL);
496 orxASSERT(_pvOp != orxNULL);
497
498 /* Reverts all */
499 _pvRes->fX = orxFLOAT_1 / _pvOp->fX;
500 _pvRes->fY = orxFLOAT_1 / _pvOp->fY;
501 _pvRes->fZ = orxFLOAT_1 / _pvOp->fZ;
502
503 /* Done! */
504 return _pvRes;
505}
506
512static orxINLINE orxVECTOR * orxVector_Floor(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
513{
514 /* Checks */
515 orxASSERT(_pvRes != orxNULL);
516 orxASSERT(_pvOp != orxNULL);
517
518 /* Reverts all */
519 _pvRes->fX = orxMath_Floor(_pvOp->fX);
520 _pvRes->fY = orxMath_Floor(_pvOp->fY);
521 _pvRes->fZ = orxMath_Floor(_pvOp->fZ);
522
523 /* Done! */
524 return _pvRes;
525}
526
532static orxINLINE orxVECTOR * orxVector_Round(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
533{
534 /* Checks */
535 orxASSERT(_pvRes != orxNULL);
536 orxASSERT(_pvOp != orxNULL);
537
538 /* Reverts all */
539 _pvRes->fX = orxMath_Round(_pvOp->fX);
540 _pvRes->fY = orxMath_Round(_pvOp->fY);
541 _pvRes->fZ = orxMath_Round(_pvOp->fZ);
542
543 /* Done! */
544 return _pvRes;
545}
546
551static orxINLINE orxFLOAT orxVector_GetSquareSize(const orxVECTOR *_pvOp)
552{
553 orxFLOAT fResult;
554
555 /* Checks */
556 orxASSERT(_pvOp != orxNULL);
557
558 /* Updates result */
559 fResult = (_pvOp->fX * _pvOp->fX) + (_pvOp->fY * _pvOp->fY) + (_pvOp->fZ * _pvOp->fZ);
560
561 /* Done! */
562 return fResult;
563}
564
569static orxINLINE orxFLOAT orxVector_GetSize(const orxVECTOR *_pvOp)
570{
571 orxFLOAT fResult;
572
573 /* Checks */
574 orxASSERT(_pvOp != orxNULL);
575
576 /* Updates result */
577 fResult = orxMath_Sqrt((_pvOp->fX * _pvOp->fX) + (_pvOp->fY * _pvOp->fY) + (_pvOp->fZ * _pvOp->fZ));
578
579 /* Done! */
580 return fResult;
581}
582
588static orxINLINE orxFLOAT orxVector_GetSquareDistance(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
589{
590 orxVECTOR vTemp;
591 orxFLOAT fResult;
592
593 /* Checks */
594 orxASSERT(_pvOp1 != orxNULL);
595 orxASSERT(_pvOp2 != orxNULL);
596
597 /* Gets distance vector */
598 orxVector_Sub(&vTemp, _pvOp2, _pvOp1);
599
600 /* Updates result */
601 fResult = orxVector_GetSquareSize(&vTemp);
602
603 /* Done! */
604 return fResult;
605}
606
612static orxINLINE orxFLOAT orxVector_GetDistance(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
613{
614 orxVECTOR vTemp;
615 orxFLOAT fResult;
616
617 /* Checks */
618 orxASSERT(_pvOp1 != orxNULL);
619 orxASSERT(_pvOp2 != orxNULL);
620
621 /* Gets distance vector */
622 orxVector_Sub(&vTemp, _pvOp2, _pvOp1);
623
624 /* Updates result */
625 fResult = orxVector_GetSize(&vTemp);
626
627 /* Done! */
628 return fResult;
629}
630
636static orxINLINE orxVECTOR * orxVector_Normalize(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
637{
638 orxFLOAT fOp;
639
640 /* Checks */
641 orxASSERT(_pvRes != orxNULL);
642 orxASSERT(_pvOp != orxNULL);
643
644 /* Gets squared size */
645 fOp = (_pvOp->fX * _pvOp->fX) + (_pvOp->fY * _pvOp->fY) + (_pvOp->fZ * _pvOp->fZ);
646
647 /* Gets reciprocal size */
649
650 /* Updates result */
651 _pvRes->fX = fOp * _pvOp->fX;
652 _pvRes->fY = fOp * _pvOp->fY;
653 _pvRes->fZ = fOp * _pvOp->fZ;
654
655 /* Done! */
656 return _pvRes;
657}
658
665static orxINLINE orxVECTOR * orxVector_2DRotate(orxVECTOR *_pvRes, const orxVECTOR *_pvOp, orxFLOAT _fAngle)
666{
667 /* Checks */
668 orxASSERT(_pvRes != orxNULL);
669 orxASSERT(_pvOp != orxNULL);
670
671 /* 0? */
672 if(_fAngle == orxFLOAT_0)
673 {
674 /* Updates result */
675 orxVector_Copy(_pvRes, _pvOp);
676 }
677 /* PI/2? */
678 if(_fAngle == orxMATH_KF_PI_BY_2)
679 {
680 /* Updates result */
681 orxVector_Set(_pvRes, -_pvOp->fY, _pvOp->fX, _pvOp->fZ);
682 }
683 /* -PI/2? */
684 else if(_fAngle == -orxMATH_KF_PI_BY_2)
685 {
686 /* Updates result */
687 orxVector_Set(_pvRes, _pvOp->fY, -_pvOp->fX, _pvOp->fZ);
688 }
689 else if(_fAngle == orxMATH_KF_PI)
690 {
691 /* Updates result */
692 orxVector_Set(_pvRes, -_pvOp->fX, -_pvOp->fY, _pvOp->fZ);
693 }
694 /* Any other angle */
695 else
696 {
697 orxFLOAT fSin, fCos;
698
699 /* Gets cos & sin of angle */
700 fCos = orxMath_Cos(_fAngle);
701 fSin = orxMath_Sin(_fAngle);
702
703 /* Updates result */
704 orxVector_Set(_pvRes, (fCos * _pvOp->fX) - (fSin * _pvOp->fY), (fSin * _pvOp->fX) + (fCos * _pvOp->fY), _pvOp->fZ);
705 }
706
707 /* Done! */
708 return _pvRes;
709}
710
715static orxINLINE orxBOOL orxVector_IsNull(const orxVECTOR *_pvOp)
716{
717 orxBOOL bResult;
718
719 /* Checks */
720 orxASSERT(_pvOp != orxNULL);
721
722 /* Updates result */
723 bResult = ((_pvOp->fX == orxFLOAT_0) && (_pvOp->fY == orxFLOAT_0) && (_pvOp->fZ == orxFLOAT_0)) ? orxTRUE : orxFALSE;
724
725 /* Done! */
726 return bResult;
727}
728
734static orxINLINE orxBOOL orxVector_AreEqual(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
735{
736 orxBOOL bResult;
737
738 /* Checks */
739 orxASSERT(_pvOp1 != orxNULL);
740 orxASSERT(_pvOp2 != orxNULL);
741
742 /* Updates result */
743 bResult = ((_pvOp1->fX == _pvOp2->fX) && (_pvOp1->fY == _pvOp2->fY) && (_pvOp1->fZ == _pvOp2->fZ)) ? orxTRUE : orxFALSE;
744
745 /* Done! */
746 return bResult;
747}
748
754static orxINLINE orxVECTOR * orxVector_FromCartesianToSpherical(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
755{
756 /* Checks */
757 orxASSERT(_pvRes != orxNULL);
758 orxASSERT(_pvOp != orxNULL);
759
760 /* Is operand vector null? */
761 if((_pvOp->fX == orxFLOAT_0)
762 && (_pvOp->fY == orxFLOAT_0)
763 && (_pvOp->fZ == orxFLOAT_0))
764 {
765 /* Updates result vector */
766 _pvRes->fRho = _pvRes->fTheta = _pvRes->fPhi = orxFLOAT_0;
767 }
768 else
769 {
770 orxFLOAT fRho, fTheta, fPhi;
771
772 /* Z = 0? */
773 if(_pvOp->fZ == orxFLOAT_0)
774 {
775 /* X = 0? */
776 if(_pvOp->fX == orxFLOAT_0)
777 {
778 /* Gets absolute value */
779 fRho = orxMath_Abs(_pvOp->fY);
780 }
781 /* X != 0 and Y = 0? */
782 else if(_pvOp->fY == orxFLOAT_0)
783 {
784 /* Gets absolute value */
785 fRho = orxMath_Abs(_pvOp->fX);
786 }
787 /* X != 0 and Y != 0 */
788 else
789 {
790 /* Computes rho */
791 fRho = orxMath_Sqrt((_pvOp->fX * _pvOp->fX) + (_pvOp->fY * _pvOp->fY));
792 }
793
794 /* Sets phi */
795 fPhi = orxFLOAT_0;
796 }
797 else
798 {
799 /* X = 0 and Y = 0? */
800 if((_pvOp->fX == orxFLOAT_0) && (_pvOp->fY == orxFLOAT_0))
801 {
802 /* Z < 0? */
803 if(_pvOp->fZ < orxFLOAT_0)
804 {
805 /* Gets absolute value */
806 fRho = orxMath_Abs(_pvOp->fZ);
807
808 /* Sets phi */
809 fPhi = orxMATH_KF_PI_BY_2;
810 }
811 else
812 {
813 /* Sets rho */
814 fRho = _pvOp->fZ;
815
816 /* Sets phi */
817 fPhi = -orxMATH_KF_PI_BY_2;
818 }
819 }
820 else
821 {
822 /* Computes rho */
824
825 /* Computes phi */
826 fPhi = orxMath_ACos(_pvOp->fZ / fRho) - orxMATH_KF_PI_BY_2;
827 }
828 }
829
830 /* Computes theta */
831 fTheta = orxMath_ATan(_pvOp->fY, _pvOp->fX);
832
833 /* Updates result */
834 _pvRes->fRho = fRho;
835 _pvRes->fTheta = fTheta;
836 _pvRes->fPhi = fPhi;
837 }
838
839 /* Done! */
840 return _pvRes;
841}
842
848static orxINLINE orxVECTOR * orxVector_FromSphericalToCartesian(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
849{
850 orxFLOAT fSinPhi, fCosPhi, fSinTheta, fCosTheta, fRho;
851
852 /* Checks */
853 orxASSERT(_pvRes != orxNULL);
854 orxASSERT(_pvOp != orxNULL);
855
856 /* Stores rho */
857 fRho = _pvOp->fRho;
858
859 /* Gets sine & cosine */
860 fSinTheta = orxMath_Sin(_pvOp->fTheta);
861 fCosTheta = orxMath_Cos(_pvOp->fTheta);
862 fSinPhi = orxMath_Sin(_pvOp->fPhi + orxMATH_KF_PI_BY_2);
863 fCosPhi = orxMath_Cos(_pvOp->fPhi + orxMATH_KF_PI_BY_2);
864 if(orxMath_Abs(fSinTheta) < orxMATH_KF_EPSILON)
865 {
866 fSinTheta = orxFLOAT_0;
867 }
868 if(orxMath_Abs(fCosTheta) < orxMATH_KF_EPSILON)
869 {
870 fCosTheta = orxFLOAT_0;
871 }
872 if(orxMath_Abs(fSinPhi) < orxMATH_KF_EPSILON)
873 {
874 fSinPhi = orxFLOAT_0;
875 }
876 if(orxMath_Abs(fCosPhi) < orxMATH_KF_EPSILON)
877 {
878 fCosPhi = orxFLOAT_0;
879 }
880
881 /* Updates result */
882 _pvRes->fX = fRho * fCosTheta * fSinPhi;
883 _pvRes->fY = fRho * fSinTheta * fSinPhi;
884 _pvRes->fZ = fRho * fCosPhi;
885
886 /* Done! */
887 return _pvRes;
888}
889
895static orxINLINE orxFLOAT orxVector_Dot(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
896{
897 orxFLOAT fResult;
898
899 /* Checks */
900 orxASSERT(_pvOp1 != orxNULL);
901 orxASSERT(_pvOp2 != orxNULL);
902
903 /* Updates result */
904 fResult = (_pvOp1->fX * _pvOp2->fX) + (_pvOp1->fY * _pvOp2->fY) + (_pvOp1->fZ * _pvOp2->fZ);
905
906 /* Done! */
907 return fResult;
908}
909
915static orxINLINE orxFLOAT orxVector_2DDot(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
916{
917 orxFLOAT fResult;
918
919 /* Checks */
920 orxASSERT(_pvOp1 != orxNULL);
921 orxASSERT(_pvOp2 != orxNULL);
922
923 /* Updates result */
924 fResult = (_pvOp1->fX * _pvOp2->fX) + (_pvOp1->fY * _pvOp2->fY);
925
926 /* Done! */
927 return fResult;
928}
929
936static orxINLINE orxVECTOR * orxVector_Cross(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
937{
938 orxFLOAT fTemp1, fTemp2;
939
940 /* Checks */
941 orxASSERT(_pvRes != orxNULL);
942 orxASSERT(_pvOp1 != orxNULL);
943 orxASSERT(_pvOp2 != orxNULL);
944
945 /* Computes cross product */
946 fTemp1 = (_pvOp1->fY * _pvOp2->fZ) - (_pvOp1->fZ * _pvOp2->fY);
947 fTemp2 = (_pvOp1->fZ * _pvOp2->fX) - (_pvOp1->fX * _pvOp2->fZ);
948 _pvRes->fZ = (_pvOp1->fX * _pvOp2->fY) - (_pvOp1->fY * _pvOp2->fX);
949 _pvRes->fY = fTemp2;
950 _pvRes->fX = fTemp1;
951
952 /* Done! */
953 return _pvRes;
954}
955
956
957/* *** Vector functions *** */
958
968extern orxDLLAPI orxVECTOR *orxFASTCALL orxVector_Bezier(orxVECTOR *_pvRes, const orxVECTOR *_pvPoint1, const orxVECTOR *_pvPoint2, const orxVECTOR *_pvPoint3, const orxVECTOR *_pvPoint4, orxFLOAT _fT);
969
979extern orxDLLAPI orxVECTOR *orxFASTCALL orxVector_CatmullRom(orxVECTOR *_pvRes, const orxVECTOR *_pvPoint1, const orxVECTOR *_pvPoint2, const orxVECTOR *_pvPoint3, const orxVECTOR *_pvPoint4, orxFLOAT _fT);
980
981
982/* *** Vector constants *** */
983
984extern orxDLLAPI const orxVECTOR orxVECTOR_X;
985extern orxDLLAPI const orxVECTOR orxVECTOR_Y;
986extern orxDLLAPI const orxVECTOR orxVECTOR_Z;
987
988extern orxDLLAPI const orxVECTOR orxVECTOR_0;
989extern orxDLLAPI const orxVECTOR orxVECTOR_1;
990
991#define orxCOLOR_DECLARE(NAME, R, G, B) extern orxDLLAPI const orxVECTOR orxVECTOR_##NAME;
992
994
995#undef orxCOLOR_DECLARE
996
997#ifdef __orxGCC__
998
999 #pragma GCC diagnostic pop
1000
1001#endif /* __orxGCC__ */
1002
1003#endif /* _orxVECTOR_H_ */
1004
#define orxASSERT(TEST,...)
Definition orxDebug.h:378
#define orxDLLAPI
Definition orxDecl.h:381
static orxINLINE orxFLOAT orxMath_Floor(orxFLOAT _fOp)
Definition orxMath.h:524
#define orxMATH_KF_PI_BY_2
Definition orxMath.h:403
static orxINLINE orxFLOAT orxMath_Mod(orxFLOAT _fOp1, orxFLOAT _fOp2)
Definition orxMath.h:579
static orxINLINE orxFLOAT orxMath_Cos(orxFLOAT _fOp)
Definition orxMath.h:430
#define orxMIN(A, B)
Definition orxMath.h:83
#define orxMATH_KF_TINY_EPSILON
Definition orxMath.h:399
#define orxLERP(A, B, T)
Definition orxMath.h:66
static orxINLINE orxFLOAT orxMath_ATan(orxFLOAT _fOp1, orxFLOAT _fOp2)
Definition orxMath.h:491
#define orxMATH_KF_EPSILON
Definition orxMath.h:398
static orxINLINE orxFLOAT orxMath_Abs(orxFLOAT _fOp)
Definition orxMath.h:610
#define orxREMAP(A1, B1, A2, B2, V)
Definition orxMath.h:76
static orxINLINE orxFLOAT orxMath_Pow(orxFLOAT _fOp, orxFLOAT _fExp)
Definition orxMath.h:595
static orxINLINE orxFLOAT orxMath_ACos(orxFLOAT _fOp)
Definition orxMath.h:460
static orxINLINE orxFLOAT orxMath_Round(orxFLOAT _fOp)
Definition orxMath.h:554
#define orxMATH_KF_PI
Definition orxMath.h:402
static orxINLINE orxFLOAT orxMath_Sqrt(orxFLOAT _fOp)
Definition orxMath.h:509
#define orxCLAMP(V, MIN, MAX)
Definition orxMath.h:98
static orxINLINE orxFLOAT orxMath_Sin(orxFLOAT _fOp)
Definition orxMath.h:415
#define orxMAX(A, B)
Definition orxMath.h:90
static orxINLINE void * orxMemory_Copy(void *_pDest, const void *_pSrc, orxU32 _u32Size)
Definition orxMemory.h:165
#define orxFALSE
Definition orxType.h:210
#define orxTRUE
Definition orxType.h:211
static const orxFLOAT orxFLOAT_1
Definition orxType.h:216
static const orxFLOAT orxFLOAT_0
Definition orxType.h:215
static orxINLINE orxVECTOR * orxVector_Mulf(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, orxFLOAT _fOp2)
Definition orxVector.h:198
static orxINLINE orxFLOAT orxVector_2DDot(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:915
static orxINLINE orxVECTOR * orxVector_SetAll(orxVECTOR *_pvVec, orxFLOAT _fValue)
Definition orxVector.h:124
orxDLLAPI const orxVECTOR orxVECTOR_Y
static orxINLINE orxVECTOR * orxVector_Div(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:268
static orxINLINE orxVECTOR * orxVector_Copy(orxVECTOR *_pvDst, const orxVECTOR *_pvSrc)
Definition orxVector.h:135
static orxINLINE orxVECTOR * orxVector_Mul(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:219
static orxINLINE orxVECTOR * orxVector_Mod(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:290
static orxINLINE orxVECTOR * orxVector_FromSphericalToCartesian(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:848
static orxINLINE orxFLOAT orxVector_GetSquareDistance(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:588
static orxINLINE orxVECTOR * orxVector_Min(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:385
static orxINLINE orxFLOAT orxVector_GetDistance(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:612
static orxINLINE orxVECTOR * orxVector_Remap(orxVECTOR *_pvRes, const orxVECTOR *_pvA1, const orxVECTOR *_pvB1, const orxVECTOR *_pvA2, const orxVECTOR *_pvB2, const orxVECTOR *_pvV)
Definition orxVector.h:360
static orxINLINE orxVECTOR * orxVector_Cross(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:936
static orxINLINE orxBOOL orxVector_AreEqual(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:734
static orxINLINE orxVECTOR * orxVector_Sub(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:176
static orxINLINE orxVECTOR * orxVector_Normalize(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:636
static orxINLINE orxFLOAT orxVector_GetSquareSize(const orxVECTOR *_pvOp)
Definition orxVector.h:551
static orxINLINE orxFLOAT orxVector_Dot(const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:895
static orxINLINE orxFLOAT orxVector_GetSize(const orxVECTOR *_pvOp)
Definition orxVector.h:569
static orxINLINE orxVECTOR * orxVector_Round(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:532
static orxINLINE orxVECTOR * orxVector_Max(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:407
static orxINLINE orxVECTOR * orxVector_Floor(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:512
static orxINLINE orxVECTOR * orxVector_Rec(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:492
static orxINLINE orxBOOL orxVector_IsNull(const orxVECTOR *_pvOp)
Definition orxVector.h:715
static orxINLINE orxVECTOR * orxVector_Lerp(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2, orxFLOAT _fOp)
Definition orxVector.h:335
orxDLLAPI orxVECTOR *orxFASTCALL orxVector_Bezier(orxVECTOR *_pvRes, const orxVECTOR *_pvPoint1, const orxVECTOR *_pvPoint2, const orxVECTOR *_pvPoint3, const orxVECTOR *_pvPoint4, orxFLOAT _fT)
static orxINLINE orxVECTOR * orxVector_Pow(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:312
orxDLLAPI const orxVECTOR orxVECTOR_1
static orxINLINE orxVECTOR * orxVector_Set(orxVECTOR *_pvVec, orxFLOAT _fX, orxFLOAT _fY, orxFLOAT _fZ)
Definition orxVector.h:105
static orxINLINE orxVECTOR * orxVector_2DRotate(orxVECTOR *_pvRes, const orxVECTOR *_pvOp, orxFLOAT _fAngle)
Definition orxVector.h:665
orxDLLAPI const orxVECTOR orxVECTOR_X
static orxINLINE orxVECTOR * orxVector_FromCartesianToSpherical(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:754
orxDLLAPI orxVECTOR *orxFASTCALL orxVector_CatmullRom(orxVECTOR *_pvRes, const orxVECTOR *_pvPoint1, const orxVECTOR *_pvPoint2, const orxVECTOR *_pvPoint3, const orxVECTOR *_pvPoint4, orxFLOAT _fT)
static orxINLINE orxVECTOR * orxVector_Add(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, const orxVECTOR *_pvOp2)
Definition orxVector.h:154
static orxINLINE orxVECTOR * orxVector_Neg(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:472
static orxINLINE orxVECTOR * orxVector_Divf(orxVECTOR *_pvRes, const orxVECTOR *_pvOp1, orxFLOAT _fOp2)
Definition orxVector.h:241
static orxINLINE orxVECTOR * orxVector_Clamp(orxVECTOR *_pvRes, const orxVECTOR *_pvOp, const orxVECTOR *_pvMin, const orxVECTOR *_pvMax)
Definition orxVector.h:430
static orxINLINE orxVECTOR * orxVector_Abs(orxVECTOR *_pvRes, const orxVECTOR *_pvOp)
Definition orxVector.h:452
orxDLLAPI const orxVECTOR orxVECTOR_0
orxDLLAPI const orxVECTOR orxVECTOR_Z
orxFLOAT fRho
Definition orxVector.h:70
orxFLOAT fV
Definition orxVector.h:89
orxFLOAT fR
Definition orxVector.h:71
orxFLOAT fY
Definition orxVector.h:77
orxFLOAT fH
Definition orxVector.h:72
orxFLOAT fTheta
Definition orxVector.h:78
orxFLOAT fL
Definition orxVector.h:88
orxFLOAT fB
Definition orxVector.h:87
orxFLOAT fPhi
Definition orxVector.h:86
orxFLOAT fX
Definition orxVector.h:69
orxFLOAT fZ
Definition orxVector.h:85
orxFLOAT fS
Definition orxVector.h:80
orxFLOAT fG
Definition orxVector.h:79

Generated for orx by doxygen 1.8.11