HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~SIM_ConRelSoftAttach();
69 
70  virtual void setStateForceSubclass(fpreal force);
71  virtual fpreal getStateForceSubclass() const;
73  virtual fpreal getStateDistanceSubclass() const;
74 
75  virtual void buildConRelGuide(
76  const GU_DetailHandle &gdh,
77  const SIM_Options &options,
78  const UT_Vector3 &anchor_pos_1,
79  const UT_Vector3 &anchor_pos_2,
80  const UT_Quaternion &anchor_rot_1,
81  const UT_Quaternion &anchor_rot_2,
82  const ConRelData &c_data) const;
83  virtual UT_Vector3 getForceSubclass(const UT_Vector3 &objAnchorPos,
84  const UT_Vector3 &objAnchorVel,
85  const UT_Vector3 &otherAnchorPos,
86  const UT_Vector3 &otherAnchorVel,
87  const UT_Matrix3 &dofFilter);
88  virtual UT_Vector3 getTorqueSubclass(const UT_Quaternion &objOrient,
89  const UT_Vector3 &objAngVel,
90  const UT_Quaternion &anchorOrient,
91  const UT_Vector3 &anchorAngVel);
92  virtual UT_Matrix3 getJacobianPosSubclass(const UT_Vector3 &objAnchorPos,
93  const UT_Vector3 &objAnchorVel,
94  const UT_Vector3 &otherAnchorPos,
95  const UT_Vector3 &otherAnchorVel,
96  const UT_Matrix3 &dofFilter) const;
97  virtual UT_Matrix3 getJacobianVelSubclass(const UT_Vector3 &objAnchorPos,
98  const UT_Vector3 &objAnchorVel,
99  const UT_Vector3 &otherAnchorPos,
100  const UT_Vector3 &otherAnchorVel,
101  const UT_Matrix3 &dofFilter) const;
102 
103  UT_Vector3 project(const UT_Vector3 &vec,
104  const UT_Matrix3 &dofFilter) const;
105 
106 private:
107  static const SIM_DopDescription *getConRelSoftAttachDopDescription();
108 
109  fpreal myStateForce;
110  fpreal myStateDistance;
111 
114  SIM_ConRel,
115  "Soft Attach Constraint Relationship",
116  getConRelSoftAttachDopDescription());
117 };
118 
119 #endif
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
virtual void setStateForceSubclass(fpreal force)
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
virtual fpreal getStateDistanceSubclass() const
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
virtual void setStateDistanceSubclass(fpreal distance)
double fpreal
Definition: SYS_Types.h:269
#define SIM_API
Definition: SIM_API.h:10
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
#define SIM_NAME_STIFFNESS
Definition: SIM_Names.h:194
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER Vec project(const Vec &s, const Vec &t)
Definition: ImathVecAlgo.h:96
#define SIM_NAME_DAMPING
Definition: SIM_Names.h:96