HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
22 template <typename T>
24 {
25 public:
26  // Several constructors that define a plane as (X - point)*zaxis = 0
29  const UT_Vector3T<T> &point,
30  const UT_Vector3T<T> &axaxis,
31  const UT_Vector3T<T> &ayaxis,
32  const UT_Vector3T<T> *azaxis,
33  bool norm = true);
35  const UT_Vector3T<T> &p0,
36  const UT_Vector3T<T> &p1,
37  const UT_Vector3T<T> &p2);
38 
40 
41  // Flip the z axis by 180 degrees:
42  void negate();
43 
44  // Orient one axis and rotate the others accordingly, or set them all:
45  void xaxis(const UT_Vector3T<T> &x, bool norm = true,
46  bool allow_flip = true);
47  void yaxis(const UT_Vector3T<T> &y, bool norm = true,
48  bool allow_flip = true);
49  void zaxis(const UT_Vector3T<T> &z, bool norm = true,
50  bool allow_flip = true);
51  void setAxes(
52  const UT_Vector3T<T> &x,
53  const UT_Vector3T<T> &y,
54  const UT_Vector3T<T> &z,
55  bool norm = true);
56 
57  // Query the axes:
58  const UT_Vector3T<T> & xaxis() const { return myXAxis; }
59  const UT_Vector3T<T> & yaxis() const { return myYAxis; }
60  const UT_Vector3T<T> & zaxis() const { return myPlane.normal(); }
61 
62  // Set or query the origin:
63  const UT_Vector3T<T> & origin() const { return myPlane.point(); }
64  void setOrigin(const UT_Vector3T<T> &o)
65  { myPlane.setPoint(o); }
66 
67  // Rotate by a given angle, expressed in radians:
68  void rotate(
69  UT_Vector3T<T> &axis,
70  T theta,
71  bool norm = true);
72  void rotate(
74  T theta);
75 
76  // Assume we're given a rotation matrix
77  // Rotate about our own origin.
78  void rotate(const UT_Matrix3T<T> &rotmatx);
79 
80  // Apply an invertible transformation to the plane: the method that takes
81  // a non-const matrix returns the inverted and transposed matrix.
82  void transform(const UT_Matrix4F &matx);
83  void transform( UT_Matrix4F &matx);
84  void transform(const UT_Matrix4D &matx);
85  void transform( UT_Matrix4D &matx);
86 
87  // Set the transformation for this space to the identity matrix.
88  void identity();
89 
90  void getTransformMatrix(UT_Matrix4T<T> &matx) const;
91 
92  // This version of getTransformMatrix is consistent with the transform
93  // method: calling identity(), then transform(matrix), then
94  // getTransformMatrixPreservingOrigin() will return the value of "matrix".
95  // Doing the same but calling getTransformMatrix() will not return the
96  // value of "matrix".
98  UT_Matrix4T<T> &matx) const;
99 
100  void shiftOffset(T by_factor)
101  {
102  myPlane.shiftOffset(by_factor);
103  }
104 
106  {
107  myPlane.translate(offset);
108  }
109 
110  // Compute rotation from world space to us or vice-versa.
111  // Return the same value "crack()" does.
112  int fromWorldRotation(
113  T &rx, T &ry, T &rz,
114  const UT_XformOrder &order) const;
115  int toWorldRotation(
116  T &rx, T &ry, T &rz,
117  const UT_XformOrder &order) const;
118 
119  void convertToWorld(
120  UT_Vector3T<T> &rel) const;
122  UT_Vector3T<T> &rel) const;
123 
124  // Allow const operations on the underlying plane.
125  const UT_PlaneT<T> & plane() const { return myPlane; }
126 
127 private:
128  template <typename MATX>
129  inline void changeSpace(MATX &matx) const;
130 
131  UT_PlaneT<T> myPlane; // Use the plane's normal as the zaxis
132  UT_Vector3T<T> myXAxis; // Define the two other axes
133  UT_Vector3T<T> myYAxis;
134 };
135 
139 typedef UT_CoordSpaceT<float> UT_CoordSpace; // deprecated
140 
141 #include "UT_CoordSpaceImpl.h"
142 
143 #endif // __UT_CoordSpace_h__
void setOrigin(const UT_Vector3T< T > &o)
Definition: UT_CoordSpace.h:64
void getTransformMatrixPreservingOrigin(UT_Matrix4T< T > &matx) const
const UT_Vector3T< T > & yaxis() const
Definition: UT_CoordSpace.h:59
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
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
void shiftOffset(T by_factor)
const UT_Vector3T< T > & origin() const
Definition: UT_CoordSpace.h:63
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLint y
Definition: glcorearb.h:102
void getTransformMatrix(UT_Matrix4T< T > &matx) const
3D Vector class.
void translate(const UT_Vector3T< T > &offset)
UT_CoordSpaceT< fpreal32 > UT_CoordSpaceF
const UT_Vector3T< T > & zaxis() const
Definition: UT_CoordSpace.h:60
GLintptr offset
Definition: glcorearb.h:664
void transform(const UT_Matrix4F &matx)
int toWorldRotation(T &rx, T &ry, T &rz, const UT_XformOrder &order) const
void rotate(UT_Vector3T< T > &axis, T theta, bool norm=true)
UT_CoordSpaceT< float > UT_CoordSpace
const UT_Vector3T< T > & xaxis() const
Definition: UT_CoordSpace.h:58
UT_PlaneType
Definition: UT_Plane.h:25
GLint GLenum GLint x
Definition: glcorearb.h:408
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