forked from prideout/fluidsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmath.hpp
5101 lines (4261 loc) · 139 KB
/
vmath.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <math.h>
#ifdef _VECTORMATH_DEBUG
#include <stdio.h>
#endif
namespace Vectormath {
namespace Aos {
//-----------------------------------------------------------------------------
// Forward Declarations
//
class Vector3;
class Vector4;
class Point3;
class Quat;
class Matrix3;
class Matrix4;
class Transform3;
// A 3-D vector in array-of-structures format
//
class Vector3
{
float mX;
float mY;
float mZ;
#ifndef __GNUC__
float d;
#endif
public:
// Default constructor; does no initialization
//
inline Vector3( ) { };
// Copy a 3-D vector
//
inline Vector3( const Vector3 & vec );
// Construct a 3-D vector from x, y, and z elements
//
inline Vector3( float x, float y, float z );
// Copy elements from a 3-D point into a 3-D vector
//
explicit inline Vector3( const Point3 & pnt );
// Set all elements of a 3-D vector to the same scalar value
//
explicit inline Vector3( float scalar );
// Assign one 3-D vector to another
//
inline Vector3 & operator =( const Vector3 & vec );
// Set the x element of a 3-D vector
//
inline Vector3 & setX( float x );
// Set the y element of a 3-D vector
//
inline Vector3 & setY( float y );
// Set the z element of a 3-D vector
//
inline Vector3 & setZ( float z );
// Get the x element of a 3-D vector
//
inline float getX( ) const;
// Get the y element of a 3-D vector
//
inline float getY( ) const;
// Get the z element of a 3-D vector
//
inline float getZ( ) const;
// Set an x, y, or z element of a 3-D vector by index
//
inline Vector3 & setElem( int idx, float value );
// Get an x, y, or z element of a 3-D vector by index
//
inline float getElem( int idx ) const;
// Subscripting operator to set or get an element
//
inline float & operator []( int idx );
// Subscripting operator to get an element
//
inline float operator []( int idx ) const;
// Add two 3-D vectors
//
inline const Vector3 operator +( const Vector3 & vec ) const;
// Subtract a 3-D vector from another 3-D vector
//
inline const Vector3 operator -( const Vector3 & vec ) const;
// Add a 3-D vector to a 3-D point
//
inline const Point3 operator +( const Point3 & pnt ) const;
// Multiply a 3-D vector by a scalar
//
inline const Vector3 operator *( float scalar ) const;
// Divide a 3-D vector by a scalar
//
inline const Vector3 operator /( float scalar ) const;
// Perform compound assignment and addition with a 3-D vector
//
inline Vector3 & operator +=( const Vector3 & vec );
// Perform compound assignment and subtraction by a 3-D vector
//
inline Vector3 & operator -=( const Vector3 & vec );
// Perform compound assignment and multiplication by a scalar
//
inline Vector3 & operator *=( float scalar );
// Perform compound assignment and division by a scalar
//
inline Vector3 & operator /=( float scalar );
// Negate all elements of a 3-D vector
//
inline const Vector3 operator -( ) const;
// Construct x axis
//
static inline const Vector3 xAxis( );
// Construct y axis
//
static inline const Vector3 yAxis( );
// Construct z axis
//
static inline const Vector3 zAxis( );
}
#ifdef __GNUC__
__attribute__ ((aligned(16)))
#endif
;
// Multiply a 3-D vector by a scalar
//
inline const Vector3 operator *( float scalar, const Vector3 & vec );
// Multiply two 3-D vectors per element
//
inline const Vector3 mulPerElem( const Vector3 & vec0, const Vector3 & vec1 );
// Divide two 3-D vectors per element
// NOTE:
// Floating-point behavior matches standard library function divf4.
//
inline const Vector3 divPerElem( const Vector3 & vec0, const Vector3 & vec1 );
// Compute the reciprocal of a 3-D vector per element
// NOTE:
// Floating-point behavior matches standard library function recipf4.
//
inline const Vector3 recipPerElem( const Vector3 & vec );
// Compute the square root of a 3-D vector per element
// NOTE:
// Floating-point behavior matches standard library function sqrtf4.
//
inline const Vector3 sqrtPerElem( const Vector3 & vec );
// Compute the reciprocal square root of a 3-D vector per element
// NOTE:
// Floating-point behavior matches standard library function rsqrtf4.
//
inline const Vector3 rsqrtPerElem( const Vector3 & vec );
// Compute the absolute value of a 3-D vector per element
//
inline const Vector3 absPerElem( const Vector3 & vec );
// Copy sign from one 3-D vector to another, per element
//
inline const Vector3 copySignPerElem( const Vector3 & vec0, const Vector3 & vec1 );
// Maximum of two 3-D vectors per element
//
inline const Vector3 maxPerElem( const Vector3 & vec0, const Vector3 & vec1 );
// Minimum of two 3-D vectors per element
//
inline const Vector3 minPerElem( const Vector3 & vec0, const Vector3 & vec1 );
// Maximum element of a 3-D vector
//
inline float maxElem( const Vector3 & vec );
// Minimum element of a 3-D vector
//
inline float minElem( const Vector3 & vec );
// Compute the sum of all elements of a 3-D vector
//
inline float sum( const Vector3 & vec );
// Compute the dot product of two 3-D vectors
//
inline float dot( const Vector3 & vec0, const Vector3 & vec1 );
// Compute the square of the length of a 3-D vector
//
inline float lengthSqr( const Vector3 & vec );
// Compute the length of a 3-D vector
//
inline float length( const Vector3 & vec );
// Normalize a 3-D vector
// NOTE:
// The result is unpredictable when all elements of vec are at or near zero.
//
inline const Vector3 normalize( const Vector3 & vec );
// Compute cross product of two 3-D vectors
//
inline const Vector3 cross( const Vector3 & vec0, const Vector3 & vec1 );
// Outer product of two 3-D vectors
//
inline const Matrix3 outer( const Vector3 & vec0, const Vector3 & vec1 );
// Pre-multiply a row vector by a 3x3 matrix
//
inline const Vector3 rowMul( const Vector3 & vec, const Matrix3 & mat );
// Cross-product matrix of a 3-D vector
//
inline const Matrix3 crossMatrix( const Vector3 & vec );
// Create cross-product matrix and multiply
// NOTE:
// Faster than separately creating a cross-product matrix and multiplying.
//
inline const Matrix3 crossMatrixMul( const Vector3 & vec, const Matrix3 & mat );
// Linear interpolation between two 3-D vectors
// NOTE:
// Does not clamp t between 0 and 1.
//
inline const Vector3 lerp( float t, const Vector3 & vec0, const Vector3 & vec1 );
// Spherical linear interpolation between two 3-D vectors
// NOTE:
// The result is unpredictable if the vectors point in opposite directions.
// Does not clamp t between 0 and 1.
//
inline const Vector3 slerp( float t, const Vector3 & unitVec0, const Vector3 & unitVec1 );
// Conditionally select between two 3-D vectors
//
inline const Vector3 select( const Vector3 & vec0, const Vector3 & vec1, bool select1 );
#ifdef _VECTORMATH_DEBUG
// Print a 3-D vector
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Vector3 & vec );
// Print a 3-D vector and an associated string identifier
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Vector3 & vec, const char * name );
#endif
// A 4-D vector in array-of-structures format
//
class Vector4
{
float mX;
float mY;
float mZ;
float mW;
public:
// Default constructor; does no initialization
//
inline Vector4( ) { };
// Copy a 4-D vector
//
inline Vector4( const Vector4 & vec );
// Construct a 4-D vector from x, y, z, and w elements
//
inline Vector4( float x, float y, float z, float w );
// Construct a 4-D vector from a 3-D vector and a scalar
//
inline Vector4( const Vector3 & xyz, float w );
// Copy x, y, and z from a 3-D vector into a 4-D vector, and set w to 0
//
explicit inline Vector4( const Vector3 & vec );
// Copy x, y, and z from a 3-D point into a 4-D vector, and set w to 1
//
explicit inline Vector4( const Point3 & pnt );
// Copy elements from a quaternion into a 4-D vector
//
explicit inline Vector4( const Quat & quat );
// Set all elements of a 4-D vector to the same scalar value
//
explicit inline Vector4( float scalar );
// Assign one 4-D vector to another
//
inline Vector4 & operator =( const Vector4 & vec );
// Set the x, y, and z elements of a 4-D vector
// NOTE:
// This function does not change the w element.
//
inline Vector4 & setXYZ( const Vector3 & vec );
// Get the x, y, and z elements of a 4-D vector
//
inline const Vector3 getXYZ( ) const;
// Set the x element of a 4-D vector
//
inline Vector4 & setX( float x );
// Set the y element of a 4-D vector
//
inline Vector4 & setY( float y );
// Set the z element of a 4-D vector
//
inline Vector4 & setZ( float z );
// Set the w element of a 4-D vector
//
inline Vector4 & setW( float w );
// Get the x element of a 4-D vector
//
inline float getX( ) const;
// Get the y element of a 4-D vector
//
inline float getY( ) const;
// Get the z element of a 4-D vector
//
inline float getZ( ) const;
// Get the w element of a 4-D vector
//
inline float getW( ) const;
// Set an x, y, z, or w element of a 4-D vector by index
//
inline Vector4 & setElem( int idx, float value );
// Get an x, y, z, or w element of a 4-D vector by index
//
inline float getElem( int idx ) const;
// Subscripting operator to set or get an element
//
inline float & operator []( int idx );
// Subscripting operator to get an element
//
inline float operator []( int idx ) const;
// Add two 4-D vectors
//
inline const Vector4 operator +( const Vector4 & vec ) const;
// Subtract a 4-D vector from another 4-D vector
//
inline const Vector4 operator -( const Vector4 & vec ) const;
// Multiply a 4-D vector by a scalar
//
inline const Vector4 operator *( float scalar ) const;
// Divide a 4-D vector by a scalar
//
inline const Vector4 operator /( float scalar ) const;
// Perform compound assignment and addition with a 4-D vector
//
inline Vector4 & operator +=( const Vector4 & vec );
// Perform compound assignment and subtraction by a 4-D vector
//
inline Vector4 & operator -=( const Vector4 & vec );
// Perform compound assignment and multiplication by a scalar
//
inline Vector4 & operator *=( float scalar );
// Perform compound assignment and division by a scalar
//
inline Vector4 & operator /=( float scalar );
// Negate all elements of a 4-D vector
//
inline const Vector4 operator -( ) const;
// Construct x axis
//
static inline const Vector4 xAxis( );
// Construct y axis
//
static inline const Vector4 yAxis( );
// Construct z axis
//
static inline const Vector4 zAxis( );
// Construct w axis
//
static inline const Vector4 wAxis( );
}
#ifdef __GNUC__
__attribute__ ((aligned(16)))
#endif
;
// Multiply a 4-D vector by a scalar
//
inline const Vector4 operator *( float scalar, const Vector4 & vec );
// Multiply two 4-D vectors per element
//
inline const Vector4 mulPerElem( const Vector4 & vec0, const Vector4 & vec1 );
// Divide two 4-D vectors per element
// NOTE:
// Floating-point behavior matches standard library function divf4.
//
inline const Vector4 divPerElem( const Vector4 & vec0, const Vector4 & vec1 );
// Compute the reciprocal of a 4-D vector per element
// NOTE:
// Floating-point behavior matches standard library function recipf4.
//
inline const Vector4 recipPerElem( const Vector4 & vec );
// Compute the square root of a 4-D vector per element
// NOTE:
// Floating-point behavior matches standard library function sqrtf4.
//
inline const Vector4 sqrtPerElem( const Vector4 & vec );
// Compute the reciprocal square root of a 4-D vector per element
// NOTE:
// Floating-point behavior matches standard library function rsqrtf4.
//
inline const Vector4 rsqrtPerElem( const Vector4 & vec );
// Compute the absolute value of a 4-D vector per element
//
inline const Vector4 absPerElem( const Vector4 & vec );
// Copy sign from one 4-D vector to another, per element
//
inline const Vector4 copySignPerElem( const Vector4 & vec0, const Vector4 & vec1 );
// Maximum of two 4-D vectors per element
//
inline const Vector4 maxPerElem( const Vector4 & vec0, const Vector4 & vec1 );
// Minimum of two 4-D vectors per element
//
inline const Vector4 minPerElem( const Vector4 & vec0, const Vector4 & vec1 );
// Maximum element of a 4-D vector
//
inline float maxElem( const Vector4 & vec );
// Minimum element of a 4-D vector
//
inline float minElem( const Vector4 & vec );
// Compute the sum of all elements of a 4-D vector
//
inline float sum( const Vector4 & vec );
// Compute the dot product of two 4-D vectors
//
inline float dot( const Vector4 & vec0, const Vector4 & vec1 );
// Compute the square of the length of a 4-D vector
//
inline float lengthSqr( const Vector4 & vec );
// Compute the length of a 4-D vector
//
inline float length( const Vector4 & vec );
// Normalize a 4-D vector
// NOTE:
// The result is unpredictable when all elements of vec are at or near zero.
//
inline const Vector4 normalize( const Vector4 & vec );
// Outer product of two 4-D vectors
//
inline const Matrix4 outer( const Vector4 & vec0, const Vector4 & vec1 );
// Linear interpolation between two 4-D vectors
// NOTE:
// Does not clamp t between 0 and 1.
//
inline const Vector4 lerp( float t, const Vector4 & vec0, const Vector4 & vec1 );
// Spherical linear interpolation between two 4-D vectors
// NOTE:
// The result is unpredictable if the vectors point in opposite directions.
// Does not clamp t between 0 and 1.
//
inline const Vector4 slerp( float t, const Vector4 & unitVec0, const Vector4 & unitVec1 );
// Conditionally select between two 4-D vectors
//
inline const Vector4 select( const Vector4 & vec0, const Vector4 & vec1, bool select1 );
#ifdef _VECTORMATH_DEBUG
// Print a 4-D vector
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Vector4 & vec );
// Print a 4-D vector and an associated string identifier
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Vector4 & vec, const char * name );
#endif
// A 3-D point in array-of-structures format
//
class Point3
{
float mX;
float mY;
float mZ;
#ifndef __GNUC__
float d;
#endif
public:
// Default constructor; does no initialization
//
inline Point3( ) { };
// Copy a 3-D point
//
inline Point3( const Point3 & pnt );
// Construct a 3-D point from x, y, and z elements
//
inline Point3( float x, float y, float z );
// Copy elements from a 3-D vector into a 3-D point
//
explicit inline Point3( const Vector3 & vec );
// Set all elements of a 3-D point to the same scalar value
//
explicit inline Point3( float scalar );
// Assign one 3-D point to another
//
inline Point3 & operator =( const Point3 & pnt );
// Set the x element of a 3-D point
//
inline Point3 & setX( float x );
// Set the y element of a 3-D point
//
inline Point3 & setY( float y );
// Set the z element of a 3-D point
//
inline Point3 & setZ( float z );
// Get the x element of a 3-D point
//
inline float getX( ) const;
// Get the y element of a 3-D point
//
inline float getY( ) const;
// Get the z element of a 3-D point
//
inline float getZ( ) const;
// Set an x, y, or z element of a 3-D point by index
//
inline Point3 & setElem( int idx, float value );
// Get an x, y, or z element of a 3-D point by index
//
inline float getElem( int idx ) const;
// Subscripting operator to set or get an element
//
inline float & operator []( int idx );
// Subscripting operator to get an element
//
inline float operator []( int idx ) const;
// Subtract a 3-D point from another 3-D point
//
inline const Vector3 operator -( const Point3 & pnt ) const;
// Add a 3-D point to a 3-D vector
//
inline const Point3 operator +( const Vector3 & vec ) const;
// Subtract a 3-D vector from a 3-D point
//
inline const Point3 operator -( const Vector3 & vec ) const;
// Perform compound assignment and addition with a 3-D vector
//
inline Point3 & operator +=( const Vector3 & vec );
// Perform compound assignment and subtraction by a 3-D vector
//
inline Point3 & operator -=( const Vector3 & vec );
}
#ifdef __GNUC__
__attribute__ ((aligned(16)))
#endif
;
// Multiply two 3-D points per element
//
inline const Point3 mulPerElem( const Point3 & pnt0, const Point3 & pnt1 );
// Divide two 3-D points per element
// NOTE:
// Floating-point behavior matches standard library function divf4.
//
inline const Point3 divPerElem( const Point3 & pnt0, const Point3 & pnt1 );
// Compute the reciprocal of a 3-D point per element
// NOTE:
// Floating-point behavior matches standard library function recipf4.
//
inline const Point3 recipPerElem( const Point3 & pnt );
// Compute the square root of a 3-D point per element
// NOTE:
// Floating-point behavior matches standard library function sqrtf4.
//
inline const Point3 sqrtPerElem( const Point3 & pnt );
// Compute the reciprocal square root of a 3-D point per element
// NOTE:
// Floating-point behavior matches standard library function rsqrtf4.
//
inline const Point3 rsqrtPerElem( const Point3 & pnt );
// Compute the absolute value of a 3-D point per element
//
inline const Point3 absPerElem( const Point3 & pnt );
// Copy sign from one 3-D point to another, per element
//
inline const Point3 copySignPerElem( const Point3 & pnt0, const Point3 & pnt1 );
// Maximum of two 3-D points per element
//
inline const Point3 maxPerElem( const Point3 & pnt0, const Point3 & pnt1 );
// Minimum of two 3-D points per element
//
inline const Point3 minPerElem( const Point3 & pnt0, const Point3 & pnt1 );
// Maximum element of a 3-D point
//
inline float maxElem( const Point3 & pnt );
// Minimum element of a 3-D point
//
inline float minElem( const Point3 & pnt );
// Compute the sum of all elements of a 3-D point
//
inline float sum( const Point3 & pnt );
// Apply uniform scale to a 3-D point
//
inline const Point3 scale( const Point3 & pnt, float scaleVal );
// Apply non-uniform scale to a 3-D point
//
inline const Point3 scale( const Point3 & pnt, const Vector3 & scaleVec );
// Scalar projection of a 3-D point on a unit-length 3-D vector
//
inline float projection( const Point3 & pnt, const Vector3 & unitVec );
// Compute the square of the distance of a 3-D point from the coordinate-system origin
//
inline float distSqrFromOrigin( const Point3 & pnt );
// Compute the distance of a 3-D point from the coordinate-system origin
//
inline float distFromOrigin( const Point3 & pnt );
// Compute the square of the distance between two 3-D points
//
inline float distSqr( const Point3 & pnt0, const Point3 & pnt1 );
// Compute the distance between two 3-D points
//
inline float dist( const Point3 & pnt0, const Point3 & pnt1 );
// Linear interpolation between two 3-D points
// NOTE:
// Does not clamp t between 0 and 1.
//
inline const Point3 lerp( float t, const Point3 & pnt0, const Point3 & pnt1 );
// Conditionally select between two 3-D points
//
inline const Point3 select( const Point3 & pnt0, const Point3 & pnt1, bool select1 );
#ifdef _VECTORMATH_DEBUG
// Print a 3-D point
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Point3 & pnt );
// Print a 3-D point and an associated string identifier
// NOTE:
// Function is only defined when _VECTORMATH_DEBUG is defined.
//
inline void print( const Point3 & pnt, const char * name );
#endif
// A quaternion in array-of-structures format
//
class Quat
{
float mX;
float mY;
float mZ;
float mW;
public:
// Default constructor; does no initialization
//
inline Quat( ) { };
// Copy a quaternion
//
inline Quat( const Quat & quat );
// Construct a quaternion from x, y, z, and w elements
//
inline Quat( float x, float y, float z, float w );
// Construct a quaternion from a 3-D vector and a scalar
//
inline Quat( const Vector3 & xyz, float w );
// Copy elements from a 4-D vector into a quaternion
//
explicit inline Quat( const Vector4 & vec );
// Convert a rotation matrix to a unit-length quaternion
//
explicit inline Quat( const Matrix3 & rotMat );
// Set all elements of a quaternion to the same scalar value
//
explicit inline Quat( float scalar );
// Assign one quaternion to another
//
inline Quat & operator =( const Quat & quat );
// Set the x, y, and z elements of a quaternion
// NOTE:
// This function does not change the w element.
//
inline Quat & setXYZ( const Vector3 & vec );
// Get the x, y, and z elements of a quaternion
//
inline const Vector3 getXYZ( ) const;
// Set the x element of a quaternion
//
inline Quat & setX( float x );
// Set the y element of a quaternion
//
inline Quat & setY( float y );
// Set the z element of a quaternion
//
inline Quat & setZ( float z );
// Set the w element of a quaternion
//
inline Quat & setW( float w );
// Get the x element of a quaternion
//
inline float getX( ) const;
// Get the y element of a quaternion
//
inline float getY( ) const;
// Get the z element of a quaternion
//
inline float getZ( ) const;
// Get the w element of a quaternion
//
inline float getW( ) const;
// Set an x, y, z, or w element of a quaternion by index
//
inline Quat & setElem( int idx, float value );
// Get an x, y, z, or w element of a quaternion by index
//
inline float getElem( int idx ) const;
// Subscripting operator to set or get an element
//
inline float & operator []( int idx );
// Subscripting operator to get an element
//
inline float operator []( int idx ) const;
// Add two quaternions
//
inline const Quat operator +( const Quat & quat ) const;
// Subtract a quaternion from another quaternion
//
inline const Quat operator -( const Quat & quat ) const;
// Multiply two quaternions
//
inline const Quat operator *( const Quat & quat ) const;
// Multiply a quaternion by a scalar
//
inline const Quat operator *( float scalar ) const;
// Divide a quaternion by a scalar
//
inline const Quat operator /( float scalar ) const;
// Perform compound assignment and addition with a quaternion
//
inline Quat & operator +=( const Quat & quat );
// Perform compound assignment and subtraction by a quaternion
//
inline Quat & operator -=( const Quat & quat );
// Perform compound assignment and multiplication by a quaternion
//
inline Quat & operator *=( const Quat & quat );
// Perform compound assignment and multiplication by a scalar
//
inline Quat & operator *=( float scalar );
// Perform compound assignment and division by a scalar
//
inline Quat & operator /=( float scalar );
// Negate all elements of a quaternion
//
inline const Quat operator -( ) const;
// Construct an identity quaternion
//
static inline const Quat identity( );
// Construct a quaternion to rotate between two unit-length 3-D vectors
// NOTE:
// The result is unpredictable if unitVec0 and unitVec1 point in opposite directions.
//
static inline const Quat rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 );
// Construct a quaternion to rotate around a unit-length 3-D vector
//
static inline const Quat rotation( float radians, const Vector3 & unitVec );
// Construct a quaternion to rotate around the x axis
//
static inline const Quat rotationX( float radians );
// Construct a quaternion to rotate around the y axis
//
static inline const Quat rotationY( float radians );
// Construct a quaternion to rotate around the z axis
//
static inline const Quat rotationZ( float radians );
}
#ifdef __GNUC__
__attribute__ ((aligned(16)))
#endif
;
// Multiply a quaternion by a scalar
//
inline const Quat operator *( float scalar, const Quat & quat );
// Compute the conjugate of a quaternion
//
inline const Quat conj( const Quat & quat );
// Use a unit-length quaternion to rotate a 3-D vector
//
inline const Vector3 rotate( const Quat & unitQuat, const Vector3 & vec );
// Compute the dot product of two quaternions
//
inline float dot( const Quat & quat0, const Quat & quat1 );