3template<
class Type,
int Dim>
17 explicit cVec4(
const float S);
18 cVec4(
const float X,
const float Y,
const float Z,
const float W);
19 cVec4(
const cVec2 &XY,
const float Z,
const float W);
22 cVec4(
const cVec4& v) :x(v.x), y(v.y), z(v.z), w(v.w) {}
25 void Set(
const float S);
26 void Set(
const float X,
const float Y,
const float Z,
const float W);
27 void Set(
const cVec2 &XY,
const float Z,
const float W);
29 void Set(
const cVec3 &XYZ,
const float W);
31 void Copy(
const float *pSrc);
33 float & operator [] (
const int index);
34 float operator [] (
const int index)
const;
36 const cVec4 operator - ()
const;
41 cVec4& operator *= (
const float);
43 cVec4& operator /= (
const float);
45 void Transform(
const cMat4 &);
46 void operator *= (
const cMat4 &);
52 const cVec4 operator * (
const float)
const;
53 friend const cVec4 operator * (
const float,
const cVec4 &);
55 const cVec4 operator / (
const float)
const;
56 friend const cVec4 operator / (
const float,
const cVec4 &);
61 bool operator == (
const cVec4 &)
const;
62 bool operator != (
const cVec4 &)
const;
63 static bool Equals(
const cVec4 &,
const cVec4 &,
const float Eps = cMath::Epsilon);
66 float LengthSq()
const;
68 float NormalizeSafe(
const cVec4 &Fallback = cVec4::AxisW);
69 bool IsNormalized(
const float Eps = cMath::Epsilon)
const;
70 bool IsZero(
const float Eps = cMath::Epsilon)
const;
73 static float Dot(
const cVec4 &,
const cVec4 &);
77 static float Length(
const cVec4 &);
78 static float LengthSq(
const cVec4 &);
84 std::tuple<float, float, float, float> __getstate__();
85 void __setstate__(
const std::tuple<float, float, float, float>& state);
86 const std::string __repr__()
const;
88 static const cVec4 Zero;
89 static const cVec4 One;
90 static const cVec4 Infinity;
91 static const cVec4 AxisX;
92 static const cVec4 AxisY;
93 static const cVec4 AxisZ;
94 static const cVec4 AxisW;
95 static const cVec4 AxisNegX;
96 static const cVec4 AxisNegY;
97 static const cVec4 AxisNegZ;
98 static const cVec4 AxisNegW;
100 const float * ToFloatPtr()
const;
101 float * ToFloatPtr();
103 const cVec2 & ToVec2()
const;
106 const cVec3 & ToVec3()
const;
110 operator cVec<Type, 4>()
const;
112 int GetDimension()
const;
113 const cStr ToString(
const int Prec = 2)
const;
117 inline void Clear(
void* = 0) {
118 x = y = z = w = 0.0f;
120 inline void AddWithWeight(
cVec4 const& src,
float weight) {
126 inline void SetPosition(
float aX,
float aY,
float aZ,
float aW) {
132 inline const float* GetPosition()
const {
141inline cVec4::cVec4() {
145inline cVec4::cVec4(
const float S)
146: x(S), y(S), z(S), w(S) {}
149inline cVec4::cVec4(
const float X,
const float Y,
const float Z,
const float W)
150: x(X), y(Y), z(Z), w(W) {}
153inline cVec4::cVec4(
const cVec2 &XY,
const float Z,
const float W)
154: x(XY.x), y(XY.y), z(Z), w(W) {}
157inline cVec4::cVec4(
const cVec2 &XY,
const cVec2 &ZW)
158: x(XY.x), y(XY.y), z(ZW.x), w(ZW.y) {}
161inline cVec4::cVec4(
const cVec3 &XYZ,
const float W)
162: x(XYZ.x), y(XYZ.y), z(XYZ.z), w(W) {}
165inline void cVec4::SetZero() {
166 x = y = z = w = 0.0f;
170inline void cVec4::Set(
const float S) {
175inline void cVec4::Set(
const float X,
const float Y,
const float Z,
const float W) {
183inline void cVec4::Set(
const cVec2 &XY,
const float Z,
const float W) {
191inline void cVec4::Set(
const cVec2 &XY,
const cVec2 &ZW) {
199inline void cVec4::Set(
const cVec3 &XYZ,
const float W) {
207inline void cVec4::Copy(
const float *pSrc) {
216inline float & cVec4::operator [] (
const int index) {
217 cAssert(index >= 0 && index < 4);
222inline float cVec4::operator [] (
const int index)
const {
223 cAssert(index >= 0 && index < 4);
228inline const cVec4 cVec4::operator - ()
const {
229 return cVec4(-x, -y, -z, -w);
233inline cVec4& cVec4::operator += (
const cVec4 &u) {
242inline cVec4& cVec4::operator -= (
const cVec4 &u) {
251inline cVec4& cVec4::operator *= (
const cVec4 &u) {
260inline cVec4& cVec4::operator *= (
const float s) {
269inline cVec4& cVec4::operator /= (
const cVec4 &u) {
278inline cVec4& cVec4::operator /= (
const float s) {
288inline const cVec4 cVec4::operator + (
const cVec4 &u)
const {
289 return cVec4(x + u.x, y + u.y, z + u.z, w + u.w);
293inline const cVec4 cVec4::operator - (
const cVec4 &u)
const {
294 return cVec4(x - u.x, y - u.y, z - u.z, w - u.w);
298inline const cVec4 cVec4::operator * (
const cVec4 &u)
const {
299 return cVec4(x * u.x, y * u.y, z * u.z, w * u.w);
303inline const cVec4 cVec4::operator * (
const float s)
const {
304 return cVec4(x * s, y * s, z * s, w * s);
308inline const cVec4 operator * (
const float s,
const cVec4 &u) {
309 return cVec4(s * u.x, s * u.y, s * u.z, s * u.w);
313inline const cVec4 cVec4::operator / (
const cVec4 &u)
const {
314 return cVec4(x / u.x, y / u.y, z / u.z, w / u.w);
318inline const cVec4 cVec4::operator / (
const float s)
const {
320 return cVec4(x * is, y * is, z * is, w * is);
324inline const cVec4 operator / (
const float s,
const cVec4 &u) {
325 return cVec4(s / u.x, s / u.y, s / u.z, s / u.w);
329inline bool cVec4::operator == (
const cVec4 &u)
const {
330 return x == u.x && y == u.y && z == u.z && w == u.w;
334inline bool cVec4::operator != (
const cVec4 &u)
const {
335 return x != u.x || y != u.y || z != u.z || w != u.w;
339inline bool cVec4::Equals(
const cVec4 &u,
const cVec4 &v,
const float Eps ) {
340 if(cMath::Abs(u.x - v.x) > Eps) {
343 if(cMath::Abs(u.y - v.y) > Eps) {
346 if(cMath::Abs(u.z - v.z) > Eps) {
349 if(cMath::Abs(u.w - v.w) > Eps) {
356inline float cVec4::Length()
const {
357 return sqrtf(x * x + y * y + z * z + w * w);
361inline float cVec4::LengthSq()
const {
362 return x * x + y * y + z * z + w * w;
366inline float cVec4::Normalize() {
367 const float l = Length();
375inline float cVec4::NormalizeSafe(
const cVec4 &Fallback ) {
376 const float l = Length();
377 if(l < cMath::Epsilon) {
379 cAssert(IsNormalized());
383 cAssert(IsNormalized());
389inline bool cVec4::IsNormalized(
const float Eps)
const {
390 return cMath::IsOne(LengthSq(), Eps);
394inline bool cVec4::IsZero(
const float Eps)
const {
395 if(!cMath::IsZero(x, Eps)) {
398 if(!cMath::IsZero(y, Eps)) {
401 if(!cMath::IsZero(z, Eps)) {
404 if(!cMath::IsZero(w, Eps)) {
411inline const cVec4 cVec4::Abs(
const cVec4 &u) {
412 return cVec4(cMath::Abs(u.x), cMath::Abs(u.y), cMath::Abs(u.z), cMath::Abs(u.w));
416inline float cVec4::Dot(
const cVec4 &u,
const cVec4 &v) {
417 return u.x * v.x + u.y * v.y + u.z * v.z + u.w * v.w;
421inline float cVec4::Length(
const cVec4 &u) {
422 return cMath::Sqrt(u.x * u.x + u.y * u.y + u.z * u.z + u.w * u.w);
426inline float cVec4::LengthSq(
const cVec4 &u) {
427 return u.x * u.x + u.y * u.y + u.z * u.z + u.w * u.w;
431inline const cVec4 cVec4::Lerp(
const cVec4 &u,
const cVec4 &v,
const float s) {
433 r.x = u.x + s * (v.x - u.x);
434 r.y = u.y + s * (v.y - u.y);
435 r.z = u.z + s * (v.z - u.z);
436 r.w = u.w + s * (v.w - u.w);
443 r.x = u.x > v.x ? u.x : v.x;
444 r.y = u.y > v.y ? u.y : v.y;
445 r.z = u.z > v.z ? u.z : v.z;
446 r.w = u.w > v.w ? u.w : v.w;
453 r.x = u.x < v.x ? u.x : v.x;
454 r.y = u.y < v.y ? u.y : v.y;
455 r.z = u.z < v.z ? u.z : v.z;
456 r.w = u.w < v.w ? u.w : v.w;
461inline const cVec4 cVec4::Normalize(
const cVec4 &u) {
462 const float l = cMath::Sqrt(u.x * u.x + u.y * u.y + u.z * u.z + u.w * u.w);
464 const float il = 1.0f / l;
465 return cVec4(u.x * il, u.y * il, u.z * il, u.w * il);
470inline std::tuple<float, float, float, float> cVec4::__getstate__() {
471 return std::make_tuple(x, y, z, w);
474inline void cVec4::__setstate__(
const std::tuple<float, float, float, float>& state) {
475 x = std::get<0>(state);
476 y = std::get<1>(state);
477 z = std::get<2>(state);
478 w = std::get<3>(state);
482inline const float * cVec4::ToFloatPtr()
const {
483 return (
const float *)&x;
487inline float * cVec4::ToFloatPtr() {
492inline const cVec2 & cVec4::ToVec2()
const {
493 return *
reinterpret_cast<const cVec2 *
>(
this);
497inline cVec2 & cVec4::ToVec2() {
498 return *
reinterpret_cast<cVec2 *
>(
this);
502inline const cVec3 & cVec4::ToVec3()
const {
503 return *
reinterpret_cast<const cVec3 *
>(
this);
507inline cVec3 & cVec4::ToVec3() {
508 return *
reinterpret_cast<cVec3 *
>(
this);
513cVec4::operator cVec<Type, 4>()
const {
514 return cVec<Type, 4>( ( Type )x, ( Type )y, ( Type )z, ( Type )w );
518inline int cVec4::GetDimension()
const {
The 4D-matrix, refer it as coat::mat4 in the Core API.
Definition cMat4.h:6
The 2D-vector, refer it as coat::vec2 in the Core API.
Definition cVec2.h:9
The 3D-vector, refer it as coat::vec3 in the Core API.
Definition cVec3.h:10
The 4D-vector, refer it as coat::vec4 in the Core API.
Definition cVec4.h:9