From acd4d291b8c781576fd7a156b9ee661609401334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 16 Nov 2018 20:31:41 -0800 Subject: [PATCH] Removing old vector math. --- include/bx/inline/math.inl | 54 ++++++++++++++------------------------ include/bx/inline/rng.inl | 43 ++++++++++++++---------------- include/bx/math.h | 21 +++++---------- include/bx/rng.h | 6 ++--- 4 files changed, 48 insertions(+), 76 deletions(-) diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index f586ea7..060b8bb 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -324,6 +324,25 @@ namespace bx return _a + angleDiff(_a, _b) * _t; } + inline Vec3 load(const void* _ptr) + { + const float* ptr = reinterpret_cast(_ptr); + return + { + ptr[0], + ptr[1], + ptr[2], + }; + } + + inline void store(void* _ptr, const Vec3& _a) + { + float* ptr = reinterpret_cast(_ptr); + ptr[0] = _a.x; + ptr[1] = _a.y; + ptr[2] = _a.z; + } + inline constexpr BX_CONST_FUNC Vec3 abs(const Vec3& _a) { return @@ -550,13 +569,6 @@ namespace bx *_outV = theta*bx::kInvPi; } - inline void vec3Move(float* _result, const float* _a) - { - _result[0] = _a[0]; - _result[1] = _a[1]; - _result[2] = _a[2]; - } - inline void vec3Abs(float* _result, const float* _a) { _result[0] = abs(_a[0]); @@ -564,13 +576,6 @@ namespace bx _result[2] = abs(_a[2]); } - inline void vec3Neg(float* _result, const float* _a) - { - _result[0] = -_a[0]; - _result[1] = -_a[1]; - _result[2] = -_a[2]; - } - inline void vec3Add(float* _result, const float* _a, const float* _b) { _result[0] = _a[0] + _b[0]; @@ -654,27 +659,6 @@ namespace bx return len; } - inline void vec3Min(float* _result, const float* _a, const float* _b) - { - _result[0] = min(_a[0], _b[0]); - _result[1] = min(_a[1], _b[1]); - _result[2] = min(_a[2], _b[2]); - } - - inline void vec3Max(float* _result, const float* _a, const float* _b) - { - _result[0] = max(_a[0], _b[0]); - _result[1] = max(_a[1], _b[1]); - _result[2] = max(_a[2], _b[2]); - } - - inline void vec3Rcp(float* _result, const float* _a) - { - _result[0] = 1.0f / _a[0]; - _result[1] = 1.0f / _a[1]; - _result[2] = 1.0f / _a[2]; - } - inline void vec3TangentFrame(const float* _n, float* _t, float* _b) { const float nx = _n[0]; diff --git a/include/bx/inline/rng.inl b/include/bx/inline/rng.inl index d9796bd..9577bb0 100644 --- a/include/bx/inline/rng.inl +++ b/include/bx/inline/rng.inl @@ -60,48 +60,45 @@ namespace bx } template - inline void randUnitCircle(float _result[3], Rng* _rng) + inline bx::Vec3 randUnitCircle(Rng* _rng) { const float angle = frnd(_rng) * kPi2; - _result[0] = cos(angle); - _result[1] = 0.0f; - _result[2] = sin(angle); + return + { + cos(angle), + 0.0f, + sin(angle), + }; } template - inline void randUnitSphere(float _result[3], Rng* _rng) + inline bx::Vec3 randUnitSphere(Rng* _rng) { const float rand0 = frnd(_rng) * 2.0f - 1.0f; const float rand1 = frnd(_rng) * kPi2; const float sqrtf1 = sqrt(1.0f - rand0*rand0); - _result[0] = sqrtf1 * cos(rand1); - _result[1] = sqrtf1 * sin(rand1); - _result[2] = rand0; + return + { + sqrtf1 * cos(rand1), + sqrtf1 * sin(rand1), + rand0, + }; } template - inline void randUnitHemisphere(float _result[3], Ty* _rng, const float _normal[3]) + inline bx::Vec3 randUnitHemisphere(Ty* _rng, const bx::Vec3& _normal) { - float dir[3]; - randUnitSphere(dir, _rng); + const bx::Vec3 dir = randUnitSphere(_rng); + const float ddotn = bx::dot(dir, _normal); - float DdotN = dir[0]*_normal[0] - + dir[1]*_normal[1] - + dir[2]*_normal[2] - ; - - if (0.0f > DdotN) + if (0.0f > ddotn) { - dir[0] = -dir[0]; - dir[1] = -dir[1]; - dir[2] = -dir[2]; + return bx::neg(dir); } - _result[0] = dir[0]; - _result[1] = dir[1]; - _result[2] = dir[2]; + return dir; } inline void generateSphereHammersley(void* _data, uint32_t _stride, uint32_t _num, float _scale) diff --git a/include/bx/math.h b/include/bx/math.h index de73d53..31d7e26 100644 --- a/include/bx/math.h +++ b/include/bx/math.h @@ -267,6 +267,12 @@ namespace bx /// BX_CONST_FUNC float angleLerp(float _a, float _b, float _t); + /// + Vec3 load(const void* _ptr); + + /// + void store(void* _ptr, const Vec3& _a); + /// constexpr BX_CONST_FUNC Vec3 abs(const Vec3& _a); @@ -333,15 +339,9 @@ namespace bx /// void toLatLong(float* _outU, float* _outV, const Vec3& _dir); - /// - void vec3Move(float* _result, const float* _a); - /// void vec3Abs(float* _result, const float* _a); - /// - void vec3Neg(float* _result, const float* _a); - /// void vec3Add(float* _result, const float* _a, const float* _b); @@ -378,15 +378,6 @@ namespace bx /// float vec3Norm(float* _result, const float* _a); - /// - void vec3Min(float* _result, const float* _a, const float* _b); - - /// - void vec3Max(float* _result, const float* _a, const float* _b); - - /// - void vec3Rcp(float* _result, const float* _a); - /// Calculate tangent frame from normal. /// void vec3TangentFrame(const float* _n, float* _t, float* _b); diff --git a/include/bx/rng.h b/include/bx/rng.h index e558615..87ba511 100644 --- a/include/bx/rng.h +++ b/include/bx/rng.h @@ -57,15 +57,15 @@ namespace bx /// Generate random point on unit circle. template - void randUnitCircle(float _result[3], Rng* _rng); + bx::Vec3 randUnitCircle(Rng* _rng); /// Generate random point on unit sphere. template - void randUnitSphere(float _result[3], Rng* _rng); + bx::Vec3 randUnitSphere(Rng* _rng); /// Generate random point on unit hemisphere. template - void randUnitHemisphere(float _result[3], Ty* _rng, const float _normal[3]); + bx::Vec3 randUnitHemisphere(Ty* _rng, const bx::Vec3& _normal); /// Sampling with Hammersley and Halton Points /// http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html