HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_ConAnchorSpatial.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_ConAnchorSpatial_h__
9 #define __SIM_ConAnchorSpatial_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 // TODO: Read over this comment and make sure it all still makes sense:
17 
18 /// Normally, constraints affect all three positional degrees of freedom
19 /// of an object. Some constraints, however, can limit their action to
20 /// only one or two degrees of freedom. For example, a hard constraint
21 /// might only force geometry to follow the anchor in y, and leave the x
22 /// and z DOFs unconstrained. In these situations, the constraint is
23 /// completely independent of the unconstrained DOFs - movement of the
24 /// geometry in unconstrained directions has no effect on the constraint
25 /// (e.g., doesn't affect springs), and the constraint never has an effect
26 /// in these DOFs (e.g., the constraint will never cause movement in x or z
27 /// in the earlier example).
29 {
30 public:
31  /// We categorize constraints by the shape created by sweeping a point
32  /// through unconstrained space. The numerical representation
33  /// is thus the number of degrees that have been constrained.
34  /// "DOF" stands for "degrees of freedom".
35  enum SIM_DOFType {
36  DOF_SPACE = 0, /// Any point in space is valid.
37  /// (i.e., constraint has no effect)
38  DOF_PLANE = 1, /// Any point on a plane is valid.
39  DOF_LINE = 2, /// Any point on a line is valid.
40  DOF_POINT = 3 /// Only one point is valid
41  /// (i.e., constraint prevents all movement)
42  };
43 
44  /// Static method for rendering the guide geometry for this type of anchor
46  const UT_Vector3& anchor_pos,
47  int dofType, UT_Vector3 dofVector,
48  fpreal scale,
49  const GA_RWHandleV3& colour_attrib,
50  const UT_Vector3& color,
51  bool show_object_link,
52  bool is_affecting_object,
53  const UT_Vector3& obj_pos);
54 
55  GETSET_DATA_FUNCS_E(SIM_NAME_CONDOF, DOFTypeInput, SIM_DOFType);
56  /// All constraints are represented by a vector which is interpreted
57  /// differently depending on how many DOF will be constrained.
58  /// This is troublesome as it only works in 3d. Ideally, we
59  /// should specify two types of constraints:
60  /// If P is the point to constrain, and R the rest point, and V
61  /// the vector, we have:
62  /// Normal constraint:
63  /// dot(V, P) = dot(V, R)
64  /// This removes one degree of freedom. Equivalent to PLANE.
65  /// Vector constraint:
66  /// P - R = s V, for some s
67  /// This removes all but one degree of freedom. Equivalent to LINE.
68  /// The result of this is always normalized.
69  ///
70  /// We can then define the UnconDOFFilter which, when applied to a velocity,
71  /// will cause it to fulfill those conditions. We can then clamp
72  /// a position P to a rest position R with the filter uF with:
73  /// P' = (uF * (P - R)) + R
74  /// (Note that we can also use the ConDOFFilter with the following
75  /// equation:
76  /// P' = (F * (R - P)) + P
77  /// We present it with the unconstrained case to match the rotational
78  /// case which is harder to rearrange)
79  ///
80  /// This vector is defined in simulation space, and may not be
81  /// normalized.
82  GETSET_DATA_FUNCS_V3(SIM_NAME_CONDIR, DOFVectorInput);
83 
84  /// Overridable get/set for the DOF of the constraint
85  SIM_DOFType getDOFType() const;
86  void setDOFType(const SIM_DOFType type);
87  const UT_Vector3 getDOFVector() const;
88  void setDOFVector(const UT_Vector3 &vector);
89 
90  /// Retrieve the world-space position to constrain to.
91  UT_Vector3 getPosition(const SIM_Time &time) const;
92  UT_Vector3 getVelocity(const SIM_Time &time) const;
93 
94  /// Retrieve number of constrained degrees of freedom.
95  int getNumConDOFs() const;
96  /// Returns a matrix that, when multiplied by a vector, gives only the
97  /// components of the vector that are constrained.
98  void getConDOFFilter(UT_Matrix3 &result,
99  const SIM_Time &time) const;
100 
101  /// Opposite of getConDOFFilter().
102  /// getUnconDOFFilter() = identity - getConDOFFilter()
103  void getUnconDOFFilter(UT_Matrix3 &result,
104  const SIM_Time &time) const;
105 
106 protected:
107  explicit SIM_ConAnchorSpatial(const SIM_DataFactory *factory);
108  virtual ~SIM_ConAnchorSpatial();
109 
111  const SIM_Options &options,
112  const GU_DetailHandle &gdh,
113  const SIM_Relationship &rel,
114  const SIM_Time &t) const;
115 
116  virtual UT_Vector3 getPositionSubclass(const SIM_Time &time) const = 0;
117  virtual UT_Vector3 getVelocitySubclass(const SIM_Time &) const;
118 
119  virtual SIM_DOFType getDOFTypeSubclass() const;
120  virtual const UT_Vector3 getDOFVectorSubclass() const;
121 
122 private:
125 };
126 
127 #endif
#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
GT_API const UT_StringHolder time
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
#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
double fpreal
Definition: SYS_Types.h:270
#define SIM_API
Definition: SIM_API.h:10
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107