123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #pragma once
- #include <cmath>
- #include <float.h>
- #include <string.h>
- #if MATH_CHECK_INDEXES
- #include <assert.h>
- #endif
- #include "rotations.h"
- template <typename T>
- class Matrix4;
- template <typename T>
- class Vector4
- {
- public:
- T M0, M1, M2, M3;
-
- constexpr Vector4<T>()
- : M0(0)
- , M1(0)
- , M2(0)
- , M3(0){}
-
- constexpr Vector4<T>(const T x0, const T x1, const T x2,const T x3)
- : M0(x0)
- , M1(x1)
- , M2(x2)
- , M3(x3){}
-
- void operator ()(const T x0, const T x1, const T x2,const T x3)
- {
- M0= x0; M1= x1; M2= x2;M3= x3;
- }
-
- float length(void) const;
-
- T operator *(const Vector4<T> &v) const;
-
- Vector4<T> operator *(const T num) const;
-
- Vector4<T> &operator *=(const T num);
-
- Vector4<T> &operator /=(const T num);
-
- Vector4<T> operator /(const T num) const;
-
- Vector4<T> &operator -=(const Vector4<T> &v);
-
- Vector4<T> operator -(const Vector4<T> &v) const;
-
- Vector4<T> operator -(void) const;
-
- Vector4<T> &operator +=(const Vector4<T> &v);
-
- Vector4<T> operator +(const Vector4<T> &v) const;
-
- bool operator ==(const Vector4<T> &v) const;
-
- bool operator !=(const Vector4<T> &v) const;
-
- Vector4<T> &operator *=(const Vector4<T> &v) {
- M0 *= v.M0; M1 *= v.M1; M2 *= v.M2;M3 *= v.M3;
- return *this;
- }
-
- bool is_nan(void) const WARN_IF_UNUSED;
-
- bool is_inf(void) const WARN_IF_UNUSED;
-
- bool is_zero(void) const WARN_IF_UNUSED {
- return (fabsf(M0) < FLT_EPSILON) &&
- (fabsf(M1) < FLT_EPSILON) &&
- (fabsf(M2) < FLT_EPSILON) &&
- (fabsf(M3) < FLT_EPSILON);
- }
-
- T length_squared() const
- {
- return (T)(*this * *this);
- }
-
- void normalize()
- {
- *this /= length();
- }
-
- void zero()
- {
- M0 = M1 = M2 = M3 = 0;
- }
-
- Vector4<T> normalized() const
- {
- return *this/length();
- }
-
- };
- typedef Vector4<int16_t> Vector4i;
- typedef Vector4<uint16_t> Vector4ui;
- typedef Vector4<int32_t> Vector4l;
- typedef Vector4<uint32_t> Vector4ul;
- typedef Vector4<float> Vector4f;
|