-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlslmath.h
9822 lines (8370 loc) · 211 KB
/
hlslmath.h
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
// You can put your copyright here!
// Generate with hlslmath/tools/build
// Filename: D:\Projects\hlslmath\tools/../hlslmath.h
// Datetime: Sat Aug 21 19:12:02 2021
#pragma once
#include <math.h>
#undef min // When Windows.h was included, min is an macro
#undef max // When Windows.h was included, max is an macro
// Detect neon support & enable
#if defined(__ARM_NEON) && defined(HLSLMATH_ENABLE_NEON) && HLSLMATH_ENABLE_NEON
# if defined(__aarch64__) && defined(__ANDROID__)
# define HLSLMATH_ENABLE_NEON 0
# else
# include <arm_neon.h>
# define HLSLMATH_ENABLE_NEON 1
# endif
#else
# define HLSLMATH_ENABLE_NEON 0
#endif
// Detect SSE support & enable
#if !defined(HLSLMATH_ENABLE_SSE)
# define HLSLMATH_ENABLE_SSE 1
#endif
#if defined(__SSSE3__)
# define HLSLMATH_SSE_SUPPORT 1
#endif
#if defined(__SSE__) || defined(__SSE2__) || defined(__SSE3__)
# undef HLSLMATH_SSE_SUPPORT
# define HLSLMATH_SSE_SUPPORT 1
#endif
#if defined(__SSE4_1__) || defined(__SSE4_2__) || defined(__SSE_MATH__)
# undef HLSLMATH_SSE_SUPPORT
# define HLSLMATH_SSE_SUPPORT 1
#endif
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_IX64))
# if defined(_M_HYBRID_X86_ARM64)
# undef HLSLMATH_SSE_SUPPORT
# define HLSLMATH_SSE_SUPPORT 0
# else
# undef HLSLMATH_SSE_SUPPORT
# define HLSLMATH_SSE_SUPPORT 1
# endif
#endif
#if !HLSLMATH_SSE_SUPPORT
# undef HLSLMATH_SSE_ENABLE
# define HLSLMATH_SSE_ENABLE 0
#endif
// API deprecated declaration
#if __cplusplus >= 201103L
# define HLSLMATH_DEPRECATED(version, reason) [[deprecated]]
#elif defined(_MSC_VER)
# define HLSLMATH_DEPRECATED(version, reason) __declspec(deprecated)
#elif defined(__GNUC__)
# define HLSLMATH_DEPRECATED(version, reason) __attribute__((deprecated))
#else
# define HLSLMATH_DEPRECATED(version, reason)
#endif
// Supporting data alignment for cache-friendly
#if __cplusplus >= 201103L
# define HLSLMATH_ALIGNAS(Type) alignas(16) Type
#elif defined(_MSC_VER)
# define HLSLMATH_ALIGNAS(Type) __declspec(align(16)) Type
#elif defined(__GNUC__)
# define HLSLMATH_ALIGNAS(Type) Type __attribute__((aligned(16)))
#else
# error "Define HLSLMATH_ALIGNED for your compiler or platform!"
#endif
// Android polyfill for log2 and log2f
#if defined(__ANDROID__)
extern "C"
{
inline float log2f(float x)
{
return (logf(x) / 0.693147180559945f);
}
inline double log2(double x)
{
return (log(x) / 0.693147180559945);
}
}
#endif
// Types supported
typedef unsigned int uint;
union bool2;
union bool3;
union bool4;
union bool2x2;
union bool3x3;
union bool4x4;
union int2;
union int3;
union int4;
union int2x2;
union int3x3;
union int4x4;
union uint2;
union uint3;
union uint4;
union uint2x2;
union uint3x3;
union uint4x4;
union float2;
union float3;
union float4;
union float2x2;
union float3x3;
union float4x4;
//
// Custom build settings
//
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
#define HLSLMATH_DEFINE_INTRINSICS 1
#else
#define HLSLMATH_DEFINE_INTRINSICS 0
#endif
#include <assert.h>
#define HLSLMATH_ASSERT(exp, msg) assert((exp) && msg)
//
// Define types
//
union int2
{
struct
{
int x, y;
};
inline int2() {} // Default constructor, do no intialization
int2(int s);
int2(int x, int y);
int& operator[](int index);
int operator[](int index) const;
};
union HLSLMATH_ALIGNAS(int3)
{
struct
{
int x, y, z;
};
inline int3() {} // Default constructor, do no intialization
int3(int s);
int3(int x, int y, int z);
int& operator[](int index);
int operator[](int index) const;
};
union HLSLMATH_ALIGNAS(int4)
{
struct
{
int x, y, z, w;
};
inline int4() {} // Default constructor, do no intialization
int4(int s);
int4(int x, int y, int z, int w);
int& operator[](int index);
int operator[](int index) const;
};
union uint2
{
struct
{
uint x, y;
};
inline uint2() {} // Default constructor, do no intialization
uint2(uint s);
uint2(uint x, uint y);
uint& operator[](int index);
uint operator[](int index) const;
};
union HLSLMATH_ALIGNAS(uint3)
{
struct
{
uint x, y, z;
};
inline uint3() {} // Default constructor, do no intialization
uint3(uint s);
uint3(uint x, uint y, uint z);
uint& operator[](int index);
uint operator[](int index) const;
};
union HLSLMATH_ALIGNAS(uint4)
{
struct
{
uint x, y, z, w;
};
inline uint4() {} // Default constructor, do no intialization
uint4(int s);
uint4(uint x, uint y, uint z, uint w);
uint& operator[](int index);
uint operator[](int index) const;
};
union bool2
{
struct
{
bool x, y;
};
inline bool2() {} // Default constructor, do no intialization
bool2(bool s);
bool2(bool x, bool y);
bool& operator[](int index);
bool operator[](int index) const;
};
union bool3
{
struct
{
bool x, y, z;
};
inline bool3() {} // Default constructor, do no intialization
bool3(bool s);
bool3(bool x, bool y, bool z);
bool& operator[](int index);
bool operator[](int index) const;
};
union bool4
{
struct
{
bool x, y, z, w;
};
inline bool4() {} // Default constructor, do no intialization
bool4(bool s);
bool4(bool x, bool y, bool z, bool w);
bool& operator[](int index);
bool operator[](int index) const;
};
union float2
{
struct
{
float x, y;
};
inline float2(); // Default constructor, do no intialization
float2(float s);
float2(float x, float y);
float2(const float3& v);
explicit float2(const float4& v);
operator float3() const;
explicit operator float4() const;
float& operator[](int index);
float operator[](int index) const;
};
union HLSLMATH_ALIGNAS(float3)
{
struct
{
float x, y, z;
};
inline float3(); // Default constructor, do no intialization
float3(float s);
float3(float x, float y, float z = 0.0f);
float3(const float2& v);
explicit float3(const float4& v);
operator float2(void) const;
explicit operator float4(void) const;
float& operator[](int index);
float operator[](int index) const;
};
union HLSLMATH_ALIGNAS(float4)
{
struct
{
float x, y, z, w;
};
inline float4() {} // Default constructor, do no intialization
float4(float s);
float4(const float3& xyz, float w = 0.0f);
float4(float x, float y, float z, float w);
float& operator[](int index);
float operator[](int index) const;
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4 quat(const float3& axis, float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4 toaxis(const float4& quat);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static void toaxis(const float4& quat, float3* axis, float* angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4 euler(const float3& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4 euler(float x, float y, float z);
};
union HLSLMATH_ALIGNAS(int2x2)
{
int data[2][2];
inline int2x2() {} // Default constructor, do no intialization
int2x2(int s);
int2x2(const int2& m0, const int2& m1);
int2x2(int m00, int m01, int m10, int m11);
int2& operator[](int index);
const int2& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(int3x3)
{
int data[3][3];
inline int3x3() {} // Default constructor, do no intialization
int3x3(int s);
int3x3(
const int3& m0,
const int3& m1,
const int3& m2);
int3x3(
int m00, int m01, int m02,
int m10, int m11, int m12,
int m20, int m21, int m22);
int3& operator[](int index);
const int3& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(int4x4)
{
int data[4][4];
inline int4x4() {} // Default constructor, do no intialization
int4x4(int s);
int4x4(
const int4& m0,
const int4& m1,
const int4& m2,
const int4& m3);
int4x4(
int m00, int m01, int m02, int m03,
int m10, int m11, int m12, int m13,
int m20, int m21, int m22, int m23,
int m30, int m31, int m32, int m33);
int4& operator[](int index);
const int4& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(uint2x2)
{
uint data[2][2];
inline uint2x2() {} // Default constructor, do no intialization
uint2x2(uint s);
uint2x2(const uint2& m0, const uint2& m1);
uint2x2(uint m00, uint m01, uint m10, uint m11);
uint2& operator[](int index);
const uint2& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(uint3x3)
{
uint data[3][3];
inline uint3x3() {} // Default constructor, do no intialization
uint3x3(uint s);
uint3x3(
const uint3& m0,
const uint3& m1,
const uint3& m2);
uint3x3(
uint m00, uint m01, uint m02,
uint m10, uint m11, uint m12,
uint m20, uint m21, uint m22);
uint3& operator[](int index);
const uint3& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(uint4x4)
{
uint data[4][4];
inline uint4x4() {} // Default constructor, do no intialization
uint4x4(uint s);
uint4x4(
const uint4& m0,
const uint4& m1,
const uint4& m2,
const uint4& m3
);
uint4x4(
uint m00, uint m01, uint m02, uint m03,
uint m10, uint m11, uint m12, uint m13,
uint m20, uint m21, uint m22, uint m23,
uint m30, uint m31, uint m32, uint m33
);
uint4& operator[](int index);
const uint4& operator[](int index) const;
};
union bool2x2
{
bool data[2][2];
inline bool2x2() {} // Default constructor, do no intialization
bool2x2(bool s);
bool2x2(const bool2& m0, const bool2& m1);
bool2x2(bool m00, bool m01, bool m10, bool m11);
bool2& operator[](int index);
const bool2& operator[](int index) const;
};
union bool3x3
{
bool data[3][3];
inline bool3x3() {} // Default constructor, do no intialization
bool3x3(bool s);
bool3x3(
const bool3& m0,
const bool3& m1,
const bool3& m2
);
bool3x3(
bool m00, bool m01, bool m02,
bool m10, bool m11, bool m12,
bool m20, bool m21, bool m22
);
bool3& operator[](int index);
const bool3& operator[](int index) const;
};
union bool4x4
{
bool data[4][4];
inline bool4x4() {} // Default constructor, do no intialization
bool4x4(bool s);
bool4x4(
const bool4& m0,
const bool4& m1,
const bool4& m2,
const bool4& m3
);
bool4x4(
bool m00, bool m01, bool m02, bool m03,
bool m10, bool m11, bool m12, bool m13,
bool m20, bool m21, bool m22, bool m23,
bool m30, bool m31, bool m32, bool m33
);
bool4& operator[](int index);
const bool4& operator[](int index) const;
};
union HLSLMATH_ALIGNAS(float2x2)
{
float data[2][2];
inline float2x2() {} // Default constructor, do no intialization
float2x2(float s);
float2x2(const float2& m0, const float2& m1);
float2x2(float m00, float m01, float m10, float m11);
float2& operator[](int index);
const float2& operator[](int index) const;
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float2x2 identity();
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float2x2 rotation(float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float2x2 scalation(float x);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float2x2 scalation(const float2& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float2x2 scalation(float x, float y);
};
union HLSLMATH_ALIGNAS(float3x3)
{
float data[3][3];
inline float3x3() {} // Default constructor, do no intialization
float3x3(float s);
float3x3(
const float3& m0,
const float3& m1,
const float3& m2);
float3x3(
float m00, float m01, float m02,
float m10, float m11, float m12,
float m20, float m21, float m22);
float3& operator[](int index);
const float3& operator[](int index) const;
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 identity();
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 translation(const float2& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 translation(float x, float y);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 rotation(float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 scalation(const float2& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 scalation(float x, float y);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float3x3 ortho(float l, float r, float b, float t);
};
union HLSLMATH_ALIGNAS(float4x4)
{
float data[4][4];
inline float4x4() {} // Default constructor, do no intialization
float4x4(float s);
float4x4(
const float4& m0,
const float4& m1,
const float4& m2,
const float4& m3);
float4x4(
float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33);
float4& operator[](int index);
const float4& operator[](int index) const;
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 identity();
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 scalation(float s);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 scalation(const float2& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 scalation(const float3& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 scalation(float x, float y, float z = 1.0f);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 translation(const float2& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 translation(const float3& v);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 translation(float x, float y, float z = 0.0f);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation(const float4& quaternion);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation(const float3& axis, float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation(float x, float y, float z, float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation_x(float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation_y(float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 rotation_z(float angle);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static void decompose(const float4x4& m, float3* scalation, float4* quaternion, float3* translation);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static void decompose(const float4x4& m, float3* scalation, float3* axis, float* angle, float3* translation);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 lookat(const float3& eye, const float3& target, const float3& up);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 ortho(float l, float r, float b, float t, float n, float f);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 frustum(float l, float r, float b, float t, float n, float f);
HLSLMATH_DEPRECATED("V1.0", "Move functions in data types to outside")
static float4x4 perspective(float fov, float aspect, float znear, float zfar);
};
inline int2::int2(int s)
: x(s)
, y(s)
{
}
inline int2::int2(int x, int y)
: x(x)
, y(y)
{
}
inline int& int2::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((int*)this)[index];
}
inline int int2::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((int*)this)[index];
}
inline int3::int3(int x, int y, int z)
: x(x)
, y(y)
, z(z)
{
}
inline int3::int3(int s)
: x(s)
, y(s)
, z(s)
{
}
inline int& int3::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((int*)this)[index];
}
inline int int3::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((int*)this)[index];
}
inline int4::int4(int x, int y, int z, int w)
: x(x)
, y(y)
, z(z)
, w(w)
{
}
inline int4::int4(int s)
: x(s)
, y(s)
, z(s)
, w(s)
{
}
inline int& int4::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((int*)this)[index];
}
inline int int4::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((int*)this)[index];
}
inline uint2::uint2(uint s)
: x(s)
, y(s)
{
}
inline uint2::uint2(uint x, uint y)
: x(x)
, y(y)
{
}
inline uint& uint2::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((uint*)this)[index];
}
inline uint uint2::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((uint*)this)[index];
}
inline uint3::uint3(uint s)
: x(s)
, y(s)
, z(s)
{
}
inline uint3::uint3(uint x, uint y, uint z)
: x(x)
, y(y)
, z(z)
{
}
inline uint& uint3::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((uint*)this)[index];
}
inline uint uint3::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((uint*)this)[index];
}
inline uint4::uint4(uint x, uint y, uint z, uint w)
: x(x)
, y(y)
, z(z)
, w(w)
{
}
inline uint4::uint4(int s)
: x(s)
, y(s)
, z(s)
, w(s)
{
}
inline uint& uint4::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((uint*)this)[index];
}
inline uint uint4::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((uint*)this)[index];
}
inline bool2::bool2(bool s)
: x(s)
, y(s)
{
}
inline bool2::bool2(bool x, bool y)
: x(x)
, y(y)
{
}
inline bool& bool2::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((bool*)this)[index];
}
inline bool bool2::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((bool*)this)[index];
}
inline bool3::bool3(bool s)
: x(s)
, y(s)
, z(s)
{
}
inline bool3::bool3(bool x, bool y, bool z)
: x(x)
, y(y)
, z(z)
{
}
inline bool& bool3::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((bool*)this)[index];
}
inline bool bool3::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 3, "Index out of range");
return ((bool*)this)[index];
}
inline bool4::bool4(bool s)
: x(s)
, y(s)
, z(s)
, w(s)
{
}
inline bool4::bool4(bool x, bool y, bool z, bool w)
: x(x)
, y(y)
, z(z)
, w(w)
{
}
inline bool& bool4::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((bool*)this)[index];
}
inline bool bool4::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 4, "Index out of range");
return ((bool*)this)[index];
}
inline float2::float2(float s)
: x(s)
, y(s)
{
}
inline float2::float2(float x, float y)
: x(x)
, y(y)
{
}
inline float2::float2(const float3& v)
: x(v.x)
, y(v.y)
{
}
inline float2::float2(const float4& v)
: x(v.x)
, y(v.y)
{
}
inline float2::operator float3() const
{
return float3(x, y, 0.0f);
}
inline float2::operator float4() const
{
return float4(x, y, 0.0f, 0.0f);
}
inline float& float2::operator[](int index)
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((float*)this)[index];
}
inline float float2::operator[](int index) const
{
HLSLMATH_ASSERT(index > -1 && index < 2, "Index out of range");
return ((float*)this)[index];
}
inline float3::float3(float s)
: x(s)
, y(s)
, z(s)
{
}
inline float3::float3(float x, float y, float z)
: x(x)
, y(y)
, z(z)
{
}
inline float3::float3(const float2& v)
: float3(v.x, v.y)
{
}
inline float3::float3(const float4& v)
: float3(v.x, v.y, v.z)
{
}
inline float3::operator float2(void) const
{
return float2(x, y);
}
inline float3::operator float4(void) const
{
return float4(x, y, z, 0.0f);
}
inline float& float3::operator[](int index)
{
return (&x)[index];
}
inline float float3::operator[](int index) const
{
return (&x)[index];
}
inline float4::float4(const float3& xyz, float w)
: x(xyz.x)
, y(xyz.y)
, z(xyz.z)
, w(w)
{
}