1#ifndef NW_MATH_VECTOR4_H_
2#define NW_MATH_VECTOR4_H_
5#include <nw/math/math_Config.h>
7namespace nw {
namespace math {
25#if defined(NW_MATH_ENABLE_INTRINSICS)
75 static const VEC4 zero(0.0f, 0.0f, 0.0f, 0.0f);
82 static const VEC4 zero(0.0f, 0.0f, 0.0f, 1.0f);
91 explicit VEC4(
const f32* p) { x = p[0]; y = p[1]; z = p[2]; w = p[3]; }
92 explicit VEC4(
const VEC4_& v) { x = v.x; y = v.y; z = v.z; w = v.w; }
93 VEC4(f32 fx, f32 fy, f32 fz, f32 fw) { x = fx; y = fy; z = fz; w = fw; }
94 explicit VEC4(
const VEC3& v) { x = v.x; y = v.y; z = v.z; w = 0.0f; }
102 template <
typename ToPtr>
105 return reinterpret_cast<
ToPtr>(
this );
108 template <
typename ToPtr>
111 return reinterpret_cast<
ToPtr>(
this );
181 void Set(f32 fx, f32 fy, f32 fz, f32 fw) { x = fx; y = fy; z = fz; w = fw; }
183#pragma clang diagnostic push
184#pragma clang diagnostic ignored "-Wfloat-equal"
186 bool operator == (
const self_type& rhs)
const {
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; }
187 bool operator != (
const self_type& rhs)
const {
return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w; }
189#pragma clang diagnostic pop
198operator * (f32 f,
const VEC4& rhs) {
VEC4 tmp; (
void)VEC4Scale(&tmp, &rhs, f);
return tmp; }
204namespace nw {
namespace math {
211 pOut->x = p1->x + p2->x;
212 pOut->y = p1->y + p2->y;
213 pOut->z = p1->z + p2->z;
214 pOut->w = p1->w + p2->w;
222 pOut->x = p1->x - p2->x;
223 pOut->y = p1->y - p2->y;
224 pOut->z = p1->z - p2->z;
225 pOut->w = p1->w - p2->w;
233 pOut->x = scale * p->x;
234 pOut->y = scale * p->y;
235 pOut->z = scale * p->z;
236 pOut->w = scale * p->w;
245 pOut->x = p1->x + t * (p2->x - p1->x);
246 pOut->y = p1->y + t * (p2->y - p1->y);
247 pOut->z = p1->z + t * (p2->z - p1->z);
248 pOut->w = p1->w + t * (p2->w - p1->w);
256 return p1->x * p2->x + p1->y * p2->y + p1->z * p2->z + p1->w * p2->w;
262 return p->x * p->x + p->y * p->y + p->z * p->z + p->w * p->w;
275 pOut->x = (p1->x > p2->x) ? p1->x : p2->x;
276 pOut->y = (p1->y > p2->y) ? p1->y : p2->y;
277 pOut->z = (p1->z > p2->z) ? p1->z : p2->z;
278 pOut->w = (p1->w > p2->w) ? p1->w : p2->w;
286 pOut->x = (p1->x < p2->x) ? p1->x : p2->x;
287 pOut->y = (p1->y < p2->y) ? p1->y : p2->y;
288 pOut->z = (p1->z < p2->z) ? p1->z : p2->z;
289 pOut->w = (p1->w < p2->w) ? p1->w : p2->w;
296#if defined(NW_MATH_ENABLE_INTRINSICS)
427 return p->x == 0.f && p->y == 0.f && p->z == 0.f && p->w == 0.f;
433 return p->x == 0.f && p->y == 0.f && p->z == 0.f && p->w == 1.f;
474 return FSqrt(VEC4LenSq(p));
550namespace 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
f32 VEC4LenSq(const VEC4 *p)
VEC4 * VEC4Scale(VEC4 *pOut, const VEC4 *p, f32 scale)
f32 VEC4Dot(const VEC4 *p1, const VEC4 *p2)
f32 VEC4DistSq(const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4Minimize(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4Add(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4Sub(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4Lerp(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2, f32 t)
VEC4 * VEC4Maximize(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
Definition math_Triangular.cpp:3
Definition math_Constant.cpp:5
f32 VEC4Len(const VEC4 &v)
Definition math_Vector4.h:560
VEC4 * VEC4Minimize(VEC4 *pOut, const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:567
f32 VEC4LenSq(const VEC4 &v)
Definition math_Vector4.h:559
NW_MATH_INLINE f32 VEC4DistSq(const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4FastSafeNormalize(VEC4 *pOut, const VEC4 &v, const VEC4 &alt)
Definition math_Vector4.h:564
VEC4 * VEC4Add(VEC4 *pOut, const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:554
VEC4 * VEC4Sub(VEC4 *pOut, const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:555
VEC4 * VEC4Scale(VEC4 *pOut, const VEC4 &v, f32 scale)
Definition math_Vector4.h:556
VEC4 operator*(f32 f, const VEC4 &rhs)
Definition math_Vector4.h:198
NW_MATH_INLINE f32 VEC4Dot(const VEC4 *p1, const VEC4 *p2)
NW_MATH_INLINE VEC4 * VEC4Sub(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
bool VEC4IsZero(const VEC4 &v)
Definition math_Vector4.h:552
f32 VEC4DistSq(const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:565
VEC4 * VEC4Lerp(VEC4 *pOut, const VEC4 &v1, const VEC4 &v2, f32 t)
Definition math_Vector4.h:557
VEC4 * VEC4Normalize(VEC4 *pOut, const VEC4 &v)
Definition math_Vector4.h:561
VEC4 * VEC4Maximize(VEC4 *pOut, const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:566
VEC4 * VEC4SafeNormalize(VEC4 *pOut, const VEC4 &v, const VEC4 &alt)
Definition math_Vector4.h:563
VEC4 * VEC4SafeNormalize(VEC4 *pOut, const VEC4 *p, const VEC4 &alt)
NW_MATH_INLINE VEC4 * VEC4Add(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
VEC4 * VEC4Normalize(VEC4 *pOut, const VEC4 *p)
VEC4 * VEC4FastNormalize(VEC4 *pOut, const VEC4 &v)
Definition math_Vector4.h:562
bool VEC4IsZeroWOne(const VEC4 &v)
Definition math_Vector4.h:553
NW_MATH_INLINE VEC4 * VEC4Lerp(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2, f32 t)
struct VEC4 Vector4
Definition math_Vector4.h:195
NW_MATH_INLINE bool VEC4IsZero(const VEC4 *p)
VEC4 * VEC4FastSafeNormalize(VEC4 *pOut, const VEC4 *p, const VEC4 &alt)
VEC4 * VEC4FastNormalize(VEC4 *pOut, const VEC4 *p)
f32 VEC4Dot(const VEC4 &v1, const VEC4 &v2)
Definition math_Vector4.h:558
NW_MATH_INLINE bool VEC4IsZeroWOne(const VEC4 *p)
NW_MATH_INLINE VEC4 * VEC4Scale(VEC4 *pOut, const VEC4 *p, f32 scale)
NW_MATH_INLINE f32 VEC4Len(const VEC4 *p)
NW_MATH_INLINE VEC4 * VEC4Minimize(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
NW_MATH_INLINE f32 VEC4LenSq(const VEC4 *p)
NW_MATH_INLINE VEC4 * VEC4Maximize(VEC4 *pOut, const VEC4 *p1, const VEC4 *p2)
Definition math_Constant.cpp:5
Definition math_Vector4.h:61
f32 w
Definition math_Vector4.h:65
f32 y
Definition math_Vector4.h:63
f32 z
Definition math_Vector4.h:64
f32 x
Definition math_Vector4.h:62
Definition math_Vector4.h:69
bool operator!=(const self_type &rhs) const
Definition math_Vector4.h:187
static const VEC4 & Zero()
Definition math_Vector4.h:73
VEC4(const f32 *p)
Definition math_Vector4.h:91
bool operator==(const self_type &rhs) const
Definition math_Vector4.h:186
NW_MATH_INLINE self_type & SetTransform(const MTX44 &pM, const VEC4 &src)
Definition math_Transform.h:150
bool IsZeroWOne() const
Definition math_Vector4.h:192
VEC4(const VEC3 &v)
Definition math_Vector4.h:94
VEC4 self_type
Definition math_Vector4.h:87
self_type & Transform(const MTX34 &pM)
Definition math_Vector4.h:176
VEC4()
Definition math_Vector4.h:90
static const VEC4 & ZeroWOne()
Definition math_Vector4.h:80
f32 value_type
Definition math_Vector4.h:88
void Set(f32 fx, f32 fy, f32 fz, f32 fw)
Definition math_Vector4.h:181
bool IsZero() const
Definition math_Vector4.h:191
VEC4(const VEC4_ &v)
Definition math_Vector4.h:92
VEC4(f32 fx, f32 fy, f32 fz, f32 fw)
Definition math_Vector4.h:93
static const int DIMENSION
Definition math_Vector4.h:71