1#ifndef NW_MATH_VECTOR3_H_
2#define NW_MATH_VECTOR3_H_
5#include <nw/math/math_Config.h>
6#include <nw/math/math_Constant.h>
8namespace nw {
namespace math {
22#if defined(NW_MATH_ENABLE_INTRINSICS)
68 static const VEC3 zero(0.0f, 0.0f, 0.0f);
77 explicit VEC3(
const f32* p) { x = p[0]; y = p[1]; z = p[2]; }
78 explicit VEC3(
const VEC3_& v) { x = v.x; y = v.y; z = v.z; }
79 VEC3(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; }
87 template <
typename ToPtr>
90 return reinterpret_cast<
ToPtr>(
this );
93 template <
typename ToPtr>
96 return reinterpret_cast<
ToPtr>(
this );
185 void Set(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; }
186 void Set(
const self_type& value) { x = value.x; y = value.y; z = value.z; }
188#pragma clang diagnostic push
189#pragma clang diagnostic ignored "-Wfloat-equal"
191 bool operator == (
const self_type& rhs)
const {
return x == rhs.x && y == rhs.y && z == rhs.z; }
192 bool operator != (
const self_type& rhs)
const {
return x != rhs.x || y != rhs.y || z != rhs.z; }
194#pragma clang diagnostic pop
206 pOut->x = p1->x + p2->x;
207 pOut->y = p1->y + p2->y;
208 pOut->z = p1->z + p2->z;
215 pOut->x = p1->x - p2->x;
216 pOut->y = p1->y - p2->y;
217 pOut->z = p1->z - p2->z;
224 pOut->x = p1->x * p2->x;
225 pOut->y = p1->y * p2->y;
226 pOut->z = p1->z * p2->z;
233 pOut->x = scale * p->x;
234 pOut->y = scale * p->y;
235 pOut->z = scale * p->z;
242 pOut->x = p1->x + t * (p2->x - p1->x);
243 pOut->y = p1->y + t * (p2->y - p1->y);
244 pOut->z = p1->z + t * (p2->z - p1->z);
251 return p1->x * p2->x + p1->y * p2->y + p1->z * p2->z;
256#if defined(NW_MATH_ENABLE_INTRINSICS)
360 return internal::standard::VEC3Dot(p1, p2);
366 return p->x * p->x + p->y * p->y + p->z * p->z;
372 return ::std::sqrt( VEC3SquareLen( p ) );
378 return ::std::sqrt( VEC3SquareDist( p1, p2 ) );
382operator * (f32 f,
const VEC3& rhs) {
VEC3 tmp; (
void)VEC3Scale(&tmp, &rhs, f);
return tmp; }
390namespace nw {
namespace math {
397 pOut->x = (p1->x > p2->x) ? p1->x : p2->x;
398 pOut->y = (p1->y > p2->y) ? p1->y : p2->y;
399 pOut->z = (p1->z > p2->z) ? p1->z : p2->z;
407 pOut->x = (p1->x < p2->x) ? p1->x : p2->x;
408 pOut->y = (p1->y < p2->y) ? p1->y : p2->y;
409 pOut->z = (p1->z < p2->z) ? p1->z : p2->z;
419 diff.x = p1->x - p2->x;
420 diff.y = p1->y - p2->y;
421 diff.z = p1->z - p2->z;
423 return (diff.x * diff.x) + (diff.y * diff.y) + (diff.z * diff.z);
428#if defined(NW_MATH_ENABLE_INTRINSICS)
489 return p->x == 0.f && p->y == 0.f && p->z == 0.f;
509 tmpVec.x = ( p1->y * p2->z ) - ( p1->z * p2->y );
510 tmpVec.y = ( p1->z * p2->x ) - ( p1->x * p2->z );
511 tmpVec.z = ( p1->x * p2->y ) - ( p1->y * p2->x );
523 f32 mag = (p->x * p->x) + (p->y * p->y) + (p->z * p->z);
525 mag = 1.0f / ::std::sqrt(mag);
527 pOut->x = p->x * mag;
528 pOut->y = p->y * mag;
529 pOut->z = p->z * mag;
551 f32 mag = (p->x * p->x) + (p->y * p->y) + (p->z * p->z);
553#pragma clang diagnostic push
554#pragma clang diagnostic ignored "-Wfloat-equal"
563#pragma clang diagnostic pop
565 mag = 1.0f / ::std::sqrt(mag);
567 pOut->x = p->x * mag;
568 pOut->y = p->y * mag;
569 pOut->z = p->z * mag;
605namespace nw {
namespace math {
#define NW_MATH_AS_INLINE
Definition math_Config.h:6
#define NW_MATH_INLINE
Definition math_Config.h:7
#define NW_MATH_IMPL_NS
Definition math_Config.h:14
Definition math_Matrix34.h:11
NW_INLINE VEC3 * VEC3Scale(VEC3 *pOut, const VEC3 *p, f32 scale)
Definition math_Vector3.h:231
VEC3 * VEC3Maximize(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
NW_INLINE VEC3 * VEC3Mult(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:222
NW_INLINE VEC3 * VEC3Lerp(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2, f32 t)
Definition math_Vector3.h:240
NW_INLINE VEC3 * VEC3Sub(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:213
f32 VEC3SquareDist(const VEC3 *p1, const VEC3 *p2)
VEC3 * VEC3Minimize(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
NW_INLINE VEC3 * VEC3Add(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:204
NW_INLINE f32 VEC3Dot(const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:249
Definition math_Triangular.cpp:3
Definition math_Constant.cpp:5
VEC3 * VEC3Normalize(VEC3 *pOut, const VEC3 &v)
Definition math_Vector3.h:611
VEC3 * VEC3FastNormalize(VEC3 *pOut, const VEC3 *p)
VEC3 * VEC3Sub(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:334
NW_MATH_INLINE VEC3 * VEC3Maximize(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
VEC3 * VEC3Lerp(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2, f32 t)
Definition math_Vector3.h:620
NW_MATH_INLINE VEC3 * VEC3SafeNormalize(VEC3 *pOut, const VEC3 *p, const VEC3 &alt)
f32 VEC3Dot(const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:621
VEC3 * VEC3FastSafeNormalize(VEC3 *pOut, const VEC3 *p, const VEC3 &alt)
f32 VEC3SquareLen(const VEC3 &v)
Definition math_Vector3.h:623
VEC3 * VEC3Add(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:617
VEC3 * VEC3Maximize(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:608
VEC3 * VEC3Scale(VEC3 *pOut, const VEC3 &v, f32 scale)
Definition math_Vector3.h:619
VEC3 * VEC3Minimize(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:609
f32 VEC3SquareLen(const VEC3 *p)
Definition math_Vector3.h:364
f32 VEC3Dist(const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:624
f32 VEC3Len(const VEC3 &v)
Definition math_Vector3.h:622
VEC3 * VEC3Add(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:328
f32 VEC3Dot(const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:358
NW_MATH_INLINE VEC3 * VEC3Cross(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
NW_MATH_INLINE VEC3 * VEC3Normalize(VEC3 *pOut, const VEC3 *p)
f32 VEC3SquareDist(const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:615
VEC3 * VEC3FastNormalize(VEC3 *pOut, const VEC3 &v)
Definition math_Vector3.h:612
VEC3 * VEC3FastSafeNormalize(VEC3 *pOut, const VEC3 &v, const VEC3 &alt)
Definition math_Vector3.h:614
VEC3 * VEC3Scale(VEC3 *pOut, const VEC3 *p, f32 scale)
Definition math_Vector3.h:346
f32 VEC3Len(const VEC3 *p)
Definition math_Vector3.h:370
f32 VEC3Dist(const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:376
NW_MATH_INLINE bool VEC3IsZero(const VEC3 *p)
VEC3 * VEC3Mult(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
Definition math_Vector3.h:340
NW_MATH_INLINE f32 VEC3SquareDist(const VEC3 *p1, const VEC3 *p2)
struct VEC3 Vector3
Definition math_Vector3.h:199
VEC3 * VEC3Sub(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:618
bool VEC3IsZero(const VEC3 &v)
Definition math_Vector3.h:607
NW_MATH_INLINE VEC3 * VEC3Minimize(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2)
VEC3 * VEC3SafeNormalize(VEC3 *pOut, const VEC3 &v, const VEC3 &alt)
Definition math_Vector3.h:613
VEC3 * VEC3Lerp(VEC3 *pOut, const VEC3 *p1, const VEC3 *p2, f32 t)
Definition math_Vector3.h:352
VEC3 operator*(f32 f, const VEC3 &rhs)
Definition math_Vector3.h:382
VEC3 * VEC3Cross(VEC3 *pOut, const VEC3 &v1, const VEC3 &v2)
Definition math_Vector3.h:610
Definition math_Constant.cpp:5
Definition math_Matrix34.h:136
Definition math_Matrix44.h:189
Definition math_Vector3.h:55
f32 z
Definition math_Vector3.h:58
f32 y
Definition math_Vector3.h:57
f32 x
Definition math_Vector3.h:56
Definition math_Vector3.h:62
static const VEC3 & Zero()
Definition math_Vector3.h:66
self_type & Transform(const MTX44 &pM)
Definition math_Vector3.h:180
VEC3()
Definition math_Vector3.h:76
f32 value_type
Definition math_Vector3.h:74
static const int DIMENSION
Definition math_Vector3.h:64
void Set(f32 fx, f32 fy, f32 fz)
Definition math_Vector3.h:185
NW_MATH_INLINE self_type & SetTransformNormal(const MTX34 &pM, const VEC3 &src)
Definition math_Transform.h:137
self_type & Transform(const MTX34 &pM)
Definition math_Vector3.h:177
VEC3(const VEC3_ &v)
Definition math_Vector3.h:78
bool IsZero() const
Definition math_Vector3.h:196
bool operator!=(const self_type &rhs) const
Definition math_Vector3.h:192
VEC3(const f32 *p)
Definition math_Vector3.h:77
void Set(const self_type &value)
Definition math_Vector3.h:186
bool operator==(const self_type &rhs) const
Definition math_Vector3.h:191
VEC3(f32 fx, f32 fy, f32 fz)
Definition math_Vector3.h:79
self_type & TransformNormal(const MTX34 &pM)
Definition math_Vector3.h:183
NW_MATH_INLINE self_type & SetTransform(const MTX44 &pM, const VEC3 &src)
Definition math_Transform.h:131
VEC3 self_type
Definition math_Vector3.h:73
#define NW_INLINE
Definition types.h:14