HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Vector3.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Utility Library (C++)
7  *
8  * COMMENTS:
9  * This class handles fpreal vectors of dimension 3.
10  *
11  * WARNING:
12  * This class should NOT contain any virtual methods, nor should it
13  * define more member data. The size of UT_Vector3 must always be
14  * 12 bytes (3 floats).
15  */
16 
17 #pragma once
18 
19 #ifndef __UT_Vector3_h__
20 #define __UT_Vector3_h__
21 
22 #include "UT_API.h"
23 #include "UT_Assert.h"
24 #include "UT_FixedVector.h"
25 #include "UT_VectorTypes.h"
26 #include "UT_Vector2.h"
27 #include <SYS/SYS_Deprecated.h>
28 #include <SYS/SYS_Inline.h>
29 #include <SYS/SYS_Math.h>
30 #include <SYS/SYS_TypeTraits.h>
31 #include <iosfwd>
32 #include <limits>
33 
34 class UT_IStream;
35 class UT_JSONWriter;
36 class UT_JSONValue;
37 class UT_JSONParser;
38 
39 // Free floating functions:
40 
41 // Right-multiply operators (M*v) have been removed. They had previously
42 // been defined to return v*M, which was too counterintuitive. Once HDK
43 // etc. users have a chance to update their code (post 7.0) we could
44 // reintroduce a right-multiply operator that does a colVecMult.
45 
46 template <typename T, typename S>
48 template <typename T, typename S>
50 template <typename T>
51 constexpr UT_Vector3T<T> operator+(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
52 template <typename T>
53 constexpr UT_Vector3T<T> operator-(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
54 template <typename T, typename S>
55 constexpr UT_Vector3T<T> operator+(const UT_Vector3T<T> &v, S scalar) noexcept;
56 template <typename T, typename S>
57 constexpr UT_Vector3T<T> operator-(const UT_Vector3T<T> &v, S scalar) noexcept;
58 template <typename T, typename S>
59 constexpr UT_Vector3T<T> operator*(const UT_Vector3T<T> &v, S scalar) noexcept;
60 template <typename T, typename S>
61 constexpr UT_Vector3T<T> operator/(const UT_Vector3T<T> &v, S scalar) noexcept;
62 template <typename T, typename S>
63 constexpr UT_Vector3T<T> operator+(S scalar, const UT_Vector3T<T> &v) noexcept;
64 template <typename T, typename S>
65 constexpr UT_Vector3T<T> operator-(S scalar, const UT_Vector3T<T> &v) noexcept;
66 template <typename T, typename S>
67 constexpr UT_Vector3T<T> operator*(S scalar, const UT_Vector3T<T> &v) noexcept;
68 template <typename T, typename S>
69 constexpr UT_Vector3T<T> operator/(S scalar, const UT_Vector3T<T> &v) noexcept;
70 
71 /// The dot and cross products between two vectors (see operator*() too)
72 // @{
73 template <typename T>
74 constexpr T dot(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
75 template <typename T>
76 constexpr UT_Vector3T<T> cross(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
77 // @}
78 
79 /// The angle between two vectors in radians
80 // @{
81 template <typename T>
83 // @}
84 
85 /// Componentwise min and maximum
86 template <typename T>
88 template <typename T>
90 
91 /// Componentwise linear interpolation
92 template <typename T,typename S>
93 inline UT_Vector3T<T> SYSlerp(const UT_Vector3T<T> &v1, const UT_Vector3T<T> &v2, S t);
94 
95 /// Componentwise inverse linear interpolation
96 template <typename T>
98 
99 /// Bilinear interpolation
100 template <typename T,typename S>
101 inline UT_Vector3T<T> SYSbilerp(const UT_Vector3T<T> &u0v0, const UT_Vector3T<T> &u1v0,
102  const UT_Vector3T<T> &u0v1, const UT_Vector3T<T> &u1v1,
103  S u, S v)
104 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
105 
106 /// Barycentric interpolation
107 template <typename T, typename S>
109  const UT_Vector3T<T> &v1, const UT_Vector3T<T> &v2, S u, S v)
110 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
111 
112 
113 /// Trilinear hat function over kernel widths in s.
114 template <typename T>
115 inline T SYStrihat(const UT_Vector3T<T> &v, const UT_Vector3T<T> &s);
116 
117 /// Gradient of trilinear hat function over kernel widths in s.
118 template <typename T>
120 
121 /// The orthogonal projection of a vector u onto a vector v
122 template <typename T>
123 inline UT_Vector3T<T> project(const UT_Vector3T<T> &u, const UT_Vector3T<T> &v);
124 
125 // TODO: make UT_Vector4 versions of these:
126 
127 /// Compute the distance between two points
128 template <typename T>
129 inline T distance3d(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &p2);
130 /// Compute the distance squared
131 template <typename T>
132 inline T distance2(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &p2);
133 template <typename T>
134 inline T segmentPointDist2(const UT_Vector3T<T> &pos,
135  const UT_Vector3T<T> &pt1,
136  const UT_Vector3T<T> &pt2 );
137 
138 /// Intersect the lines p1 + v1 * t1 and p2 + v2 * t2.
139 /// t1 and t2 are set so that the lines intersect when
140 /// projected to the plane defined by the two lines.
141 /// This function returns a value which indicates how close
142 /// to being parallel the lines are. Closer to zero means
143 /// more parallel. This is done so that the user of this
144 /// function can decide what epsilon they want to use.
145 template <typename T>
146 UT_API double intersectLines(const UT_Vector3T<T> &p1,
147  const UT_Vector3T<T> &v1,
148  const UT_Vector3T<T> &p2,
149  const UT_Vector3T<T> &v2,
150  T &t1, T &t2);
151 
152 /// Returns true if the segments from p0 to p1 and from a to b intersect, and
153 /// t will contain the parametric value of the intersection on the segment a-b.
154 /// Otherwise returns false. Parallel segments will return false. T is
155 /// guaranteed to be between 0.0 and 1.0 if this function returns true.
156 template <typename T>
158  const UT_Vector3T<T> &p1,
159  const UT_Vector3T<T> &a,
160  const UT_Vector3T<T> &b, T &t);
161 
162 /// Returns the U coordinates of the closest points on each of the two
163 /// parallel line segments
164 template <typename T>
166  const UT_Vector3T<T> &p1,
167  const UT_Vector3T<T> &a,
168  const UT_Vector3T<T> &b);
169 /// Returns the U coordinates of the closest points on each of the two
170 /// line segments
171 template <typename T>
173  const UT_Vector3T<T> &p1,
174  const UT_Vector3T<T> &a,
175  const UT_Vector3T<T> &b);
176 /// Returns the U coordinate of the point on line segment p0->p1
177 /// that is closest to a.
178 template <typename T>
180  const UT_Vector3T<T> &p0,
181  const UT_Vector3T<T> &p1,
182  const UT_Vector3T<T> &a);
183 
184 /// Returns the squared distance between two line segments: p0-p1 and a-b
185 template <typename T>
186 inline T segmentDistance2(const UT_Vector3T<T> &p0,
187  const UT_Vector3T<T> &p1,
188  const UT_Vector3T<T> &a,
189  const UT_Vector3T<T> &b);
190 /// Returns the distance between two line segments: p0-p1 and a-b
191 template <typename T>
192 inline T segmentDistance(const UT_Vector3T<T> &p0,
193  const UT_Vector3T<T> &p1,
194  const UT_Vector3T<T> &a,
195  const UT_Vector3T<T> &b);
196 /// 3D Vector class.
197 template <typename T>
198 class UT_API UT_Vector3T : public UT_FixedVector<T,3,true>
199 {
200 public:
202 
203  // These "using" statements are needed for operator=, operator*=, and
204  // distance, so that the ones in UT_FixedVector aren't hidden by the
205  // additional ones here.
206  using Base::operator=;
207  using Base::operator*=;
208  using Base::distance;
209 
210  // These "using" statements are needed for GCC and Clang, because
211  // otherwise, they ignore all members of UT_FixedVector when
212  // checking validity of code in functions in this class.
213  using Base::vec;
214  using Base::data;
215  using Base::normalize;
216  using Base::length2;
217 
218  typedef T value_type;
219  static constexpr int tuple_size = 3;
220 
221  /// Default constructor.
222  /// No data is initialized! Use it for extra speed.
223  SYS_FORCE_INLINE UT_Vector3T() = default;
224 
225  constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T<T> &that) = default;
226  constexpr SYS_FORCE_INLINE UT_Vector3T(UT_Vector3T<T> &&that) = default;
227 
228  constexpr explicit SYS_FORCE_INLINE UT_Vector3T(T v) noexcept :
229  Base(Base::CT::CF, v, v, v)
230  {}
231  constexpr SYS_FORCE_INLINE UT_Vector3T(const T vx, const T vy, const T vz) noexcept :
232  Base(Base::CT::CF, vx, vy, vz)
233  {}
234  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept
235  : Base(v)
236  {}
237  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal32 v[tuple_size]) noexcept
238  : Base(v)
239  {}
240  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept
241  : Base(v)
242  {}
243  constexpr SYS_FORCE_INLINE UT_Vector3T(const int32 v[tuple_size]) noexcept
244  : Base(v)
245  {}
246  constexpr SYS_FORCE_INLINE UT_Vector3T(const int64 v[tuple_size]) noexcept
247  : Base(v)
248  {}
249 
250  SYS_FORCE_INLINE explicit UT_Vector3T(const UT_Vector2T<T> &v);
251  SYS_FORCE_INLINE explicit UT_Vector3T(const UT_Vector4T<T> &v);
252 
253  /// Our own type of any given value_type.
254  template <typename S>
255  constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T<S> &v) noexcept
256  : Base(v)
257  {}
258 
259  /// Arbitrary UT_FixedVector of the same size
260  template <typename S,bool S_INSTANTIATED>
262  : Base(v)
263  {}
264 
265  constexpr SYS_FORCE_INLINE UT_Vector3T<T> &operator=(const UT_Vector3T<T> &that) = default;
266  constexpr SYS_FORCE_INLINE UT_Vector3T<T> &operator=(UT_Vector3T<T> &&that) = default;
267 
268  template <typename S>
270  { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
271 
272  /// Assignment operator that truncates a V4 to a V3.
273  /// TODO: remove this. This should require an explicit UT_Vector3()
274  /// construction, since it's unsafe.
275  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit UT_Vector3 constructor to avoid implicit conversion from UT_Vector4)
277 
278  /// It's unclear why this is needed, given UT_FixedVector::operator-(),
279  /// but the compiler seems not to accept not having it.
281  {
282  return UT_Vector3T<T>(-vec[0], -vec[1], -vec[2]);
283  }
284 
285  void clampZero(T tol = T(0.00001f))
286  {
287  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
288  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
289  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
290  }
291 
294  {
295  vec[0] *= v.vec[0];
296  vec[1] *= v.vec[1];
297  vec[2] *= v.vec[2];
298  }
299 
300  /// If you need a multiplication operator that left multiplies the vector
301  /// by a matrix (M * v), use the following colVecMult() functions. If
302  /// you'd rather not use operator*=() for right-multiplications (v * M),
303  /// use the following rowVecMult() functions. The methods that take a 4x4
304  /// matrix first extend this vector to 4D by adding an element equal to 1.0.
305  /// @internal These are implemented in UT_Matrix3.h and UT_Matrix4.h
306  // @{
315  // @}
316 
317 
318  /// This multiply will not extend the vector by adding a fourth element.
319  /// Instead, it converts the Matrix4 to a Matrix3. This means that
320  /// the translate component of the matrix is not applied to the vector
321  /// @internal These are implemented in UT_Matrix4.h
322  // @{
327  // @}
328 
329 
330 
331  /// The *=, multiply, multiply3 and multiplyT routines are provided for
332  /// legacy reasons. They all assume that *this is a row vector. Generally,
333  /// the rowVecMult and colVecMult methods are preferred, since they're
334  /// more explicit about the row vector assumption.
335  // @{
336  template <typename S>
338  template <typename S>
340 
341  template <typename S>
342  SYS_FORCE_INLINE void multiply3(const UT_Matrix4T<S> &mat);
343  // @}
344 
345  /// This multiply will multiply the (row) vector by the transpose of the
346  /// matrix instead of the matrix itself. This is faster than
347  /// transposing the matrix, then multiplying (as well there's potentially
348  /// less storage requirements).
349  // @{
350  template <typename S>
351  SYS_FORCE_INLINE void multiplyT(const UT_Matrix3T<S> &mat);
352  template <typename S>
353  SYS_FORCE_INLINE void multiply3T(const UT_Matrix4T<S> &mat);
354  // @}
355 
356  /// The following methods implement multiplies (row) vector by a matrix,
357  /// however, the resulting vector is specified by the dest parameter
358  /// These operations are safe even if "dest" is the same as "this".
359  // @{
360  template <typename S>
361  SYS_FORCE_INLINE void multiply3(UT_Vector3T<T> &dest,
362  const UT_Matrix4T<S> &mat) const;
363  template <typename S>
364  SYS_FORCE_INLINE void multiplyT(UT_Vector3T<T> &dest,
365  const UT_Matrix3T<S> &mat) const;
366  template <typename S>
367  SYS_FORCE_INLINE void multiply3T(UT_Vector3T<T> &dest,
368  const UT_Matrix4T<S> &mat) const;
369  template <typename S>
371  const UT_Matrix4T<S> &mat) const;
372  template <typename S>
374  const UT_Matrix3T<S> &mat) const;
375  // @}
376 
377  constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T<T> &v) noexcept
378  {
379  operator=(::cross(*this, v));
380  }
381 
383  {
384  vec[0] += (va.vec[2]+vb.vec[2])*(vb.vec[1]-va.vec[1]);
385  vec[1] += (va.vec[0]+vb.vec[0])*(vb.vec[2]-va.vec[2]);
386  vec[2] += (va.vec[1]+vb.vec[1])*(vb.vec[0]-va.vec[0]);
387  }
388 
389  /// Finds an arbitrary perpendicular to v, and sets this to it.
390  void arbitraryPerp(const UT_Vector3T<T> &v);
391  /// Makes this orthogonal to the given vector. If they are colinear,
392  /// does an arbitrary perp
393  void makeOrthonormal(const UT_Vector3T<T> &v);
394 
395  /// These allow you to find out what indices to use for different axes
396  // @{
397  int findMinAbsAxis() const
398  {
399  T ax = SYSabs(x()), ay = SYSabs(y());
400  if (ax < ay)
401  return (SYSabs(z()) < ax) ? 2 : 0;
402  else
403  return (SYSabs(z()) < ay) ? 2 : 1;
404  }
405  int findMaxAbsAxis() const
406  {
407  T ax = SYSabs(x()), ay = SYSabs(y());
408  if (ax >= ay)
409  return (SYSabs(z()) >= ax) ? 2 : 0;
410  else
411  return (SYSabs(z()) >= ay) ? 2 : 1;
412  }
413  // @}
414 
415  /// Given this vector as the z-axis, get a frame of reference such that the
416  /// X and Y vectors are orthonormal to the vector. This vector should be
417  /// normalized.
419  {
420  if (SYSabs(x()) < 0.6F) Y = UT_Vector3T<T>(1, 0, 0);
421  else if (SYSabs(z()) < 0.6F) Y = UT_Vector3T<T>(0, 1, 0);
422  else Y = UT_Vector3T<T>(0, 0, 1);
423  X = ::cross(Y, *this);
424  X.normalize();
425  Y = ::cross(*this, X);
426  }
427 
428  /// Calculates the orthogonal projection of a vector u on the *this vector
429  UT_Vector3T<T> project(const UT_Vector3T<T> &u) const;
430 
431  /// Create a matrix of projection onto this vector: the matrix transforms
432  /// a vector v into its projection on the direction of (*this) vector,
433  /// ie. dot(*this, v) * this->normalize();
434  /// If we need to be normalized, set norm to non-false.
435  template <typename S>
436  UT_Matrix3T<S> project(bool norm=true);
437 
438  /// Vector p (representing a point in 3-space) and vector v define
439  /// a line. This member returns the projection of "this" onto the
440  /// line (the point on the line that is closest to this point).
441  UT_Vector3T<T> projection(const UT_Vector3T<T> &p,
442  const UT_Vector3T<T> &v) const;
443 
444  /// Projects this onto the line segement [a,b]. The returned point
445  /// will lie between a and b.
446  UT_Vector3T<T> projectOnSegment(const UT_Vector3T<T> &va,
447  const UT_Vector3T<T> &vb) const;
448  /// Projects this onto the line segment [a, b]. The fpreal t is set
449  /// to the parametric position of intersection, a being 0 and b being 1.
450  UT_Vector3T<T> projectOnSegment(const UT_Vector3T<T> &va, const UT_Vector3T<T> &vb,
451  T &t) const;
452 
453  /// Create a matrix of symmetry around this vector: the matrix transforms
454  /// a vector v into its symmetry around (*this), ie. two times the
455  /// projection of v onto (*this) minus v.
456  /// If we need to be normalized, set norm to non-false.
457  UT_Matrix3 symmetry(bool norm=true);
458 
459  /// This method stores in (*this) the intersection between two 3D lines,
460  /// p1+t*v1 and p2+u*v2. If the two lines do not actually intersect, we
461  /// shift the 2nd line along the perpendicular on both lines (along the
462  /// line of min distance) and return the shifted intersection point; this
463  /// point thus lies on the 1st line.
464  /// If we find an intersection point (shifted or not) we return 0; if
465  /// the two lines are parallel we return -1; and if they intersect
466  /// behind our back we return -2. When we return -2 there still is a
467  /// valid intersection point in (*this).
468  int lineIntersect(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1,
469  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2);
470 
471  /// Compute the intersection of vector p2+t*v2 and the line segment between
472  /// points pa and pb. If the two lines do not intersect we shift the
473  /// (p2, v2) line along the line of min distance and return the point
474  /// where it intersects the segment. If we find an intersection point
475  /// along the stretch between pa and pb, we return 0. If the lines are
476  /// parallel we return -1. If they intersect before pa we return -2, and
477  /// if after pb, we return -3. The intersection point is valid with
478  /// return codes 0,-2,-3.
479  int segLineIntersect(const UT_Vector3T<T> &pa, const UT_Vector3T<T> &pb,
480  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2);
481 
482  /// Determines whether or not the points p0, p1 and "this" are collinear.
483  /// If they are t contains the parametric value of where "this" is found
484  /// on the segment from p0 to p1 and returns true. Otherwise returns
485  /// false. If p0 and p1 are equal, t is set to
486  /// std::numeric_limits<T>::max() and true is returned.
487  bool areCollinear(const UT_Vector3T<T> &p0, const UT_Vector3T<T> &p1,
488  T *t = 0, T tol = 1e-5) const;
489 
490  /// Compute (homogeneous) barycentric co-ordinates of this point
491  /// relative to the triangle defined by t0, t1 and t2. (The point is
492  /// projected into the triangle's plane.)
493  UT_Vector3T<T> getBary(const UT_Vector3T<T> &t0, const UT_Vector3T<T> &t1,
494  const UT_Vector3T<T> &t2, bool *degen = NULL) const;
495 
496 
497  /// Compute the signed distance from us to a line.
498  T distance(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1) const;
499  /// Compute the signed distance between two lines.
500  T distance(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1,
501  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2) const;
502 
503  /// Return the components of the vector. The () operator does NOT check
504  /// for the boundary condition.
505  /// @{
506  SYS_FORCE_INLINE T &x() { return vec[0]; }
507  SYS_FORCE_INLINE T x() const { return vec[0]; }
508  SYS_FORCE_INLINE T &y() { return vec[1]; }
509  SYS_FORCE_INLINE T y() const { return vec[1]; }
510  SYS_FORCE_INLINE T &z() { return vec[2]; }
511  SYS_FORCE_INLINE T z() const { return vec[2]; }
512  SYS_FORCE_INLINE T &r() { return vec[0]; }
513  SYS_FORCE_INLINE T r() const { return vec[0]; }
514  SYS_FORCE_INLINE T &g() { return vec[1]; }
515  SYS_FORCE_INLINE T g() const { return vec[1]; }
516  SYS_FORCE_INLINE T &b() { return vec[2]; }
517  SYS_FORCE_INLINE T b() const { return vec[2]; }
518 
519  constexpr SYS_FORCE_INLINE T &operator()(unsigned i) noexcept
520  {
521  UT_ASSERT_EXPR_P(i < tuple_size);
522  return vec[i];
523  }
524  constexpr SYS_FORCE_INLINE T operator()(unsigned i) const noexcept
525  {
526  UT_ASSERT_EXPR_P( i < tuple_size );
527  return vec[i];
528  }
529  /// @}
530 
531  /// Compute a hash
532  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
533 
534  // TODO: eliminate these methods. They're redundant, given good inline
535  // constructors.
536  /// Set the values of the vector components
537  void assign(T xx = 0.0f, T yy = 0.0f, T zz = 0.0f)
538  {
539  vec[0] = xx; vec[1] = yy; vec[2] = zz;
540  }
541  /// Set the values of the vector components
542  void assign(const T *v)
543  {
544  vec[0]=v[0]; vec[1]=v[1]; vec[2]=v[2];
545  }
546 
547  /// Express the point in homogeneous coordinates or vice-versa
548  // @{
549  void homogenize()
550  {
551  vec[0] *= vec[2];
552  vec[1] *= vec[2];
553  }
555  {
556  if (vec[2] != 0)
557  {
558  T denom = 1.0f / vec[2];
559  vec[0] *= denom;
560  vec[1] *= denom;
561  }
562  }
563  // @}
564 
565  /// assuming that "this" is a rotation (in radians, of course), the
566  /// equivalent set of rotations which are closest to the "base" rotation
567  /// are found. The equivalent rotations are the same as the original
568  /// rotations +2*n*PI
569  void roundAngles(const UT_Vector3T<T> &base);
570 
571  /// conversion between degrees and radians
572  // @{
573  void degToRad();
574  void radToDeg();
575  // @}
576 
577  /// It seems that given any rotation matrix and transform order,
578  /// there are two distinct triples of rotations that will result in
579  /// the same overall rotation. This method will find the closest of
580  /// the two after finding the closest using the above method.
581  void roundAngles(const UT_Vector3T<T> &b, const UT_XformOrder &o);
582 
583  /// Return the dual of the vector
584  /// The dual is a matrix which acts like the cross product when
585  /// multiplied by other vectors.
586  /// The following are equivalent:
587  /// a.getDual(A); c = colVecMult(A, b)
588  /// c = cross(a, b)
589  template <typename S>
590  void getDual(UT_Matrix3T<S> &dual) const;
591 
592  /// Protected I/O methods
593  // @{
594  void save(std::ostream &os, bool binary = false) const;
595  bool load(UT_IStream &is);
596  // @}
597 
598  /// @{
599  /// Methods to serialize to a JSON stream. The vector is stored as an
600  /// array of 3 reals.
601  bool save(UT_JSONWriter &w) const;
602  bool save(UT_JSONValue &v) const;
603  bool load(UT_JSONParser &p);
604  /// @}
605 
606  /// @{
607  /// Method to return the angle (in radians) between this and another vector
609  {
610  return ::UTangleBetween(*this, v);
611  }
612  /// @}
613 
614  /// Returns the vector size
615  static int entries() { return tuple_size; }
616 
617 private:
618  /// I/O friends
619  // @{
620  friend std::ostream &operator<<(std::ostream &os, const UT_Vector3T<T> &v)
621  {
622  v.save(os);
623  return os;
624  }
625  // @}
626 };
627 
628 // Required for constructor
629 #include "UT_Vector2.h"
630 #include "UT_Vector4.h"
631 
632 template <typename T>
634 {
635  vec[0] = v.x();
636  vec[1] = v.y();
637  vec[2] = T(0);
638 }
639 template <typename T>
641 {
642  vec[0] = v.x();
643  vec[1] = v.y();
644  vec[2] = v.z();
645 }
646 
647 // Free floating functions:
648 template <typename T>
649 constexpr
651 {
652  return UT_Vector3T<T>(a.vec[0]+b.vec[0], a.vec[1]+b.vec[1], a.vec[2]+b.vec[2]);
653 }
654 
655 template <typename T>
656 constexpr
658 {
659  return UT_Vector3T<T>(a.vec[0]-b.vec[0], a.vec[1]-b.vec[1], a.vec[2]-b.vec[2]);
660 }
661 
662 template <typename T, typename S>
663 constexpr
664 UT_Vector3T<T> operator+(const UT_Vector3T<T> &v, S scalar) noexcept
665 {
666  return UT_Vector3T<T>(v.vec[0]+scalar, v.vec[1]+scalar, v.vec[2]+scalar);
667 }
668 
669 template <typename T>
670 constexpr
672 {
673  return UT_Vector3T<T>(v1.vec[0]*v2.vec[0], v1.vec[1]*v2.vec[1], v1.vec[2]*v2.vec[2]);
674 }
675 
676 template <typename T>
677 constexpr
679 {
680  return UT_Vector3T<T>(v1.vec[0]/v2.vec[0], v1.vec[1]/v2.vec[1], v1.vec[2]/v2.vec[2]);
681 }
682 
683 template <typename T, typename S>
684 constexpr
685 UT_Vector3T<T> operator+(S scalar, const UT_Vector3T<T> &v) noexcept
686 {
687  return UT_Vector3T<T>(v.vec[0]+scalar, v.vec[1]+scalar, v.vec[2]+scalar);
688 }
689 
690 template <typename T, typename S>
691 constexpr
692 UT_Vector3T<T> operator-(const UT_Vector3T<T> &v, S scalar) noexcept
693 {
694  return UT_Vector3T<T>(v.vec[0]-scalar, v.vec[1]-scalar, v.vec[2]-scalar);
695 }
696 
697 template <typename T, typename S>
698 constexpr
699 UT_Vector3T<T> operator-(S scalar, const UT_Vector3T<T> &v) noexcept
700 {
701  return UT_Vector3T<T>(scalar-v.vec[0], scalar-v.vec[1], scalar-v.vec[2]);
702 }
703 
704 template <typename T, typename S>
705 constexpr
706 UT_Vector3T<T> operator*(const UT_Vector3T<T> &v, S scalar) noexcept
707 {
708  return UT_Vector3T<T>(v.vec[0]*scalar, v.vec[1]*scalar, v.vec[2]*scalar);
709 }
710 
711 template <typename T, typename S>
712 constexpr
713 UT_Vector3T<T> operator*(S scalar, const UT_Vector3T<T> &v) noexcept
714 {
715  return UT_Vector3T<T>(v.vec[0]*scalar, v.vec[1]*scalar, v.vec[2]*scalar);
716 }
717 
718 template <typename T, typename S>
719 constexpr
720 UT_Vector3T<T> operator/(const UT_Vector3T<T> &v, S scalar) noexcept
721 {
722  //TODO: in C++17, this can be "if constexpr"
723  if ( SYS_IsFloatingPoint_v< T > )
724  {
725  // This has to be T because S may be int for "v = v/2" code
726  // For the same reason we must cast the 1
727  T inv = T(1) / scalar;
728  return UT_Vector3T<T>(v.vec[0]*inv, v.vec[1]*inv, v.vec[2]*inv);
729  }
730  return UT_Vector3T<T>(v.vec[0]/scalar, v.vec[1]/scalar, v.vec[2]/scalar);
731 }
732 
733 template <typename T, typename S>
734 constexpr
735 UT_Vector3T<T> operator/(S scalar, const UT_Vector3T<T> &v) noexcept
736 {
737  return UT_Vector3T<T>(scalar/v.vec[0], scalar/v.vec[1], scalar/v.vec[2]);
738 }
739 
740 template <typename T>
741 constexpr
742 T dot(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept
743 {
744  return a.vec[0]*b.vec[0] + a.vec[1]*b.vec[1] + a.vec[2]*b.vec[2];
745 }
746 
747 template <typename T>
748 constexpr
750 {
751  return UT_Vector3T<T>(
752  a.vec[1]*b.vec[2] - a.vec[2]*b.vec[1],
753  a.vec[2]*b.vec[0] - a.vec[0]*b.vec[2],
754  a.vec[0]*b.vec[1] - a.vec[1]*b.vec[0]
755  );
756 }
757 
758 template <typename T>
759 inline
761 {
762  UT_Vector3T<fpreal64> v1crossv2 = cross(v1, v2);
763  fpreal v1dotv2 = dot(v1, v2);
764  return SYSatan2(v1crossv2.length(), v1dotv2);
765 }
766 
767 template <typename T>
768 inline
770 {
771  return UT_Vector3T<T>(SYSabs(v.x()), SYSabs(v.y()), SYSabs(v.z()));
772 }
773 
774 template <typename T>
775 inline
777 {
778  return UT_Vector3T<T>(
779  SYSmin(v1.x(), v2.x()),
780  SYSmin(v1.y(), v2.y()),
781  SYSmin(v1.z(), v2.z())
782  );
783 }
784 
785 template <typename T>
786 inline
788 {
789  return UT_Vector3T<T>(
790  SYSmax(v1.x(), v2.x()),
791  SYSmax(v1.y(), v2.y()),
792  SYSmax(v1.z(), v2.z())
793  );
794 }
795 
796 template <typename T,typename S>
797 inline
799 {
800  return UT_Vector3T<T>(
801  SYSlerp(v1.x(), v2.x(), t),
802  SYSlerp(v1.y(), v2.y(), t),
803  SYSlerp(v1.z(), v2.z(), t));
804 }
805 
806 template <typename T>
807 inline
809  const UT_Vector3T<T> &v2,
810  const UT_Vector3T<T> &t)
811 {
812  return UT_Vector3T<T>(
813  SYSlerp(v1.x(), v2.x(), t.x()),
814  SYSlerp(v1.y(), v2.y(), t.y()),
815  SYSlerp(v1.z(), v2.z(), t.z()));
816 }
817 
818 template <typename T>
819 inline
821  const UT_Vector3T<T> &v1,
822  const UT_Vector3T<T> &v2)
823 {
824  return UT_Vector3T<T>(
825  SYSinvlerp(a.x(), v1.x(), v2.x()),
826  SYSinvlerp(a.y(), v1.y(), v2.y()),
827  SYSinvlerp(a.z(), v1.z(), v2.z()));
828 }
829 
830 template <typename T>
831 inline
833  const UT_Vector3T<T> &min,
834  const UT_Vector3T<T> &max)
835 {
836  return UT_Vector3T<T>(
837  SYSclamp(v.x(), min.x(), max.x()),
838  SYSclamp(v.y(), min.y(), max.y()),
839  SYSclamp(v.z(), min.z(), max.z()));
840 }
841 
842 template <typename T>
843 inline
845 {
846  return SYSequalZero(v.x()) && SYSequalZero(v.y()) && SYSequalZero(v.z());
847 }
848 
849 template <typename T>
850 inline
852 {
853  return SYSisFinite(v.x()) && SYSisFinite(v.y()) && SYSisFinite(v.z());
854 }
855 
856 template <typename T>
857 inline
859 {
860  return UT_Vector3T<T>(SYSrecip(v[0]), SYSrecip(v[1]), SYSrecip(v[2]));
861 }
862 
863 template <typename T>
864 inline
866 {
867  return SYShat(v.x(), s.x()) * SYShat(v.y(), s.y()) * SYShat(v.z(), s.z());
868 }
869 
870 template <typename T>
871 inline
873 {
874  const T xhat = SYShat(v.x(), s.x());
875  const T yhat = SYShat(v.y(), s.y());
876  const T zhat = SYShat(v.z(), s.z());
877  return UT_Vector3T<T>(SYSdhat(v.x(), s.x()) * yhat * zhat,
878  xhat * SYSdhat(v.y(), s.y()) * zhat,
879  xhat * yhat * SYSdhat(v.z(), s.z()));
880 }
881 
882 template <typename T>
883 inline
885 {
886  return dot(u, v) / v.length2() * v;
887 }
888 
889 template <typename T>
890 inline
892 {
893  return (v1 - v2).length();
894 }
895 template <typename T>
896 inline
898 {
899  return (v1 - v2).length2();
900 }
901 
902 // calculate distance squared of pos to the line segment defined by pt1 to pt2
903 template <typename T>
904 inline
906  const UT_Vector3T<T> &pt1, const UT_Vector3T<T> &pt2 )
907 {
908  UT_Vector3T<T> vec;
909  T proj_t;
910  T veclen2;
911 
912  vec = pt2 - pt1;
913  proj_t = vec.dot( pos - pt1 );
914  veclen2 = vec.length2();
915 
916  if( proj_t <= (T)0.0 )
917  {
918  // in bottom cap region, calculate distance from pt1
919  vec = pos - pt1;
920  }
921  else if( proj_t >= veclen2 )
922  {
923  // in top cap region, calculate distance from pt2
924  vec = pos - pt2;
925  }
926  else
927  {
928  // middle region, calculate distance from projected pt
929  proj_t /= veclen2;
930  vec = (pt1 + (proj_t * vec)) - pos;
931  }
932 
933  return dot(vec, vec);
934 }
935 
936 // TODO: review the effiency of the following routine, there is a faster
937 // way to get just the distance.
938 template <typename T>
939 inline
941  const UT_Vector3T<T> &q0, const UT_Vector3T<T> &q1)
942 {
943  UT_Vector2 t = segmentClosest(p0, p1, q0, q1);
944  UT_Vector3 a = p0 + (p1 - p0) * t[0];
945  UT_Vector3 b = q0 + (q1 - q0) * t[1];
946  return distance2(a, b);
947 }
948 
949 template <typename T>
950 inline
952  const UT_Vector3T<T> &q0, const UT_Vector3T<T> &q1)
953 {
954  return SYSsqrt(segmentDistance2(p0, p1, q0, q1));
955 }
956 
957 /// Given a 3D position, input, and a 3D parallelpiped with corner p0 and
958 /// directions du, dv, and dw, finds the 0 or 1 locations in the parameter
959 /// space of that parallelpiped that correspond with the input position.
960 /// Only a parameter location approximately between 0 and 1
961 /// is accepted. The return value is the number of accepted parameter locations,
962 /// i.e. 0 or 1.
963 template <typename T>
965  const UT_Vector3T<T> &p0,
966  const UT_Vector3T<T> &du, const UT_Vector3T<T> &dv, const UT_Vector3T<T> &dw,
967  UT_Vector3T<T> &output)
968 {
969  const UT_Vector3T<T> orig = input - p0;
970 
971  const UT_Matrix3T<T> matrix(
972  du.x(), dv.x(), dw.x(),
973  du.y(), dv.y(), dw.y(),
974  du.z(), dv.z(), dw.z()
975  );
976 
977  bool failed = matrix.solve(orig.x(), orig.y(), orig.z(), output);
978  return !failed &&
979  SYSisGreaterOrEqual(output.x(), 0) && SYSisLessOrEqual(output.x(), 1) &&
980  SYSisGreaterOrEqual(output.y(), 0) && SYSisLessOrEqual(output.y(), 1) &&
981  SYSisGreaterOrEqual(output.z(), 0) && SYSisLessOrEqual(output.z(), 1);
982 }
983 
984 template <typename T>
985 inline size_t hash_value(const UT_Vector3T<T> &val)
986 {
987  return val.hash();
988 }
989 
990 // Overload for custom formatting of UT_Vector3T<T> with UTformat.
991 template<typename T>
992 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector3T<T> &v);
993 
994 
995 template<typename T>
997 {
999  typedef T DataType;
1000  static const exint TupleSize = 3;
1001  static const bool isVectorType = true;
1002 };
1003 
1004 #endif
UT_Vector3T< T > rowVecMult(const UT_Vector3T< T > &v, const UT_Matrix3T< S > &m)
Definition: UT_Matrix3.h:1477
UT_Vector3T< T > SYSlerp(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S t)
Componentwise linear interpolation.
Definition: UT_Vector3.h:798
constexpr SYS_FORCE_INLINE T operator()(unsigned i) const noexcept
Definition: UT_Vector3.h:524
UT_API double intersectLines(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &p2, const UT_Vector3T< T > &v2, T &t1, T &t2)
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.
Definition: Mat3.h:575
constexpr UT_Vector3T< T > cross(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
Definition: UT_Vector3.h:749
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
constexpr SYS_FORCE_INLINE UT_Vector3T(const int32 v[tuple_size]) noexcept
Definition: UT_Vector3.h:243
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal32 v[tuple_size]) noexcept
Definition: UT_Vector3.h:237
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector3.h:405
UT_Vector3T< T > SYSrecip(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:858
int int32
Definition: SYS_Types.h:39
constexpr T dot(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
Definition: UT_Vector3.h:742
UT_Vector3T< T > SYSbilerp(const UT_Vector3T< T > &u0v0, const UT_Vector3T< T > &u1v0, const UT_Vector3T< T > &u0v1, const UT_Vector3T< T > &u1v1, S u, S v)
Bilinear interpolation.
Definition: UT_Vector3.h:101
T distance2(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance squared.
Definition: UT_Vector3.h:897
T distance3d(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector3.h:891
int UTinverseTrilerpFlat(const UT_Vector3T< T > &input, const UT_Vector3T< T > &p0, const UT_Vector3T< T > &du, const UT_Vector3T< T > &dv, const UT_Vector3T< T > &dw, UT_Vector3T< T > &output)
Definition: UT_Vector3.h:964
UT_Vector3T< T > SYSabs(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:769
constexpr SYS_FORCE_INLINE UT_Vector3T(const int64 v[tuple_size]) noexcept
Definition: UT_Vector3.h:246
Transformation order of scales, rotates, and translates.
Definition: UT_XformOrder.h:23
void assign(const T *v)
Set the values of the vector components.
Definition: UT_Vector3.h:542
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.
Definition: Mat3.h:591
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLenum GLenum GLenum input
Definition: glew.h:14162
fpreal64 UTangleBetween(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
The angle between two vectors in radians.
Definition: UT_Vector3.h:760
int64 exint
Definition: SYS_Types.h:125
UT_Vector3T< T > SYSmin(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise min and maximum.
Definition: UT_Vector3.h:776
SYS_FORCE_INLINE T & g()
Definition: UT_Vector3.h:514
T segmentDistance(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the distance between two line segments: p0-p1 and a-b.
Definition: UT_Vector3.h:951
unsigned hash() const
Compute a hash.
Definition: UT_Vector3.h:532
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
SYS_FORCE_INLINE MF length() const
#define UT_API
Definition: UT_API.h:14
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition: glew.h:12900
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
static const exint TupleSize
SYS_FORCE_INLINE T & r()
Definition: UT_Vector3.h:512
UT_Vector3T< T > SYStrihatgrad(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Gradient of trilinear hat function over kernel widths in s.
Definition: UT_Vector3.h:872
T SYStrihat(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Trilinear hat function over kernel widths in s.
Definition: UT_Vector3.h:865
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:166
2D Vector class.
Definition: UT_Vector2.h:149
float fpreal32
Definition: SYS_Types.h:200
GLdouble GLdouble t
Definition: glew.h:1403
GLuint buffer
Definition: glcorearb.h:659
constexpr SYS_FORCE_INLINE T & operator()(unsigned i) noexcept
Definition: UT_Vector3.h:519
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept
Definition: UT_Vector3.h:234
constexpr SYS_FORCE_INLINE void operator*=(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) noexcept
T segmentPointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &pt1, const UT_Vector3T< T > &pt2)
Definition: UT_Vector3.h:905
GLint GLenum GLint x
Definition: glcorearb.h:408
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
double fpreal64
Definition: SYS_Types.h:201
SYS_FORCE_INLINE T z() const
Definition: UT_Vector3.h:511
void getFrameOfReference(UT_Vector3T< T > &X, UT_Vector3T< T > &Y) const
Definition: UT_Vector3.h:418
SYS_FORCE_INLINE T & b()
Definition: UT_Vector3.h:516
constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T< T > &v) noexcept
Definition: UT_Vector3.h:377
SYS_FORCE_INLINE MF normalize()
SYS_FORCE_INLINE T & y()
Definition: UT_Vector3.h:508
SYS_FORCE_INLINE T y() const
Definition: UT_Vector3.h:509
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T< S > &v) noexcept
Our own type of any given value_type.
Definition: UT_Vector3.h:255
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
constexpr UT_Vector3T< T > operator/(const UT_Vector3T< T > &v, S scalar) noexcept
Definition: UT_Vector3.h:720
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.
Definition: Mat3.h:601
UT_API UT_Vector2T< T > segmentClosest(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
GLsizei GLsizei GLfloat distance
Definition: glew.h:13923
void clampZero(T tol=T(0.00001f))
Definition: UT_Vector3.h:285
const GLdouble * v
Definition: glcorearb.h:836
size_t hash_value(const UT_Vector3T< T > &val)
Definition: UT_Vector3.h:985
static const bool isVectorType
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE T & z()
Definition: UT_Vector3.h:510
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:832
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
static int entries()
Returns the vector size.
Definition: UT_Vector3.h:615
constexpr SYS_FORCE_INLINE UT_Vector3T(const T vx, const T vy, const T vz) noexcept
Definition: UT_Vector3.h:231
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
UT_Vector3T< T > SYSmax(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Definition: UT_Vector3.h:787
UT_Vector3T< T > SYSbarycentric(const UT_Vector3T< T > &v0, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S u, S v)
Barycentric interpolation.
Definition: UT_Vector3.h:108
class UT_API UT_Vector3T
long long int64
Definition: SYS_Types.h:116
UT_API UT_Vector2T< T > segmentClosestParallel(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
GLfloat GLfloat p
Definition: glew.h:16656
constexpr SYS_FORCE_INLINE UT_Vector3T(T v) noexcept
Definition: UT_Vector3.h:228
T segmentDistance2(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the squared distance between two line segments: p0-p1 and a-b.
Definition: UT_Vector3.h:940
constexpr SYS_FORCE_INLINE UT_FixedVector & operator=(const UT_FixedVector &that)=default
#define UT_ASSERT_EXPR_P(ZZ)
Definition: UT_Assert.h:167
UT_Vector3T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix4.h:1881
SYS_FORCE_INLINE UT_StorageNum< typename UT_StorageBetter< T, S >::Type >::MathFloat distance(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) const
GLfloat v0
Definition: glcorearb.h:815
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept
Definition: UT_Vector3.h:240
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_FixedVector< S, tuple_size, S_INSTANTIATED > &v) noexcept
Arbitrary UT_FixedVector of the same size.
Definition: UT_Vector3.h:261
GLuint GLenum matrix
Definition: glew.h:15055
bool SYSisFinite(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:851
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector3.h:554
constexpr SYS_FORCE_INLINE UT_StorageAtLeast32Bit< T, T >::Type length2() const noexcept
UT_FixedVector< T, 3, true > Base
Definition: UT_Vector3.h:201
bool SYSequalZero(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:844
GLboolean * data
Definition: glcorearb.h:130
SYS_FORCE_INLINE UT_StorageAtLeast32Bit< T, S >::Type dot(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that) const
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f)
Set the values of the vector components.
Definition: UT_Vector3.h:537
SYS_FORCE_INLINE UT_Vector3T< T > & operator=(const UT_Vector3T< S > &v)
Definition: UT_Vector3.h:269
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector3.h:549
GLuint GLfloat * val
Definition: glcorearb.h:1607
SYS_FORCE_INLINE T g() const
Definition: UT_Vector3.h:515
UT_Vector3T< T > SYSinvlerp(const UT_Vector3T< T > &a, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise inverse linear interpolation.
Definition: UT_Vector3.h:820
constexpr SYS_FORCE_INLINE const T * data() const noexcept
UT_API bool intersectSegments(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b, T &t)
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator-() const noexcept
Definition: UT_Vector3.h:280
UT_Vector3T< T > rowVecMult3(const UT_Vector3T< T > &v, const UT_Matrix4T< S > &m)
Definition: UT_Matrix4.h:1859
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_FixedVector< T, 3 > FixedVectorType
Definition: UT_Vector3.h:998
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition: glew.h:12900
UT_Vector3T< T > colVecMult(const UT_Matrix3T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix3.h:1495
const GLdouble * m
Definition: glew.h:9166
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:77
GLfloat f
Definition: glcorearb.h:1925
SYS_FORCE_INLINE T & x()
Definition: UT_Vector3.h:506
fp normalize(fp value)
Definition: format-inl.h:1160
SYS_FORCE_INLINE T b() const
Definition: UT_Vector3.h:517
SYS_FORCE_INLINE UT_Vector3T()=default
#define const
Definition: zconf.h:214
GLfloat GLfloat v1
Definition: glcorearb.h:816
UT_Vector3T< T > project(const UT_Vector3T< T > &u, const UT_Vector3T< T > &v)
The orthogonal projection of a vector u onto a vector v.
Definition: UT_Vector3.h:884
SYS_FORCE_INLINE void normal(const UT_Vector3T< T > &va, const UT_Vector3T< T > &vb)
Definition: UT_Vector3.h:382
SYS_FORCE_INLINE void multiplyComponents(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:293
GLdouble s
Definition: glew.h:1395
uint64_t multiply(uint64_t lhs, uint64_t rhs)
Definition: format-inl.h:1178
GLint y
Definition: glcorearb.h:102
SYS_FORCE_INLINE T r() const
Definition: UT_Vector3.h:513
SYS_FORCE_INLINE T x() const
Definition: UT_Vector3.h:507
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector3T< T > &v)
fpreal64 angleTo(const UT_Vector3T< T > &v) const
Definition: UT_Vector3.h:608
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector3.h:397