HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_ConRelSoftAttach.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_ConRelSoftAttach_h__
9 #define __SIM_ConRelSoftAttach_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_ConRel.h"
13 #include "SIM_OptionsUser.h"
14 #include <UT/UT_Vector3.h>
15 #include <UT/UT_Matrix3.h>
16 
18 
19 /// Defines a soft attachment force between two anchors.
20 ///
21 /// The force is expressed mathematically as:
22 /// F = -k * x
23 /// with a damping force of
24 /// Fd = -kd * v
25 /// where x is the vector connecting the two anchors and v is dx/dt.
26 ///
28  public SIM_OptionsUser
29 {
30 public:
31  /// Retrieve the force (and optional jacobian) acting on objAnchor from a
32  /// spring.
33  UT_Vector3 getForce(const SIM_Time &time,
34  const SIM_ConAnchorSpatial &objAnchor,
35  const SIM_ConAnchorSpatial &otherAnchor,
36  UT_Matrix3 *jacobianPos = NULL,
37  UT_Matrix3 *jacobianVel = NULL);
38  UT_Vector3 getForce(const UT_Vector3 &objAnchorPos,
39  const UT_Vector3 &objAnchorVel,
40  const UT_Vector3 &otherAnchorPos,
41  const UT_Vector3 &otherAnchorVel,
42  const UT_Matrix3 &dofFilter);
43  UT_Vector3 getTorque(const UT_Quaternion &objOrient,
44  const UT_Vector3 &objAngVel,
45  const UT_Quaternion &anchorOrient,
46  const UT_Vector3 &anchorAngVel);
47 
48  /// Get Jacobian with respect to position, dF/dx. The returned Jacobian
49  /// is w.r.t. the obj point (dF_i/dx_i); the Jacobian for the other
50  /// point is the same thing, just negated (dF_i/dx_j = -dF_i/dx_i)
51  UT_Matrix3 getJacobianPos(const UT_Vector3 &objAnchorPos,
52  const UT_Vector3 &objAnchorVel,
53  const UT_Vector3 &otherAnchorPos,
54  const UT_Vector3 &otherAnchorVel,
55  const UT_Matrix3 &dofFilter) const;
56  /// Get Jacobian with respect to velocity, dF/dv. Same caveats as dF/dx.
57  UT_Matrix3 getJacobianVel(const UT_Vector3 &objAnchorPos,
58  const UT_Vector3 &objAnchorVel,
59  const UT_Vector3 &otherAnchorPos,
60  const UT_Vector3 &otherAnchorVel,
61  const UT_Matrix3 &dofFilter) const;
62 
65 
66 protected:
67  explicit SIM_ConRelSoftAttach(const SIM_DataFactory *factory);
68  ~SIM_ConRelSoftAttach() override;
69 
70  void setStateForceSubclass(fpreal force) override;
71  fpreal getStateForceSubclass() const override;
73  fpreal getStateDistanceSubclass() const override;
74 
76  const GU_DetailHandle &gdh,
77  const SIM_Time &time,
78  const SIM_Relationship &rel,
79  const SIM_ConAnchor &anchor1,
80  const SIM_ConAnchor &anchor2) const override;
81  void buildConRelGuide(
82  const GU_DetailHandle &gdh,
83  const SIM_Options &options,
84  const UT_Vector3 &anchor_pos_1,
85  const UT_Vector3 &anchor_pos_2,
86  const UT_Quaternion &anchor_rot_1,
87  const UT_Quaternion &anchor_rot_2,
88  const ConRelData &c_data) const override;
89  virtual UT_Vector3 getForceSubclass(const UT_Vector3 &objAnchorPos,
90  const UT_Vector3 &objAnchorVel,
91  const UT_Vector3 &otherAnchorPos,
92  const UT_Vector3 &otherAnchorVel,
93  const UT_Matrix3 &dofFilter);
94  virtual UT_Vector3 getTorqueSubclass(const UT_Quaternion &objOrient,
95  const UT_Vector3 &objAngVel,
96  const UT_Quaternion &anchorOrient,
97  const UT_Vector3 &anchorAngVel);
98  virtual UT_Matrix3 getJacobianPosSubclass(const UT_Vector3 &objAnchorPos,
99  const UT_Vector3 &objAnchorVel,
100  const UT_Vector3 &otherAnchorPos,
101  const UT_Vector3 &otherAnchorVel,
102  const UT_Matrix3 &dofFilter) const;
103  virtual UT_Matrix3 getJacobianVelSubclass(const UT_Vector3 &objAnchorPos,
104  const UT_Vector3 &objAnchorVel,
105  const UT_Vector3 &otherAnchorPos,
106  const UT_Vector3 &otherAnchorVel,
107  const UT_Matrix3 &dofFilter) const;
108 
109  UT_Vector3 project(const UT_Vector3 &vec,
110  const UT_Matrix3 &dofFilter) const;
111 
112 private:
113  static const SIM_DopDescription *getConRelSoftAttachDopDescription();
114 
115  fpreal myStateForce;
116  fpreal myStateDistance;
117 
120  SIM_ConRel,
121  "Soft Attach Constraint Relationship",
122  getConRelSoftAttachDopDescription());
123 };
124 
125 #endif
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
virtual void setStateForceSubclass(fpreal force)
GT_API const UT_StringHolder time
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
virtual fpreal getStateDistanceSubclass() const
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:63
UT_Vector2T< T > project(const UT_Vector2T< T > &u, const UT_Vector2T< T > &v)
The orthogonal projection of a vector u onto a vector v.
Definition: UT_Vector2.h:700
virtual void setStateDistanceSubclass(fpreal distance)
SIM_API const UT_StringHolder force
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SIM_API
Definition: SIM_API.h:12
virtual void buildConRelGuide(const GU_DetailHandle &gdh, const SIM_Options &options, const UT_Vector3 &anchor_pos_1, const UT_Vector3 &anchor_pos_2, const UT_Quaternion &anchor_rot_1, const UT_Quaternion &anchor_rot_2, const ConRelData &c_data) const
virtual fpreal getStateForceSubclass() const
SIM_API const UT_StringHolder distance
#define SIM_NAME_STIFFNESS
Definition: SIM_Names.h:195
virtual void buildConRelGuideGeometrySubclass(const GU_DetailHandle &gdh, const SIM_Time &time, const SIM_Relationship &rel, const SIM_ConAnchor &anchor1, const SIM_ConAnchor &anchor2) const
#define SIM_NAME_DAMPING
Definition: SIM_Names.h:97