-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvec.h
More file actions
1708 lines (1373 loc) · 74.9 KB
/
vec.h
File metadata and controls
1708 lines (1373 loc) · 74.9 KB
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
#pragma once
/**
* Basic Vector Math, Copyright (c) 2015 - Jorma Rebane
* Distributed under MIT Software License
*/
#include "strview.h"
#include "math.h" // min, max, abs, radf, degf, clamp, lerp, lerpInverse
#include <vector> // for vector<Vector3> and vector<int>
#if _MSC_VER
#pragma warning(push)
#pragma warning(disable:4201) // nameless struct/union warning
#endif
namespace rpp
{
///////////////////////////////////////////////////////////////////////////////
/** @brief 2D Vector for UI calculations */
struct RPPAPI Vector2
{
float x, y;
static constexpr Vector2 Zero() { return { 0.0f, 0.0f }; } // 0 0
static constexpr Vector2 One() { return { 1.0f, 1.0f }; } // 1 1
static constexpr Vector2 Right() { return { 1.0f, 0.0f }; } // 1, 0 (X-axis)
static constexpr Vector2 Up() { return { 0.0f, 1.0f }; } // 0, 1 (Y-axis=OpenGL UP)
/** Print the Vector2 */
void print() const;
/** @return Temporary static string from this Vector */
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char(&buffer)[SIZE]) {
return toString(buffer, SIZE);
}
/** @return TRUE if all elements are exactly 0.0f, which implies default initialized.
* To avoid FP errors, use almostZero() if you performed calculations */
bool isZero() const { return x == 0.0f && y == 0.0f; }
bool notZero() const { return x != 0.0f || y != 0.0f; }
bool hasNaN() const { return isnan(x) || isnan(y); }
/** @return TRUE if this vector is almost zero, with all components abs < 0.0001 */
bool almostZero() const;
/** @return TRUE if the vectors are almost equal, with a difference of < 0.0001 */
bool almostEqual(const Vector2& b) const;
/** @brief Set new XY values */
void set(float newX, float newY);
/** @return Length of the vector */
float length() const;
/** @return Squared length of the vector */
float sqlength() const;
/** @brief Normalize this vector */
void normalize();
/** @brief Normalize this vector to the given magnitude */
void normalize(float magnitude);
/** @return A normalized copy of this vector */
Vector2 normalized() const;
Vector2 normalized(float magnitude) const;
/** @return Dot product of two vectors */
float dot(const Vector2& v) const;
/** @return Normalized direction of this vector */
Vector2 direction() const { return normalized(); }
/**
* Treating this as point A, gives the RIGHT direction for vec AB
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2 right(const Vector2& b, float magnitude = 1.0f) const;
/**
* Treating this as point A, gives the LEFT direction for vec AB
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2 left(const Vector2& b, float magnitude = 1.0f) const;
/**
* Assuming this is already a direction vector, gives the perpendicular RIGHT direction vector
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2 right(float magnitude = 1.0f) const;
/**
* Assuming this is already a direction vector, gives the perpendicular LEFT direction vector
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2 left(float magnitude = 1.0f) const;
Vector2& operator+=(float f) { x+=f; y+=f; return *this; }
Vector2& operator-=(float f) { x-=f; y-=f; return *this; }
Vector2& operator*=(float f) { x*=f; y*=f; return *this; }
Vector2& operator/=(float f) { x/=f; y/=f; return *this; }
Vector2& operator+=(const Vector2& b) { x+=b.x; y+=b.y; return *this; }
Vector2& operator-=(const Vector2& b) { x-=b.x; y-=b.y; return *this; }
Vector2& operator*=(const Vector2& b) { x*=b.x; y*=b.y; return *this; }
Vector2& operator/=(const Vector2& b) { x/=b.x; y/=b.y; return *this; }
Vector2 operator+ (const Vector2& b) const { return { x+b.x, y+b.y }; }
Vector2 operator- (const Vector2& b) const { return { x-b.x, y-b.y }; }
Vector2 operator* (const Vector2& b) const { return { x*b.x, y*b.y }; }
Vector2 operator/ (const Vector2& b) const { return { x/b.x, y/b.y }; }
Vector2 operator- () const { return {-x, -y}; }
bool operator==(const Vector2& b) const { return x == b.x && y == b.y; }
bool operator!=(const Vector2& b) const { return x != b.x || y != b.y; }
};
constexpr Vector2 vec2(float xy) { return { xy, xy }; }
inline Vector2 operator+(const Vector2& a, float f) { return { a.x+f, a.y+f }; }
inline Vector2 operator-(const Vector2& a, float f) { return { a.x-f, a.y-f }; }
inline Vector2 operator*(const Vector2& a, float f) { return { a.x*f, a.y*f }; }
inline Vector2 operator/(const Vector2& a, float f) { return { a.x/f, a.y/f }; }
inline Vector2 operator+(float f, const Vector2& a) { return { f+a.x, f+a.y }; }
inline Vector2 operator-(float f, const Vector2& a) { return { f-a.x, f-a.y }; }
inline Vector2 operator*(float f, const Vector2& a) { return { f*a.x, f*a.y }; }
inline Vector2 operator/(float f, const Vector2& a) { return { f/a.x, f/a.y }; }
constexpr Vector2 clamp(const Vector2& value, const Vector2& min, const Vector2& max)
{
return { value.x < min.x ? min.x : (value.x < max.x ? value.x : max.x),
value.y < min.y ? min.y : (value.y < max.y ? value.y : max.y) };
}
constexpr Vector2 lerp(float position, const Vector2& start, const Vector2& end)
{
return { start.x + (end.x - start.x)*position,
start.y + (end.y - start.y)*position };
}
///////////////////////////////////////////////////////////////////////////////
/** @brief 2D Vector for UI calculations */
struct RPPAPI Vector2d
{
double x, y;
static constexpr Vector2d Zero() { return { 0.0, 0.0 }; } // 0 0
static constexpr Vector2d One() { return { 1.0, 1.0 }; } // 1 1
static constexpr Vector2d Right() { return { 1.0, 0.0 }; } // 1, 0 (X-axis)
static constexpr Vector2d Up() { return { 0.0, 1.0 }; } // 0, 1 (Y-axis=OpenGL UP)
/** Print the Vector2 */
void print() const;
/** @return Temporary static string from this Vector */
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char(&buffer)[SIZE]) {
return toString(buffer, SIZE);
}
/** @return TRUE if all elements are exactly 0.0f, which implies default initialized.
* To avoid FP errors, use almostZero() if you performed calculations */
bool isZero() const { return x == 0.0 && y == 0.0; }
bool notZero() const { return x != 0.0 || y != 0.0; }
bool hasNaN() const { return isnan(x) || isnan(y); }
/** @return TRUE if this vector is almost zero, with all components abs < 0.0001 */
bool almostZero() const;
/** @return TRUE if the vectors are almost equal, with a difference of < 0.0001 */
bool almostEqual(const Vector2d& b) const;
/** @brief Set new XY values */
void set(double newX, double newY);
/** @return Length of the vector */
double length() const;
/** @return Squared length of the vector */
double sqlength() const;
/** @brief Normalize this vector */
void normalize();
/** @brief Normalize this vector to the given magnitude */
void normalize(double magnitude);
/** @return A normalized copy of this vector */
Vector2d normalized() const;
Vector2d normalized(double magnitude) const;
/** @return Dot product of two vectors */
double dot(const Vector2d& v) const;
/** @return Normalized direction of this vector */
Vector2d direction() const { return normalized(); }
/**
* Treating this as point A, gives the RIGHT direction for vec AB
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2d right(const Vector2d& b, double magnitude = 1.0) const;
/**
* Treating this as point A, gives the LEFT direction for vec AB
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2d left(const Vector2d& b, double magnitude = 1.0) const;
/**
* Assuming this is already a direction vector, gives the perpendicular RIGHT direction vector
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2d right(double magnitude = 1.0) const;
/**
* Assuming this is already a direction vector, gives the perpendicular LEFT direction vector
* @note THIS ASSUMES OPENGL COORDINATE SYSTEM
*/
Vector2d left(double magnitude = 1.0) const;
Vector2d& operator+=(double f) { x+=f; y+=f; return *this; }
Vector2d& operator-=(double f) { x-=f; y-=f; return *this; }
Vector2d& operator*=(double f) { x*=f; y*=f; return *this; }
Vector2d& operator/=(double f) { x/=f; y/=f; return *this; }
Vector2d& operator+=(const Vector2d& b) { x+=b.x; y+=b.y; return *this; }
Vector2d& operator-=(const Vector2d& b) { x-=b.x; y-=b.y; return *this; }
Vector2d& operator*=(const Vector2d& b) { x*=b.x; y*=b.y; return *this; }
Vector2d& operator/=(const Vector2d& b) { x/=b.x; y/=b.y; return *this; }
Vector2d operator+ (const Vector2d& b) const { return { x+b.x, y+b.y }; }
Vector2d operator- (const Vector2d& b) const { return { x-b.x, y-b.y }; }
Vector2d operator* (const Vector2d& b) const { return { x*b.x, y*b.y }; }
Vector2d operator/ (const Vector2d& b) const { return { x/b.x, y/b.y }; }
Vector2d operator- () const { return {-x, -y}; }
bool operator==(const Vector2d& b) const { return x == b.x && y == b.y; }
bool operator!=(const Vector2d& b) const { return x != b.x || y != b.y; }
};
constexpr Vector2d vec2d(double xy) { return { xy, xy }; }
inline Vector2d operator+(const Vector2d& a, double f) { return { a.x+f, a.y+f }; }
inline Vector2d operator-(const Vector2d& a, double f) { return { a.x-f, a.y-f }; }
inline Vector2d operator*(const Vector2d& a, double f) { return { a.x*f, a.y*f }; }
inline Vector2d operator/(const Vector2d& a, double f) { return { a.x/f, a.y/f }; }
inline Vector2d operator+(double f, const Vector2d& a) { return { f+a.x, f+a.y }; }
inline Vector2d operator-(double f, const Vector2d& a) { return { f-a.x, f-a.y }; }
inline Vector2d operator*(double f, const Vector2d& a) { return { f*a.x, f*a.y }; }
inline Vector2d operator/(double f, const Vector2d& a) { return { f/a.x, f/a.y }; }
constexpr Vector2d clamp(const Vector2d& value, const Vector2d& min, const Vector2d& max)
{
return { value.x < min.x ? min.x : (value.x < max.x ? value.x : max.x),
value.y < min.y ? min.y : (value.y < max.y ? value.y : max.y) };
}
constexpr Vector2d lerp(double position, const Vector2d& start, const Vector2d& end)
{
return { start.x + (end.x - start.x)*position,
start.y + (end.y - start.y)*position };
}
////////////////////////////////////////////////////////////////////////////////
/**
* @brief Utility for dealing with integer-only points. Pretty rare, but useful.
*/
struct RPPAPI Point
{
int x, y;
static constexpr Point Zero() { return { 0, 0 }; } // 0 0
explicit operator bool() const { return x || y; }
bool operator!() const { return !x && !y; }
void set(int nx, int ny) { x = nx; y = ny; }
bool isZero() const { return !x && !y; }
bool notZero() const { return x || y; }
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char(&buffer)[SIZE]) {
return toString(buffer, SIZE);
}
Point& operator+=(int i) { x+=i; y+=i; return *this; }
Point& operator-=(int i) { x-=i; y-=i; return *this; }
Point& operator*=(int i) { x*=i; y*=i; return *this; }
Point& operator/=(int i) { x/=i; y/=i; return *this; }
Point& operator*=(float f) { x = int(x*f); y = int(y*f); return *this; }
Point& operator/=(float f) { x = int(x/f); y = int(y/f); return *this; }
Point& operator+=(const Point& b) { x+=b.x; y+=b.y; return *this; }
Point& operator-=(const Point& b) { x-=b.x; y-=b.y; return *this; }
Point& operator*=(const Point& b) { x*=b.x; y*=b.y; return *this; }
Point& operator/=(const Point& b) { x/=b.x; y/=b.y; return *this; }
Point operator+ (const Point& b) const { return { x+b.x, y+b.y }; }
Point operator- (const Point& b) const { return { x-b.x, y-b.y }; }
Point operator* (const Point& b) const { return { x*b.x, y*b.y }; }
Point operator/ (const Point& b) const { return { x/b.x, y/b.y }; }
Point operator- () const { return {-x, -y}; }
bool operator==(const Point& b) const { return x == b.x && y == b.y; }
bool operator!=(const Point& b) const { return x != b.x || y != b.y; }
};
constexpr RPPAPI Point point2(int xy) { return { xy, xy }; }
inline Point operator+(const Point& a, int i) { return { a.x+i, a.y+i }; }
inline Point operator-(const Point& a, int i) { return { a.x-i, a.y-i }; }
inline Point operator*(const Point& a, int i) { return { a.x*i, a.y*i }; }
inline Point operator/(const Point& a, int i) { return { a.x/i, a.y/i }; }
inline Point operator+(int i, const Point& a) { return { i+a.x, i+a.y }; }
inline Point operator-(int i, const Point& a) { return { i-a.x, i-a.y }; }
inline Point operator*(int i, const Point& a) { return { i*a.x, i*a.y }; }
inline Point operator/(int i, const Point& a) { return { i/a.x, i/a.y }; }
////////////////////////////////////////////////////////////////////////////////
/** @brief Utility for dealing with 2D Rects */
struct RPPAPI RectF
{
union {
struct { float x, y, w, h; };
struct { Vector2 pos; Vector2 size; };
};
static constexpr RectF Zero() { return { 0, 0, 0, 0 }; } // 0 0 0 0
constexpr RectF() : x{ 0 }, y{ 0 }, w{ 0 }, h{ 0 } {}
constexpr RectF(float x, float y, float w, float h) : x{x}, y{y}, w{w}, h{h} {}
constexpr RectF(Vector2 pos, Vector2 size) : pos{pos}, size{size} {}
constexpr RectF(Vector2 pos, float w, float h) : pos{ pos }, size{ w, h } {}
constexpr RectF(float x, float y, Vector2 size) : pos{ x, y }, size{ size } {}
/** Print the RectF */
void print() const;
/** @return Temporary static string from this RectF in the form of "{pos %g;%g size %g;%g}" */
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int bufSize) const;
template<int N> char* toString(char(&b)[N]) { return toString(b, N); }
float area() const { return w * h; }
float left() const { return x; }
float top() const { return y; }
float right() const { return x + w; }
float bottom() const { return y + h; }
const Vector2& topleft() const { return pos; }
Vector2 botright() const { return { x+w, y+h }; }
Vector2 center() const { return { x + w/2, y + h/2 }; }
float center_x() const { return x + w/2; }
float center_y() const { return y + h/2; }
/** @return TRUE if this RectF is equal to RectF::Zero */
bool isZero() const { return !x && !y && !w && !h; }
/** @return TRUE if this RectF is NOT equal to RectF::Zero */
bool notZero() const { return w || h || x || y; }
/** @return True if point is inside this RectF */
bool hitTest(const Vector2& position) const;
bool hitTest(float xPos, float yPos) const;
/** @return TRUE if r is completely inside this RectF */
bool hitTest(const RectF& r) const;
/** @return TRUE if this RectF and r intersect */
bool intersectsWith(const RectF& r) const;
/** @brief Extrude the bounds of this RectF by a positive or negative amount */
void extrude(float extrude);
void extrude(const Vector2& extrude);
RectF extruded(float extrude) const {
RectF r = *this;
r.extrude(extrude);
return *this;
}
RectF& operator+=(const RectF& b) { join(b); return *this; }
// joins two rects, resulting in a RectF that fits them both
RectF joined(const RectF& b) const;
// modifies this RectF by joining RectF b with this RectF
void join(const RectF& b);
// clips this RectF with a potentially smaller frame
// this RectF will then fit inside the frame RectF
void clip(const RectF& frame);
RectF operator+(const RectF& b) const { return joined(b); }
bool operator==(const RectF& r) const { return x == r.x && y == r.y && w == r.w && h == r.h; }
bool operator!=(const RectF& r) const { return x != r.x || y != r.y || w != r.w || h != r.h; }
};
inline RectF operator+(const RectF& a, float f) { return{ a.x+f, a.y+f, a.w, a.h }; }
inline RectF operator-(const RectF& a, float f) { return{ a.x-f, a.y-f, a.w, a.h }; }
inline RectF operator*(const RectF& a, float f) { return{ a.x, a.y, a.w*f, a.h*f }; }
inline RectF operator/(const RectF& a, float f) { return{ a.x, a.y, a.w/f, a.h/f }; }
inline RectF operator+(float f, const RectF& a) { return{ f+a.x, f+a.y, a.w, a.h }; }
inline RectF operator-(float f, const RectF& a) { return{ f-a.x, f-a.y, a.w, a.h }; }
inline RectF operator*(float f, const RectF& a) { return{ a.x, a.y, f*a.w, f*a.h }; }
inline RectF operator/(float f, const RectF& a) { return{ a.x, a.y, f/a.w, f/a.h }; }
using Rect = RectF;
///////////////////////////////////////////////////////////////////////////////
struct RPPAPI Recti
{
union {
struct { int x, y, w, h; };
struct { Point pos; Point size; };
};
static constexpr Recti Zero() { return { 0, 0, 0, 0 }; } // 0 0 0 0
constexpr Recti() : x{ 0 }, y{ 0 }, w{ 0 }, h{ 0 } {}
constexpr Recti(int x, int y, int w, int h) : x{x}, y{y}, w{w}, h{h} {}
constexpr Recti(Point pos, Point size) : x{ pos.x }, y{ pos.y }, w{ size.x }, h{ size.y } {}
constexpr Recti(Point pos, int w, int h) : x{ pos.x }, y{ pos.y }, w{ w }, h{ h } {}
constexpr Recti(int x, int y, Point size) : x{ x }, y{ y }, w{ size.x }, h{ size.y } {}
/** Print the Recti */
void print() const;
/** @return Temporary static string from this Recti in the form of "{pos %d;%d size %d;%d}" */
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int bufSize) const;
template<int N> char* toString(char(&b)[N]) { return toString(b, N); }
int area() const { return w * h; }
int left() const { return x; }
int top() const { return y; }
int right() const { return x + w; }
int bottom() const { return y + h; }
const Point& topleft() const { return pos; }
Point botright() const { return { x+w, y+h }; }
Point center() const { return { x + w/2, y + h/2 }; }
int center_x() const { return x + w/2; }
int center_y() const { return y + h/2; }
/** @return TRUE if this Recti is equal to Recti::Zero */
bool isZero() const { return !x && !y && !w && !h; }
/** @return TRUE if this Recti is NOT equal to Recti::Zero */
bool notZero() const { return w || h || x || y; }
/** @return TRUE if this Recti has a valid W and H */
explicit operator bool() const { return w > 0 && h > 0; }
/** @return True if point is inside this Recti */
bool hitTest(const Point& position) const;
bool hitTest(int xPos, int yPos) const;
/** @return TRUE if r is completely inside this Recti */
bool hitTest(const Recti& r) const;
/** @return TRUE if this Recti and r intersect */
bool intersectsWith(const Recti& r) const;
/** @brief Extrude the bounds of this rect by a positive or negative amount */
void extrude(int extrude);
void extrude(const Point& extrude);
Recti extruded(int extrude) const {
Recti r = *this;
r.extrude(extrude);
return *this;
}
Recti& operator+=(const Recti& b) { join(b); return *this; }
// joins two rects, resulting in a Recti that fits them both
Recti joined(const Recti& b) const;
// modifies this Recti by joining Recti b with this Recti
void join(const Recti& b);
// clips this Recti with a potentially smaller frame
// this Recti will then fit inside the frame Recti
void clip(const Recti& frame);
Recti operator+(const Recti& b) const { return joined(b); }
bool operator==(const Recti& r) const { return x == r.x && y == r.y && w == r.w && h == r.h; }
bool operator!=(const Recti& r) const { return x != r.x || y != r.y || w != r.w || h != r.h; }
};
inline Recti operator+(const Recti& a, int i) { return{ a.x+i, a.y+i, a.w, a.h }; }
inline Recti operator-(const Recti& a, int i) { return{ a.x-i, a.y-i, a.w, a.h }; }
inline Recti operator*(const Recti& a, int i) { return{ a.x, a.y, a.w*i, a.h*i }; }
inline Recti operator/(const Recti& a, int i) { return{ a.x, a.y, a.w/i, a.h/i }; }
inline Recti operator+(int i, const Recti& a) { return{ i+a.x, i+a.y, a.w, a.h }; }
inline Recti operator-(int i, const Recti& a) { return{ i-a.x, i-a.y, a.w, a.h }; }
inline Recti operator*(int i, const Recti& a) { return{ a.x, a.y, i*a.w, i*a.h }; }
inline Recti operator/(int i, const Recti& a) { return{ a.x, a.y, i/a.w, i/a.h }; }
///////////////////////////////////////////////////////////////////////////////
struct Vector3d;
/**
* 3D Vector for matrix calculations
* The coordinate system assumed in UP, FORWARD, RIGHT is OpenGL coordinate system:
* +X is Right on the screen
* +Y is Up on the screen
* +Z is Forward INTO the screen
*/
struct RPPAPI Vector3
{
union {
struct { float x, y, z; };
struct { float r, g, b; };
};
static constexpr Vector3 Zero() { return { 0.0f, 0.0f, 0.0f }; } // 0 0 0
static constexpr Vector3 One() { return { 1.0f, 1.0f, 1.0f }; } // 1 1 1
static constexpr Vector3 Left() { return { -1.0f, 0.0f, 0.0f }; } // -X axis
static constexpr Vector3 Right() { return { +1.0f, 0.0f, 0.0f }; } // +X axis
static constexpr Vector3 Up() { return { 0.0f, +1.0f, 0.0f }; } // +Y axis
static constexpr Vector3 Down() { return { 0.0f, -1.0f, 0.0f }; } // -Y axis
static constexpr Vector3 Forward() { return { 0.0f, 0.0f, +1.0f }; } // +Z axis
static constexpr Vector3 Backward() { return { 0.0f, 0.0f, -1.0f }; } // -Z axis
static constexpr Vector3 XAxis() { return { +1.0f, 0.0f, 0.0f }; } // +X axis
static constexpr Vector3 YAxis() { return { 0.0f, +1.0f, 0.0f }; } // +Y axis
static constexpr Vector3 ZAxis() { return { 0.0f, 0.0f, +1.0f }; } // +Z axis
static constexpr Vector3 White() { return { 1.0f, 1.0f, 1.0f }; } // RGB 1 1 1
static constexpr Vector3 Black() { return { 0.0f, 0.0f, 0.0f }; } // RGB 0 0 0
static constexpr Vector3 Red() { return { 1.0f, 0.0f, 0.0f }; } // RGB 1 0 0
static constexpr Vector3 Green() { return { 0.0f, 1.0f, 0.0f }; } // RGB 0 1 0
static constexpr Vector3 Blue() { return { 0.0f, 0.0f, 1.0f }; } // RGB 0 0 1
static constexpr Vector3 Yellow() { return { 1.0f, 1.0f, 0.0f }; } // 1 1 0
static constexpr Vector3 Orange() { return { 1.0f, 0.50196f, 0.0f }; } // 1 0.502 0; 255 128 0
static constexpr Vector3 Magenta() { return { 1.0f, 0.0f, 1.0f }; } // 1 0 1
static constexpr Vector3 Cyan() { return { 0.0f, 1.0f, 1.0f }; } // 0 1 1
static constexpr Vector3 SweetGreen() { return { 0.337f, 0.737f, 0.223f }; } // 86, 188, 57
static constexpr Vector3 CornflowerBlue() { return { 0.33f, 0.66f, 1.0f }; } // #55AAFF 85, 170, 255
#if __clang__ || _MSC_VER
Vector3() = default;
constexpr Vector3(float x, float y, float z) : x{x}, y{y}, z{z} {}
#endif
explicit operator Vector3d() const;
/** @brief Set new XYZ values */
void set(float newX, float newY, float newZ);
/** @return Length of the vector */
float length() const;
/** @return Squared length of the vector */
float sqlength() const;
/** @return Absolute distance from this vec3 to target vec3 */
float distanceTo(Vector3 v) const;
/** @return Squared distance from this vec3 to target vec3 */
float sqDistanceTo(Vector3 v) const;
/** @brief Normalize this vector */
void normalize();
void normalize(float magnitude);
/** @return A normalized copy of this vector */
Vector3 normalized() const;
Vector3 normalized(float magnitude) const;
/** @return Cross product with another vector */
Vector3 cross(Vector3 v) const;
/** @return Dot product with another vector */
float dot(Vector3 v) const;
/**
* Creates a mask vector for each component
* x = almostZero(x) ? 1.0f : 0.0f;
*/
Vector3 mask() const;
/**
* @return Assuming this is a direction vector, gives XYZ Euler rotation in RADIANS
* X: Roll
* Y: Pitch
* Z: Yaw
*/
Vector3 toEulerAngles() const;
/**
* Transforms this Vector3 with a transformation functor
* @param componentTransform `float transform(float v)`
*/
template<class Transform> void transform(const Transform& componentTransform)
{
x = componentTransform(x);
y = componentTransform(y);
z = componentTransform(z);
}
void print() const;
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char(&buffer)[SIZE]) const {
return toString(buffer, SIZE);
}
/** @return TRUE if all elements are exactly 0.0f, which implies default initialized.
* To avoid FP errors, use almostZero() if you performed calculations */
bool isZero() const { return x == 0.0f && y == 0.0f && z == 0.0f; }
bool notZero() const { return x != 0.0f || y != 0.0f || z != 0.0f; }
bool hasNaN() const { return isnan(x) || isnan(y) || isnan(z); }
/** @return TRUE if this vector is almost zero, with all components abs < 0.0001 */
bool almostZero() const;
/** @return TRUE if the vectors are almost equal, with a difference of < 0.0001 */
bool almostEqual(Vector3 v) const;
Vector3& operator+=(float f) { x+=f; y+=f; z+=f; return *this; }
Vector3& operator-=(float f) { x-=f; y-=f; z-=f; return *this; }
Vector3& operator*=(float f) { x*=f; y*=f; z*=f; return *this; }
Vector3& operator/=(float f) { x/=f; y/=f; z/=f; return *this; }
Vector3& operator+=(const Vector3& v) { x+=v.x; y+=v.y; z+=v.z; return *this; }
Vector3& operator-=(const Vector3& v) { x-=v.x; y-=v.y; z-=v.z; return *this; }
Vector3& operator*=(const Vector3& v) { x*=v.x; y*=v.y; z*=v.z; return *this; }
Vector3& operator/=(const Vector3& v) { x/=v.x; y/=v.y; z/=v.z; return *this; }
Vector3 operator+ (const Vector3& v) const { return { x+v.x, y+v.y, z+v.z }; }
Vector3 operator- (const Vector3& v) const { return { x-v.x, y-v.y, z-v.z }; }
Vector3 operator* (const Vector3& v) const { return { x*v.x, y*v.y, z*v.z }; }
Vector3 operator/ (const Vector3& v) const { return { x/v.x, y/v.y, z/v.z }; }
Vector3 operator- () const { return {-x, -y, -z}; }
bool operator==(const Vector3& v) const { return x == v.x && y == v.y && z == v.z; }
bool operator!=(const Vector3& v) const { return x != v.x || y != v.y || z != v.z; }
static Vector3 smoothColor(Vector3 src, Vector3 dst, float ratio);
// don't use macros plz :)
#undef RGB
/** @return A 3-component float color from integer RGBA color */
static constexpr Vector3 RGB(int r, int g, int b)
{
return { r / 255.0f, g / 255.0f, b / 255.0f };
}
/**
* Parses any type of color string. Supported:
* -) RGB HEX color strings: #rrggbb
* -) Named color strings: 'orange'
* -) RGB integer values: 255 0 128
* -) RGB float values: 0.1 0.2 0.5
* @note All HEX and NUMBER color fields are optional.
* Color channel default is 0
* Example '#aa' would give 170 0 0 and '0.1' would give 25 0 0
* @return Default color White or parsed color in normalized float value range [0.0 ... 1.0]
*/
static Vector3 parseColor(const strview& s) noexcept;
/**
* Some common 3D vector conversions
* Some conversions are two way <->, but we still provide duplicate overloads for consistency
*
* This Vector library is based on OpenGL coordsys -- important when dealing with Matrix/Vector4(quat).
*
* OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
*
*/
// OpenGL to OpenCV coordinate conversion. Works both ways: GL <-> CV
// OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
// OpenCV coordsys: +X is Right on the screen, +Y is Down on the screen, +Z is INTO the screen
Vector3 convertGL2CV() const noexcept { return { x, -y, z }; }
Vector3 convertCV2GL() const noexcept { return { x, -y, z }; }
// 3ds Max to OpenCV coordinate conversion
// 3ds Max coordsys: +X is Right on the screen, +Y is INTO the screen, +Z is Up
// OpenCV coordsys: +X is Right on the screen, +Y is Down on the screen, +Z is INTO the screen
Vector3 convertMax2CV() const noexcept { return { x, -z, y }; }
Vector3 convertCV2Max() const noexcept { return { x, z, -y }; }
// OpenGL to 3ds Max coordinate conversion
// 3ds Max coordsys: +X is Right on the screen, +Y is INTO the screen, +Z is Up
// OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
Vector3 convertMax2GL() const noexcept { return { x, z, y }; }
Vector3 convertGL2Max() const noexcept { return { x, z, y }; }
// OpenGL to iPhone coordinate conversion
// OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
// iPhone coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is OUT of the screen
Vector3 convertGL2IOS() const noexcept { return { x, y, -z }; }
Vector3 convertIOS2GL() const noexcept { return { x, y, -z }; }
// Blender to OpenGL coordinate conversion
// Blender coordsys: +X is Right on the screen, +Y is INTO the screen, +Z is Up on the screen
// OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
Vector3 convertBlender2GL() const noexcept { return { x, z, y }; }
Vector3 convertGL2Blender() const noexcept { return { x, z, y }; }
// Blender to iPhone coordinate conversion
// Blender coordsys: +X is Right on the screen, +Y is INTO the screen, +Z is Up on the screen
// iPhone coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is OUT of the screen
Vector3 convertBlender2IOS() const noexcept { return { x, z, -y }; }
Vector3 convertIOS2Blender() const noexcept { return { x, -z, y }; }
// DirectX to OpenGL coordinate conversion
// DirectX default coordsys: +X is Right on the screen, +Y is Up, +Z is INTO the screen
// -- D3D is identical to modern OpenGL coordsys --
Vector3 convertDX2GL() const noexcept { return *this; }
Vector3 convertGL2DX() const noexcept { return *this; }
// Unreal Engine 4 to openGL coordinate conversion
// UE4 coordsys: +X is INTO the screen, +Y is Right on the screen, +Z is Up
Vector3 convertUE2GL() const noexcept { return { y, z, x }; }
Vector3 convertGL2UE() const noexcept { return { z, x, y }; }
};
constexpr Vector3 vec3(Vector2 xy, float z) { return { xy.x, xy.y, z }; }
constexpr Vector3 vec3(float x, Vector2 yz) { return { x, yz.x, yz.y }; }
constexpr Vector3 vec3(float xyz) { return { xyz, xyz, xyz }; }
inline Vector3 operator+(const Vector3& a, float f) { return { a.x+f, a.y+f, a.z+f }; }
inline Vector3 operator-(const Vector3& a, float f) { return { a.x-f, a.y-f, a.z-f }; }
inline Vector3 operator*(const Vector3& a, float f) { return { a.x*f, a.y*f, a.z*f }; }
inline Vector3 operator/(const Vector3& a, float f) { return { a.x/f, a.y/f, a.z/f }; }
inline Vector3 operator+(float f, const Vector3& a) { return { f+a.x, f+a.y, f+a.z }; }
inline Vector3 operator-(float f, const Vector3& a) { return { f-a.x, f-a.y, f-a.z }; }
inline Vector3 operator*(float f, const Vector3& a) { return { f*a.x, f*a.y, f*a.z }; }
inline Vector3 operator/(float f, const Vector3& a) { return { f/a.x, f/a.y, f/a.z }; }
constexpr Vector3 clamp(const Vector3& value, const Vector3& min, const Vector3& max)
{
return { value.x < min.x ? min.x : (value.x < max.x ? value.x : max.x),
value.y < min.y ? min.y : (value.y < max.y ? value.y : max.y),
value.z < min.z ? min.z : (value.z < max.z ? value.z : max.z) };
}
constexpr Vector3 lerp(float position, const Vector3& start, const Vector3& end)
{
return { start.x + (end.x - start.x)*position,
start.y + (end.y - start.y)*position,
start.z + (end.z - start.z)*position };
}
////////////////////////////////////////////////////////////////////////////////
struct RPPAPI Vector3d
{
double x, y, z;
static constexpr Vector3d Zero() { return { 0.0f, 0.0f, 0.0f }; }
explicit operator Vector3() const { return {float(x), float(y), float(z)}; }
/** @brief Set new XYZ values */
void set(double newX, double newY, double newZ);
/** @return Length of the vector */
double length() const;
/** @return Squared length of the vector */
double sqlength() const;
/** @return Absolute distance from this vec3 to target vec3 */
double distanceTo(const Vector3d& v) const;
/** @brief Normalize this vector */
void normalize();
void normalize(const double magnitude);
/** @return A normalized copy of this vector */
Vector3d normalized() const;
Vector3d normalized(const double magnitude) const;
/** @return Cross product with another vector */
Vector3d cross(const Vector3d& b) const;
/** @return Dot product with another vector */
double dot(const Vector3d& b) const;
void print() const;
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char(&buffer)[SIZE]) const {
return toString(buffer, SIZE);
}
/** @return TRUE if all elements are exactly 0.0f, which implies default initialized.
* To avoid FP errors, use almostZero() if you performed calculations */
bool isZero() const { return x == 0.0 && y == 0.0 && z == 0.0; }
bool notZero() const { return x != 0.0 || y != 0.0 || z != 0.0; }
bool hasNaN() const { return isnan(x) || isnan(y) || isnan(z); }
/** @return TRUE if this vector is almost zero, with all components abs < 0.0001 */
bool almostZero() const;
/** @return TRUE if the vectors are almost equal, with a difference of < 0.0001 */
bool almostEqual(const Vector3d& v) const;
Vector3d& operator+=(double f) { x+=f; y+=f; z+=f; return *this; }
Vector3d& operator-=(double f) { x-=f; y-=f; z-=f; return *this; }
Vector3d& operator*=(double f) { x*=f; y*=f; z*=f; return *this; }
Vector3d& operator/=(double f) { x/=f; y/=f; z/=f; return *this; }
Vector3d& operator+=(const Vector3d& b) { x+=b.x; y+=b.y; z+=b.z; return *this; }
Vector3d& operator-=(const Vector3d& b) { x-=b.x; y-=b.y; z-=b.z; return *this; }
Vector3d& operator*=(const Vector3d& b) { x*=b.x; y*=b.y; z*=b.z; return *this; }
Vector3d& operator/=(const Vector3d& b) { x/=b.x; y/=b.y; z/=b.z; return *this; }
Vector3d operator+ (const Vector3d& b) const { return { x+b.x, y+b.y, z+b.z }; }
Vector3d operator- (const Vector3d& b) const { return { x-b.x, y-b.y, z-b.z }; }
Vector3d operator* (const Vector3d& b) const { return { x*b.x, y*b.y, z*b.z }; }
Vector3d operator/ (const Vector3d& b) const { return { x/b.x, y/b.y, z/b.z }; }
Vector3d operator- () const { return {-x, -y, -z}; }
bool operator==(const Vector3d& v) const { return x == v.x && y == v.y && z == v.z; }
bool operator!=(const Vector3d& v) const { return x != v.x || y != v.y || z != v.z; }
/**
* Some common 3D vector conversions
* Some conversions are two way <->, but we still provide duplicate overloads for consistency
*
* This Vector library is based on OpenGL coordsys -- important when dealing with Matrix/Vector4(quat).
*
* OpenGL coordsys: +X is Right on the screen, +Y is Up on the screen, +Z is Forward INTO the screen
*
*/
// OpenGL to OpenCV coordinate conversion. Works both ways: GL <-> CV
// OpenCV coordsys: +X is Right on the screen, +Y is Down on the screen, +Z is INTO the screen
Vector3d convertGL2CV() const noexcept { return { x, -y, z }; }
Vector3d convertCV2GL() const noexcept { return { x, -y, z }; }
};
constexpr Vector3d vec3d(double xyz) { return { xyz, xyz, xyz }; }
inline Vector3d operator+(const Vector3d& a, double f) { return { a.x+f, a.y+f, a.z+f }; }
inline Vector3d operator-(const Vector3d& a, double f) { return { a.x-f, a.y-f, a.z-f }; }
inline Vector3d operator*(const Vector3d& a, double f) { return { a.x*f, a.y*f, a.z*f }; }
inline Vector3d operator/(const Vector3d& a, double f) { return { a.x/f, a.y/f, a.z/f }; }
inline Vector3d operator+(double f, const Vector3d& a) { return { f+a.x, f+a.y, f+a.z }; }
inline Vector3d operator-(double f, const Vector3d& a) { return { f-a.x, f-a.y, f-a.z }; }
inline Vector3d operator*(double f, const Vector3d& a) { return { f*a.x, f*a.y, f*a.z }; }
inline Vector3d operator/(double f, const Vector3d& a) { return { f/a.x, f/a.y, f/a.z }; }
constexpr Vector3d clamp(const Vector3d& value, const Vector3d& min, const Vector3d& max)
{
return { value.x < min.x ? min.x : (value.x < max.x ? value.x : max.x),
value.y < min.y ? min.y : (value.y < max.y ? value.y : max.y),
value.z < min.z ? min.z : (value.z < max.z ? value.z : max.z) };
}
constexpr Vector3d lerp(double position, const Vector3d& start, const Vector3d& end)
{
return { start.x + (end.x - start.x)*position,
start.y + (end.y - start.y)*position,
start.z + (end.z - start.z)*position };
}
inline Vector3::operator Vector3d() const { return { double(x), double(y), double(z) }; }
////////////////////////////////////////////////////////////////////////////////
/**
* @note This is meant for use along with Matrix4
* It has no intrinsic value as stand-alone
*/
struct RPPAPI AngleAxis
{
Vector3 axis = Vector3::Zero(); // rotation axis
float angle = 0.0f; // rotation angle in DEGREES
/**
* @return The rotation axis and angle between two vectors
*/
static AngleAxis fromVectors(Vector3 a, Vector3 b);
};
////////////////////////////////////////////////////////////////////////////////
struct RPPAPI Matrix3;
struct RPPAPI Matrix4;
/** @brief 4D Vector for matrix calculations and quaternion rotations */
struct RPPAPI Vector4
{
union {
struct { float x, y, z, w; };
struct { float r, g, b, a; };
struct { Vector2 xy; Vector2 zw; };
struct { Vector3 xyz; };
struct { Vector3 rgb; };
};
static constexpr Vector4 Zero() { return { 0.0f, 0.0f, 0.0f, 0.0f }; } // XYZW 0 0 0 0
static constexpr Vector4 One() { return { 1.0f, 1.0f, 1.0f, 1.0f }; } // XYZW 1 1 1 1
static constexpr Vector4 White() { return { 1.0f, 1.0f, 1.0f, 1.0f }; } // RGBA 1 1 1 1
static constexpr Vector4 Black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; } // RGBA 0 0 0 1
static constexpr Vector4 Red() { return { 1.0f, 0.0f, 0.0f, 1.0f }; } // RGBA 1 0 0 1
static constexpr Vector4 Green() { return { 0.0f, 1.0f, 0.0f, 1.0f }; } // RGBA 0 1 0 1
static constexpr Vector4 Blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; } // RGBA 0 0 1 1
static constexpr Vector4 Yellow() { return { 1.0f, 1.0f, 0.0f, 1.0f }; } // 1 1 0 1
static constexpr Vector4 Orange() { return { 1.0f, 0.50196f, 0.0f, 1.0f }; } // 1 0.502 0 1; 255 128 0 255
static constexpr Vector4 Magenta() { return { 1.0f, 0.0f, 1.0f, 1.0f }; } // 1 0 1 1
static constexpr Vector4 Cyan() { return { 0.0f, 1.0f, 1.0f, 1.0f }; } // 0 1 1 1
static constexpr Vector4 SweetGreen() { return { 0.337f, 0.737f, 0.223f, 1.0f }; } // 86, 188, 57
static constexpr Vector4 CornflowerBlue() { return { 0.33f, 0.66f, 1.0f, 1.0f }; } // #55AAFF 85, 170, 255
#if __clang__ || _MSC_VER
Vector4() = default;
constexpr Vector4(Vector2 xy, Vector2 zw) : xy{xy}, zw{zw} {}
constexpr Vector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} {}
#endif
/** @return TRUE if all elements are exactly 0.0f, which implies default initialized.
* To avoid FP errors, use almostZero() if you performed calculations */
bool isZero() const { return x == 0.0f && y == 0.0f && z == 0.0f && w == 0.0f; }
bool notZero() const { return x != 0.0f || y != 0.0f || z != 0.0f || w != 0.0f; }
bool hasNaN() const { return isnan(x) || isnan(y) || isnan(z) || isnan(w); }
/** @return TRUE if this vector is almost zero, with all components abs < 0.0001 */
bool almostZero() const;
/** @return TRUE if the vectors are almost equal, with a difference of < 0.0001 */
bool almostEqual(const Vector4& v) const;
void set(float newX, float newY, float newZ, float newW);
/** @return Dot product with another vector */
float dot(const Vector4& v) const;
/** Print the matrix */
void print() const;
/** @return Temporary static string from this Matrix4 */
const char* toString() const;
char* toString(char* buffer) const;
char* toString(char* buffer, int size) const;
template<int SIZE> char* toString(char (&buffer)[SIZE]) const {
return toString(buffer, SIZE);
}
/** @brief Assuming this is a quaternion, gives the Euler XYZ angles (degrees) */
Vector3 quatToEulerAngles() const;
Vector3 quatToEulerRadians() const;
/** @brief Creates a quaternion rotation from an Euler angle (degrees), rotation axis must be specified */
static Vector4 fromAngleAxis(float degrees, const Vector3& axis)
{ return fromAngleAxis(degrees, axis.x, axis.y, axis.z); }
static Vector4 fromRadianAxis(float radians, const Vector3& axis)
{ return fromRadianAxis(radians, axis.x, axis.y, axis.z); }
/** @brief Creates a quaternion rotation from an Euler angle (degrees), rotation axis must be specified */
static Vector4 fromAngleAxis(float degrees, float x, float y, float z);
static Vector4 fromRadianAxis(float radians, float x, float y, float z);
/** @brief Creates a quaternion rotation from Euler XYZ (degrees) rotation */
static Vector4 fromRotationAngles(const Vector3& rotationDegrees);
static Vector4 fromRotationRadians(const Vector3& rotationRadians);
/** @brief Creates a quaternion rotation from a 4x4 affine matrix */
static Vector4 fromRotationMatrix(const Matrix4& rotation);
/** @brief Creates a quaternion rotation from a 3x3 rotation matrix */
static Vector4 fromRotationMatrix(const Matrix3& rotation);
/** @return A 4-component float color from integer RGB color, with A being 1.0f */
static constexpr Vector4 RGB(int r, int g, int b)
{
return { r / 255.0f, g / 255.0f, b / 255.0f, 1.0f };
}
/** @return A 4-component float color from integer RGBA color */
static constexpr Vector4 RGB(int r, int g, int b, int a)
{
return { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f };
}
/** @return A 4-component float color with Alpha override */
static constexpr Vector4 RGB(Vector4 color, float newAlpha)
{