Removing old vector math.

This commit is contained in:
Branimir Karadžić
2018-11-16 20:31:41 -08:00
parent c827ec4c6d
commit acd4d291b8
4 changed files with 48 additions and 76 deletions

View File

@@ -324,6 +324,25 @@ namespace bx
return _a + angleDiff(_a, _b) * _t;
}
inline Vec3 load(const void* _ptr)
{
const float* ptr = reinterpret_cast<const float*>(_ptr);
return
{
ptr[0],
ptr[1],
ptr[2],
};
}
inline void store(void* _ptr, const Vec3& _a)
{
float* ptr = reinterpret_cast<float*>(_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];

View File

@@ -60,48 +60,45 @@ namespace bx
}
template <typename Rng>
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 <typename Rng>
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 <typename Ty>
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)

View File

@@ -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);

View File

@@ -57,15 +57,15 @@ namespace bx
/// Generate random point on unit circle.
template <typename Rng>
void randUnitCircle(float _result[3], Rng* _rng);
bx::Vec3 randUnitCircle(Rng* _rng);
/// Generate random point on unit sphere.
template <typename Rng>
void randUnitSphere(float _result[3], Rng* _rng);
bx::Vec3 randUnitSphere(Rng* _rng);
/// Generate random point on unit hemisphere.
template <typename Ty>
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