HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_CoordSpace.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: UT_CoordSpace.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * A 3D system of coordinates.
10  *
11  */
12 
13 #ifndef __UT_CoordSpace_h__
14 #define __UT_CoordSpace_h__
15 
16 #include "UT_API.h"
17 #include "UT_Axis.h"
18 #include "UT_Plane.h"
19 #include "UT_VectorTypes.h"
20 #include "UT_XformOrder.h"
21 #include <SYS/SYS_Deprecated.h>
22 
23 template <typename T>
25 {
26 public:
27  // Several constructors that define a plane as (X - point)*zaxis = 0
30  const UT_Vector3T<T> &point,
31  const UT_Vector3T<T> &axaxis,
32  const UT_Vector3T<T> &ayaxis,
33  const UT_Vector3T<T> *azaxis,
34  bool norm = true);
36  const UT_Vector3T<T> &p0,
37  const UT_Vector3T<T> &p1,
38  const UT_Vector3T<T> &p2);
39 
41 
42  // Flip the z axis by 180 degrees:
43  void negate();
44 
45  // Orient one axis and rotate the others accordingly, or set them all:
46  void xaxis(const UT_Vector3T<T> &x, bool norm = true,
47  bool allow_flip = true);
48  void yaxis(const UT_Vector3T<T> &y, bool norm = true,
49  bool allow_flip = true);
50  void zaxis(const UT_Vector3T<T> &z, bool norm = true,
51  bool allow_flip = true);
52  void setAxes(
53  const UT_Vector3T<T> &x,
54  const UT_Vector3T<T> &y,
55  const UT_Vector3T<T> &z,
56  bool norm = true);
57 
58  // Query the axes:
59  const UT_Vector3T<T> & xaxis() const { return myXAxis; }
60  const UT_Vector3T<T> & yaxis() const { return myYAxis; }
61  const UT_Vector3T<T> & zaxis() const { return myPlane.normal(); }
62 
63  // Set or query the origin:
64  const UT_Vector3T<T> & origin() const { return myPlane.point(); }
65  void setOrigin(const UT_Vector3T<T> &o)
66  { myPlane.setPoint(o); }
67 
68  // Rotate by a given angle, expressed in radians:
69  void rotate(
70  UT_Vector3T<T> &axis,
71  T theta,
72  bool norm = true);
73  void rotate(
75  T theta);
76 
77  // Assume we're given a rotation matrix
78  // Rotate about our own origin.
79  void rotate(const UT_Matrix3T<T> &rotmatx);
80 
81  // Apply an invertible transformation to the space.
82  void transform(const UT_Matrix4F &matx);
83  void transform(const UT_Matrix4D &matx);
84 
85  // Apply an invertible transformation to the space and return the inverted
86  // and transposed matrix in the non-const argument.
89 
90  // Set the transformation for this space to the identity matrix.
91  void identity();
92 
93  void getTransformMatrix(UT_Matrix4T<T> &matx) const;
94 
95  // This version of getTransformMatrix is consistent with the transform
96  // method: calling identity(), then transform(matrix), then
97  // getTransformMatrixPreservingOrigin() will return the value of "matrix".
98  // Doing the same but calling getTransformMatrix() will not return the
99  // value of "matrix".
101  UT_Matrix4T<T> &matx) const;
102 
103  void shiftOffset(T by_factor)
104  {
105  myPlane.shiftOffset(by_factor);
106  }
107 
109  {
110  myPlane.translate(offset);
111  }
112 
113  // Compute rotation from world space to us or vice-versa.
114  // Return the same value "crack()" does.
115  int fromWorldRotation(
116  T &rx, T &ry, T &rz,
117  const UT_XformOrder &order) const;
118  int toWorldRotation(
119  T &rx, T &ry, T &rz,
120  const UT_XformOrder &order) const;
121 
122  void convertToWorld(
123  UT_Vector3T<T> &rel) const;
125  UT_Vector3T<T> &rel) const;
126 
127  // Allow const operations on the underlying plane.
128  const UT_PlaneT<T> & plane() const { return myPlane; }
129 
130 private:
131  template <typename MATX>
132  inline void changeSpace(MATX &matx) const;
133 
134  UT_PlaneT<T> myPlane; // Use the plane's normal as the zaxis
135  UT_Vector3T<T> myXAxis; // Define the two other axes
136  UT_Vector3T<T> myYAxis;
137 };
138 
142 typedef UT_CoordSpaceT<float> UT_CoordSpace; // deprecated
143 
144 #include "UT_CoordSpaceImpl.h"
145 
146 #endif // __UT_CoordSpace_h__
void setOrigin(const UT_Vector3T< T > &o)
Definition: UT_CoordSpace.h:65
void getTransformMatrixPreservingOrigin(UT_Matrix4T< T > &matx) const
const UT_Vector3T< T > & yaxis() const
Definition: UT_CoordSpace.h:60
void convertToWorld(UT_Vector3T< T > &rel) const
void convertToWorldNoOriginAdj(UT_Vector3T< T > &rel) const
UT_CoordSpaceT< fpreal > UT_CoordSpaceR
int fromWorldRotation(T &rx, T &ry, T &rz, const UT_XformOrder &order) const
Transformation order of scales, rotates, and translates.
Definition: UT_XformOrder.h:23
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
void shiftOffset(T by_factor)
const UT_Vector3T< T > & origin() const
Definition: UT_CoordSpace.h:64
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLint y
Definition: glcorearb.h:103
void getTransformMatrix(UT_Matrix4T< T > &matx) const
3D Vector class.
void translate(const UT_Vector3T< T > &offset)
GLintptr offset
Definition: glcorearb.h:665
UT_CoordSpaceT< fpreal32 > UT_CoordSpaceF
void transformAndReturnNormalXform(UT_Matrix4F &matx)
const UT_Vector3T< T > & zaxis() const
Definition: UT_CoordSpace.h:61
void transform(const UT_Matrix4F &matx)
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
int toWorldRotation(T &rx, T &ry, T &rz, const UT_XformOrder &order) const
void rotate(UT_Vector3T< T > &axis, T theta, bool norm=true)
GLint GLenum GLint x
Definition: glcorearb.h:409
UT_CoordSpaceT< float > UT_CoordSpace
const UT_Vector3T< T > & xaxis() const
Definition: UT_CoordSpace.h:59
UT_PlaneType
Definition: UT_Plane.h:26
UT_CoordSpaceT(UT_PlaneType p=UT_PLANE_XY)
void setAxes(const UT_Vector3T< T > &x, const UT_Vector3T< T > &y, const UT_Vector3T< T > &z, bool norm=true)
UT_CoordSpaceT< fpreal64 > UT_CoordSpaceD
const UT_PlaneT< T > & plane() const