HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_ConAnchorRotational.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  */
7 
8 #ifndef __SIM_ConAnchorRotational_h__
9 #define __SIM_ConAnchorRotational_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_ConAnchor.h"
13 #include <UT/UT_Quaternion.h>
14 #include <UT/UT_Vector3.h>
15 
16 /// Rotational constraints are a bit odd.
17 /// We categorize constraints by the shape created by sweeping the
18 /// possible rotation axes through unconstrained space.
19 /// The numerical representation is thus the number of degrees that
20 /// have been constrained. "DOF" stands for "degrees of freedom".
22 {
23 public:
25 
26  /// We need better names for these.
27  enum SIM_DOFType {
28  /// DOF_FREE is a complete absence of any restrictions on
29  /// orientation. Any orientation is valid.
30  DOF_FREE = 0,
31  /// DOF_PLANEJOINT provides the mobility of a thick wire system.
32  /// The plane's axis can be made to look in any direction, but can't
33  /// be rotated freely.
34  /// Only rotations whose axes lie in a given plane are allowed.
35  DOF_PLANEJOINT = 1,
36  /// DOF_HINGE allows any orientation around a specific axis.
37  /// A specific axis is locked, rotating around that is allowed.
38  DOF_HINGE = 2,
39  /// DOF_ORIENT provides no free orientation.
40  /// Orientation completely locked down.
41  DOF_ORIENT = 3
42  };
43 
44  /// Static method for rendering the guide geometry for this type of anchor
46  const UT_Vector3& anchor_pos,
47  const UT_Quaternion& q,
48  int dofType, UT_Vector3 dofVector,
49  fpreal scale,
50  const GA_RWHandleV3& colour_attrib,
51  const UT_Vector3& color,
52  bool show_object_link,
53  bool is_affecting_object,
54  const UT_Vector3& obj_pos);
55 
56  GETSET_DATA_FUNCS_E(SIM_NAME_CONDOF, DOFTypeInput, SIM_DOFType);
57  /// All constraints are represented by a vector which is interpreted
58  /// differently depending on how many DOF will be constrained.
59  ///
60  /// If O is the orientation to constrain, and Q the rest orientation,
61  /// and V the vector:
62  /// Free constraint:
63  /// O = O
64  /// No constraint occurs.
65  ///
66  /// Plane constraint:
67  /// (O / Q) . V = 0
68  /// The rotation which maps from Q to O should not have any
69  /// component of V in it. This allows all orientations which
70  /// can be reached from Q by rotating around a vector perpendicular
71  /// to V.
72  ///
73  /// Hinge constraint:
74  /// (O / Q) = s V, for some s
75  /// There is one degree of freedom. The set of valid orientations
76  /// are those that can be reached from Q by rotating around V.
77  ///
78  /// Orient constraint:
79  /// O = Q
80  /// The quaternion is fully constrained.
81  ///
82  /// Through further abuse of notation, we can define the UnconDOFFilter
83  /// which when applied to an angular velocity will cause it to fulfill
84  /// those conditions. We can then clamp a quaternion O into the desired
85  /// value Q according to the filter uF with:
86  /// O' = ((uF) * (O / Q)) * Q
87  ///
88  /// (Note that uF is symmetric and O/Q a vector,
89  /// so we don't have to worry which side we multiply it on.)
90  ///
91  /// This vector is defined in *object* space.
92  /// (Ie, a value of (1, 0, 0) means that the X axis of the object should
93  /// point in the fashion that the X axis of O does)
94  GETSET_DATA_FUNCS_V3(SIM_NAME_CONDIR, DOFVectorInput);
95 
96  /// Overridable get/set for Rotation and DOF of constraint
97  const UT_Vector3 getRotation() const;
98  void setRotation(const UT_Vector3 &rotation);
99  SIM_DOFType getDOFType() const;
100  void setDOFType(const SIM_DOFType type);
101  const UT_Vector3 getDOFVector() const;
102  void setDOFVector(const UT_Vector3 &vector);
103 
104  /// Retrieve the world-space position for the guide geometry
105  UT_Vector3 getGuidePosition(const SIM_Time &t) const;
106 
107  /// Retrieve the world-space orientation to constrain to.
108  UT_Quaternion getOrientation(const SIM_Time &time) const;
109  UT_Vector3 getAngularVelocity(const SIM_Time &time) const;
110 
111  /// Retrieve number of constrained degrees of freedom.
112  int getNumConDOFs() const;
113 
114  /// Returns a matrix that, when multiplied by a angular velocity, gives
115  /// only the components of the angular velocity that are constrained.
116  void getConDOFFilter(UT_Matrix3 &result,
117  const SIM_Time &time) const;
118 
119  /// Opposite of getConDOFFilter().
120  /// getUnconDOFFilter() = identity - getConDOFFilter()
121  void getUnconDOFFilter(UT_Matrix3 &result,
122  const SIM_Time &time) const;
123 
124 protected:
125  explicit SIM_ConAnchorRotational(const SIM_DataFactory *f);
126  virtual ~SIM_ConAnchorRotational();
127 
129  const SIM_Options &options,
130  const GU_DetailHandle &gdh,
131  const SIM_Relationship &rel,
132  const SIM_Time &t) const;
133 
134  virtual UT_Vector3 getGuidePositionSubclass(
135  const SIM_Time &time) const;
136 
137  virtual UT_Quaternion getOrientationSubclass(
138  const SIM_Time &time) const = 0;
139  virtual UT_Vector3 getAngularVelocitySubclass(
140  const SIM_Time &time) const = 0;
141 
142  virtual const UT_Vector3 getRotationSubclass() const;
143  virtual SIM_DOFType getDOFTypeSubclass() const;
144  virtual const UT_Vector3 getDOFVectorSubclass() const;
145 
146 private:
149 };
150 
151 #endif
152 
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
#define SIM_NAME_CONDOF
Definition: SIM_Names.h:90
virtual void buildAnchorGuideGeometrySubclass(const SIM_Options &options, const GU_DetailHandle &gdh, const SIM_Relationship &rel, const SIM_Time &t) const
Default implementation does nothing.
GLuint color
Definition: glcorearb.h:1260
#define SIM_NAME_CONDIR
Definition: SIM_Names.h:88
3D Vector class.
#define GETSET_DATA_FUNCS_V3(DataName, FuncName)
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_API const UT_StringHolder scale
GLfloat f
Definition: glcorearb.h:1925
#define GETSET_DATA_FUNCS_E(DataName, FuncName, EnumType)
void buildAnchorGuideGeometry(const SIM_Options &options, const GU_DetailHandle &gdh, const SIM_Relationship &rel, const SIM_Time &t) const
SIM_DOFType
We need better names for these.
double fpreal
Definition: SYS_Types.h:269
#define SIM_API
Definition: SIM_API.h:10
#define SIM_NAME_ROTATION
Definition: SIM_Names.h:177
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
MatType rotation(const Quat< typename MatType::value_type > &q, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the rotation matrix specified by the given quaternion.
Definition: Mat.h:169