20 #ifndef __UT_Vector4_h__
21 #define __UT_Vector4_h__
33 #ifndef UT_DISABLE_VECTORIZE_MATRIX
49 template <
typename T,
typename S>
55 template <
typename T,
typename S>
57 template <
typename T,
typename S>
59 template <
typename T,
typename S>
61 template <
typename T,
typename S>
63 template <
typename T,
typename S>
65 template <
typename T,
typename S>
67 template <
typename T,
typename S>
69 template <
typename T,
typename S>
99 template <
typename T,
typename S>
102 template <
typename T>
106 template <
typename T,
typename S>
113 template <
typename T,
typename S>
116 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
136 template <
typename T,
typename S>
138 template <
typename T,
typename S>
141 template <
typename T,
typename S>
143 template <
typename T,
typename S>
149 template <
typename T>
151 template <
typename T>
153 template <
typename T>
156 template <
typename T>
159 template <
typename T>
165 template <
typename T>
174 using Base::operator=;
175 using Base::operator*=;
186 static constexpr
int tuple_size = 4;
218 template <
typename S>
224 template <
typename S,
bool S_INSTANTIATED>
232 template <
typename S>
234 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3];
249 return (vec[0] >= -tol && vec[0] <= tol) &&
250 (vec[1] >= -tol && vec[1] <= tol) &&
251 (vec[2] >= -tol && vec[2] <= tol);
256 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
257 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
258 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
259 if (vec[3] >= -tol && vec[3] <= tol) vec[3] = 0;
264 if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
265 if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
266 if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
270 { vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2]; }
290 template <
typename S>
293 template <
typename S>
303 template <
typename S>
313 template <
typename S>
318 template <
typename S>
321 template <
typename S>
383 inline T &
x() {
return vec[0]; }
384 inline T x()
const {
return vec[0]; }
385 inline T &
y() {
return vec[1]; }
386 inline T y()
const {
return vec[1]; }
387 inline T &
z() {
return vec[2]; }
388 inline T z()
const {
return vec[2]; }
389 inline T &
w() {
return vec[3]; }
390 inline T w()
const {
return vec[3]; }
404 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
412 vec[0] = xx; vec[1] = yy; vec[2] = zz; vec[3] = ww;
420 if (
size == tuple_size) vec[3] = v[3];
435 T denom = 1.0f / vec[3];
443 void save(std::ostream &os,
int binary=0)
const;
460 friend std::ostream &operator<<(std::ostream &os, const UT_Vector4T<T> &
v)
482 template <
typename T>
490 template <
typename T>
499 #ifndef UT_DISABLE_VECTORIZE_MATRIX
500 template <>
inline void
507 vm_store(this->
data(), l.vector);
511 template <
typename T>
515 return ((vec[0]>=vect.
x()-tol) && (vec[0]<=vect.
x()+tol) &&
516 (vec[1]>=vect.
y()-tol) && (vec[1]<=vect.
y()+tol) &&
517 (vec[2]>=vect.
z()-tol) && (vec[2]<=vect.
z()+tol));
521 template <
typename T>
525 v1.
z()+v2.
z(), v1.
w()+v2.
w());
527 template <
typename T>
533 template <
typename T>
539 template <
typename T>
543 v1.
z()-v2.
z(), v1.
w()-v2.
w());
545 template <
typename T>
551 template <
typename T>
557 template <
typename T>
563 template <
typename T>
568 #ifndef UT_DISABLE_VECTORIZE_MATRIX
587 template <
typename T,
typename S>
592 template <
typename T,
typename S>
597 template <
typename T,
typename S>
602 template <
typename T,
typename S>
607 template <
typename T,
typename S>
612 template <
typename T,
typename S>
617 template <
typename T,
typename S>
622 T inv = ((
T)1) / scalar;
625 template <
typename T,
typename S>
630 template <
typename T>
633 return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z() + v1.
w()*v2.
w();
635 #ifndef UT_DISABLE_VECTORIZE_MATRIX
643 template <
typename T>
646 return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z();
648 template <
typename T>
651 return v1.
x()*v2.
x() + v1.
y()*v2.
y() + v1.
z()*v2.
z();
653 template <
typename T>
665 template <
typename T>
677 template <
typename T>
689 template <
typename T,
typename S>
699 #ifndef UT_DISABLE_VECTORIZE_MATRIX
711 template <
typename T>
725 template <
typename T,
typename S>
730 template <
typename T>
737 return SYSsqrt(x*x + y*y + z*z + w*w);
739 template <
typename T>
745 return SYSsqrt(x*x + y*y + z*z);
748 #ifndef UT_DISABLE_VECTORIZE_MATRIX
757 return SYSsqrt(result[0] + result[1] + result[2] + result[3]);
767 return SYSsqrt(result[0] + result[1] + result[2]);
771 template <
typename T>
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T< T > &v)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
constexpr SYS_FORCE_INLINE UT_FixedVector< T, SIZE > operator-() const noexcept
UT_Vector4T< T > operator/(const UT_Vector4T< T > &v, S scalar)
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[tuple_size])
UT_Vector4T< T > SYSlerp(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S t)
Componentwise linear interpolation.
UT_Vector4T< T > SYSmin(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Componentwise min and maximum.
unsigned hash() const
Compute a hash.
T operator()(unsigned i) const
SYS_FORCE_INLINE UT_Vector4T(const UT_FixedVector< S, tuple_size, S_INSTANTIATED > &v)
Arbitrary UT_FixedVector of the same size.
void multiplyComponents(const UT_Vector4T< T > &v)
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T< S > &v)
Our own type of any given value_type.
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
void colVecMult(const UT_Matrix4T< S > &m)
JSON reader class which handles parsing of JSON or bJSON files.
Class which writes ASCII or binary JSON streams.
int isEqual(const UT_Vector3T< T > &vect, T tol=0.00001f) const
static const exint TupleSize
size_t hash_value(const UT_Vector4T< T > &val)
SYS_FORCE_INLINE UT_Vector4T()=default
GLubyte GLubyte GLubyte GLubyte w
UT_Vector4T< T > SYSmax(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
UT_API UT_Vector4T< T > rowVecMult3(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
void clampZero(T tol=0.00001f)
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
GLfloat GLfloat GLfloat v2
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
static const bool isVectorType
GLboolean GLboolean GLboolean GLboolean a
void multiply3(UT_Vector4T< T > &dest, const UT_Matrix4T< S > &mat) const
UT_Vector4T< T > SYSinvlerp(const UT_Vector4T< T > &a, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
constexpr SYS_FORCE_INLINE UT_Vector4T(const int32 v[tuple_size])
GLdouble GLdouble GLdouble z
UT_API UT_Vector3T< T > cross(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
T & operator()(unsigned i)
constexpr SYS_FORCE_INLINE UT_FixedVector & operator=(const UT_FixedVector &that)=default
constexpr SYS_FORCE_INLINE UT_Vector4T(T vx, T vy, T vz, T vw=1.0f)
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
UT_Vector4T< T > & operator*=(const UT_Matrix4T< S > &mat)
T distance4(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< S > &v)
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f, T ww=1.0f)
Set the values of the vector components.
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
UT_Vector4T< T > SYSbilerp(const UT_Vector4T< T > &u0v0, const UT_Vector4T< T > &u1v0, const UT_Vector4T< T > &u0v1, const UT_Vector4T< T > &u1v1, S u, S v)
Bilinear interpolation.
UT_FixedVector< T, 4 > FixedVectorType
void rowVecMult(const UT_Matrix4T< S > &m)
SYS_FORCE_INLINE bool isEqual(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that, S tol=S(SYS_FTOLERANCE)) const
static int entries()
Returns the vector size.
UT_API UT_Vector4T< T > rowVecMult(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
UT_Vector4T< T > SYSabs(const UT_Vector4T< T > &v)
void assign(const T *v, int size=tuple_size)
Set the values of the vector components.
Class to store JSON objects as C++ objects.
void multiply3(const UT_Matrix4T< S > &mat)
constexpr SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[tuple_size])
UT_Vector4T< T > SYSbarycentric(const UT_Vector4T< T > &v0, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S u, S v)
Barycentric interpolation.
T distance3d(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
T dot(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
The dot product between two vectors.
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
void clampZero3(T tol=0.00001f)
int equalZero3(T tol=0.00001f) const
void rowVecMult3(const UT_Matrix4T< S > &m)
constexpr SYS_FORCE_INLINE UT_Vector4T(const int64 v[tuple_size])
T distance3(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
UT_FixedVector< T, 4, true > Base