@@ -286,9 +286,24 @@ namespace bx
286
286
return _c - _a * _b;
287
287
}
288
288
289
+ inline BX_CONSTEXPR_FUNC float add (float _a, float _b)
290
+ {
291
+ return _a + _b;
292
+ }
293
+
294
+ inline BX_CONSTEXPR_FUNC float sub (float _a, float _b)
295
+ {
296
+ return _a - _b;
297
+ }
298
+
299
+ inline BX_CONSTEXPR_FUNC float mul (float _a, float _b)
300
+ {
301
+ return _a * _b;
302
+ }
303
+
289
304
inline BX_CONSTEXPR_FUNC float mad (float _a, float _b, float _c)
290
305
{
291
- return _a * _b + _c ;
306
+ return add ( mul (_a, _b), _c) ;
292
307
}
293
308
294
309
inline BX_CONSTEXPR_FUNC float rcp (float _a)
@@ -383,7 +398,7 @@ namespace bx
383
398
template <typename Ty>
384
399
inline Ty load (const void * _ptr)
385
400
{
386
- Ty result;
401
+ Ty result (init::None) ;
387
402
memCopy (&result, _ptr, sizeof (Ty) );
388
403
return result;
389
404
}
@@ -394,7 +409,21 @@ namespace bx
394
409
memCopy (_ptr, &_a, sizeof (Ty) );
395
410
}
396
411
397
- inline Vec3::Vec3 ()
412
+ inline Vec3::Vec3 (init::NoneType)
413
+ {
414
+ }
415
+
416
+ constexpr Vec3::Vec3 (init::ZeroType)
417
+ : x(0 .0f )
418
+ , y(0 .0f )
419
+ , z(0 .0f )
420
+ {
421
+ }
422
+
423
+ constexpr Vec3::Vec3 (init::IdentityType)
424
+ : x(0 .0f )
425
+ , y(0 .0f )
426
+ , z(0 .0f )
398
427
{
399
428
}
400
429
@@ -412,6 +441,57 @@ namespace bx
412
441
{
413
442
}
414
443
444
+ inline Plane::Plane (init::NoneType)
445
+ : normal(init::None)
446
+ {
447
+ }
448
+
449
+ constexpr Plane::Plane (init::ZeroType)
450
+ : normal(init::Zero)
451
+ , dist(0 .0f )
452
+ {
453
+ }
454
+
455
+ constexpr Plane::Plane (init::IdentityType)
456
+ : normal(0 .0f , 1 .0f , 0 .0f )
457
+ , dist(0 .0f )
458
+ {
459
+ }
460
+
461
+ constexpr Plane::Plane (Vec3 _normal, float _dist)
462
+ : normal(_normal)
463
+ , dist(_dist)
464
+ {
465
+ }
466
+
467
+ inline Quaternion::Quaternion (init::NoneType)
468
+ {
469
+ }
470
+
471
+ constexpr Quaternion::Quaternion (init::ZeroType)
472
+ : x(0 .0f )
473
+ , y(0 .0f )
474
+ , z(0 .0f )
475
+ , w(0 .0f )
476
+ {
477
+ }
478
+
479
+ constexpr Quaternion::Quaternion (init::IdentityType)
480
+ : x(0 .0f )
481
+ , y(0 .0f )
482
+ , z(0 .0f )
483
+ , w(1 .0f )
484
+ {
485
+ }
486
+
487
+ constexpr Quaternion::Quaternion (float _x, float _y, float _z, float _w)
488
+ : x(_x)
489
+ , y(_y)
490
+ , z(_z)
491
+ , w(_w)
492
+ {
493
+ }
494
+
415
495
inline BX_CONSTEXPR_FUNC Vec3 round (const Vec3 _a)
416
496
{
417
497
return
@@ -650,7 +730,7 @@ namespace bx
650
730
651
731
inline BX_CONST_FUNC Vec3 fromLatLong (float _u, float _v)
652
732
{
653
- Vec3 result;
733
+ Vec3 result (init::None) ;
654
734
const float phi = _u * kPi2 ;
655
735
const float theta = _v * kPi ;
656
736
@@ -705,6 +785,39 @@ namespace bx
705
785
};
706
786
}
707
787
788
+ inline BX_CONSTEXPR_FUNC Quaternion add (const Quaternion _a, const Quaternion _b)
789
+ {
790
+ return
791
+ {
792
+ _a.x + _b.x ,
793
+ _a.y + _b.y ,
794
+ _a.z + _b.z ,
795
+ _a.w + _b.w ,
796
+ };
797
+ }
798
+
799
+ inline BX_CONSTEXPR_FUNC Quaternion sub (const Quaternion _a, const Quaternion _b)
800
+ {
801
+ return
802
+ {
803
+ _a.x - _b.x ,
804
+ _a.y - _b.y ,
805
+ _a.z - _b.z ,
806
+ _a.w - _b.w ,
807
+ };
808
+ }
809
+
810
+ inline BX_CONSTEXPR_FUNC Quaternion mul (const Quaternion _a, float _b)
811
+ {
812
+ return
813
+ {
814
+ _a.x * _b,
815
+ _a.y * _b,
816
+ _a.z * _b,
817
+ _a.w * _b,
818
+ };
819
+ }
820
+
708
821
inline BX_CONSTEXPR_FUNC Quaternion mul (const Quaternion _a, const Quaternion _b)
709
822
{
710
823
const float ax = _a.x ;
@@ -751,15 +864,9 @@ namespace bx
751
864
const float norm = dot (_a, _a);
752
865
if (0 .0f < norm)
753
866
{
754
- const float invNorm = 1 .0f / sqrt (norm);
755
-
756
- return
757
- {
758
- _a.x * invNorm,
759
- _a.y * invNorm,
760
- _a.z * invNorm,
761
- _a.w * invNorm,
762
- };
867
+ const float invNorm = rsqrt (norm);
868
+
869
+ return mul (_a, invNorm);
763
870
}
764
871
765
872
return
@@ -771,6 +878,19 @@ namespace bx
771
878
};
772
879
}
773
880
881
+ inline BX_CONSTEXPR_FUNC Quaternion lerp (const Quaternion _a, const Quaternion _b, float _t)
882
+ {
883
+ const float sa = 1 .0f - _t;
884
+ const float adotb = dot (_a, _b);
885
+ const float sb = sign (adotb) * _t;
886
+
887
+ const Quaternion aa = mul (_a, sa);
888
+ const Quaternion bb = mul (_b, sb);
889
+ const Quaternion qq = add (aa, bb);
890
+
891
+ return normalize (qq);
892
+ }
893
+
774
894
inline BX_CONST_FUNC Vec3 toEuler (const Quaternion _a)
775
895
{
776
896
const float xx = _a.x ;
@@ -872,8 +992,8 @@ namespace bx
872
992
873
993
inline void mtxFromNormal (float * _result, const Vec3& _normal, float _scale, const Vec3& _pos)
874
994
{
875
- Vec3 tangent;
876
- Vec3 bitangent;
995
+ Vec3 tangent (init::None) ;
996
+ Vec3 bitangent (init::None) ;
877
997
calcTangentFrame (tangent, bitangent, _normal);
878
998
879
999
store (&_result[ 0 ], mul (bitangent, _scale) );
@@ -891,8 +1011,8 @@ namespace bx
891
1011
892
1012
inline void mtxFromNormal (float * _result, const Vec3& _normal, float _scale, const Vec3& _pos, float _angle)
893
1013
{
894
- Vec3 tangent;
895
- Vec3 bitangent;
1014
+ Vec3 tangent (init::None) ;
1015
+ Vec3 bitangent (init::None) ;
896
1016
calcTangentFrame (tangent, bitangent, _normal, _angle);
897
1017
898
1018
store (&_result[0 ], mul (bitangent, _scale) );
@@ -969,7 +1089,7 @@ namespace bx
969
1089
970
1090
inline Vec3 mul (const Vec3& _vec, const float * _mat)
971
1091
{
972
- Vec3 result;
1092
+ Vec3 result (init::None) ;
973
1093
result.x = _vec.x * _mat[0 ] + _vec.y * _mat[4 ] + _vec.z * _mat[ 8 ] + _mat[12 ];
974
1094
result.y = _vec.x * _mat[1 ] + _vec.y * _mat[5 ] + _vec.z * _mat[ 9 ] + _mat[13 ];
975
1095
result.z = _vec.x * _mat[2 ] + _vec.y * _mat[6 ] + _vec.z * _mat[10 ] + _mat[14 ];
@@ -978,7 +1098,7 @@ namespace bx
978
1098
979
1099
inline Vec3 mulXyz0 (const Vec3& _vec, const float * _mat)
980
1100
{
981
- Vec3 result;
1101
+ Vec3 result (init::None) ;
982
1102
result.x = _vec.x * _mat[0 ] + _vec.y * _mat[4 ] + _vec.z * _mat[ 8 ];
983
1103
result.y = _vec.x * _mat[1 ] + _vec.y * _mat[5 ] + _vec.z * _mat[ 9 ];
984
1104
result.z = _vec.x * _mat[2 ] + _vec.y * _mat[6 ] + _vec.z * _mat[10 ];
0 commit comments