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