Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

624 lines
25 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Declaration of the constraint operator classes. The constraint
  4. // operators control the position and / or orientation of a specified slave dag
  5. // node based on the position and orientation of a set of weighted target dag
  6. // nodes. The relationship between the target dag node and the slave is
  7. // determined by the type of the constraint. The Operate() function of each
  8. // constraint class is responsible for enforcing its specific relationship.
  9. //
  10. //=============================================================================
  11. #ifndef DMERIGCONSTRAINTOPERATORS_H
  12. #define DMERIGCONSTRAINTOPERATORS_H
  13. #ifdef _WIN32
  14. #pragma once
  15. #endif
  16. #include "movieobjects/dmedag.h"
  17. #include "movieobjects/dmeoperator.h"
  18. // Forward declarations
  19. class CDmAttribute;
  20. class CDmeChannel;
  21. class CDmeFilmClip;
  22. class CDmeRigBaseConstraintOperator;
  23. //-----------------------------------------------------------------------------
  24. // Different rig operator modes (directions)
  25. //-----------------------------------------------------------------------------
  26. enum RigOperatorMode_t
  27. {
  28. RM_FORWARD = 0, // Data flows from handles to drive slaves
  29. RM_REVERSE, // Slave transforms drive handle positions
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Constraint attribute attachment type, specifies which channels the
  33. // constraint will apply to.
  34. //-----------------------------------------------------------------------------
  35. enum EAddType
  36. {
  37. AA_TYPE_UNKNOWN = 0,
  38. AA_TYPE_POSITION = (1<<0),
  39. AA_TYPE_ORIENTATION = (1<<1),
  40. AA_TYPE_ALL = AA_TYPE_POSITION | AA_TYPE_ORIENTATION,
  41. };
  42. //-----------------------------------------------------------------------------
  43. // General constraint types
  44. //-----------------------------------------------------------------------------
  45. enum EConstraintType
  46. {
  47. CT_UNKNOWN = 0,
  48. CT_POINT, // Point constraint, slave position matches target position
  49. CT_ORIENT, // Orient constraint, slave orientation matches target orientation
  50. CT_AIM, // Aim constraint, slave orientation is adjusted to look point toward target position
  51. CT_IK, // Inverse kinematics constraint, position and orientation are adjusted to reach a target
  52. CT_PARENT, // Parent constraint, slave position and orientation are updated to behave as children of the target
  53. CT_ROTATION, // Rotation constraint, slave orientation is set to the orientation generated from a set of rotations
  54. CT_TWIST, // Twist constraint, takes a percentage of the rotation around the axis between a child & parent bone
  55. NUM_CONSTRAINT_TYPES,
  56. };
  57. //-----------------------------------------------------------------------------
  58. // CDmeConstraintTarget: Specifies a single target of a constraint and the
  59. // weight of that target in the final result, as well as a position and
  60. // orientation.
  61. //-----------------------------------------------------------------------------
  62. class CDmeConstraintTarget : public CDmElement
  63. {
  64. DEFINE_ELEMENT( CDmeConstraintTarget, CDmElement );
  65. friend class CDmeRigBaseConstraintOperator;
  66. public:
  67. // Clear the position and rotation offset
  68. void ClearOffset();
  69. // Find the channel driving the weight value of the constraint
  70. CDmeChannel *FindWeightChannel() const;
  71. // Get the constraint to which the target belongs.
  72. CDmeRigBaseConstraintOperator *GetConstraint();
  73. // Find the control attached to constraint's weight
  74. CDmElement *FindWeightControl() const;
  75. // Get the dag node that is the source of the target
  76. CDmeDag *GetDag() { return m_Handle; }
  77. // Get the weight value for the target
  78. float GetWeight() { return m_flWeight; }
  79. // Get the position offset of the target
  80. const Vector &GetPositionOfffset() { return m_vecOffset; }
  81. // Get the orientation offset of the target
  82. const Quaternion &GetOrientationOffset() { return m_qOffset; }
  83. // Get the weight attribute of the target
  84. CDmAttribute *GetWeightAttribute() { return m_flWeight.GetAttribute(); }
  85. private:
  86. CDmaElement< CDmeDag > m_Handle;
  87. CDmaVar< float > m_flWeight;
  88. CDmaVar< Vector > m_vecOffset;
  89. CDmaVar< Quaternion > m_qOffset;
  90. };
  91. //-----------------------------------------------------------------------------
  92. // CDmeConstraintSlave: A dag node which is being controlled by a constraint,
  93. // also stores the original position and orientation of the dag which will be
  94. // used if no weight is active.
  95. //-----------------------------------------------------------------------------
  96. class CDmeConstraintSlave : public CDmElement
  97. {
  98. DEFINE_ELEMENT( CDmeConstraintSlave, CDmElement );
  99. friend class CDmeRigBaseConstraintOperator;
  100. public:
  101. // Get the transform of the dag assigned to the slave
  102. CDmeTransform *GetTransform() { return m_Dag.GetElement() ? m_Dag->GetTransform() : NULL; }
  103. // Set the dag node targeted by the slave
  104. void SetDag( CDmeDag *pDag ) { m_Dag = pDag; }
  105. // Get the dag node targeted by the slave.
  106. CDmeDag *GetDag() const { return m_Dag; }
  107. // Set the local space base position of the slave
  108. void SetBasePosition( const Vector &positon ) { m_BasePosition = positon; }
  109. // Get the local space base position of the slave
  110. const Vector &GetBasePosition() const { return m_BasePosition; }
  111. // Set the local space base orientation of the slave
  112. void SetBaseOrientation( const Quaternion &orientation ) { m_BaseOrientation = orientation; }
  113. // Get the local space base orientation of the slave
  114. const Quaternion &GetBaseOrientation() const { return m_BaseOrientation; }
  115. // Get the attribute for the base position
  116. const CDmAttribute *GetBasePositionAttribute() const { return m_BasePosition.GetAttribute(); }
  117. // Get the attribute for the base orientation
  118. const CDmAttribute *GetBaseOrientationAttribute() const { return m_BaseOrientation.GetAttribute(); }
  119. // Get the constraint to which the slave belongs.
  120. CDmeRigBaseConstraintOperator *GetConstraint() const;
  121. // Compute the base world space matrix
  122. void GetBaseWorldTransform( matrix3x4_t &worldTransform ) const;
  123. // Compute the base position and orientation in world space
  124. void ComputeBaseWorldValues( Vector &wsPosition, Quaternion &wsOrientation ) const;
  125. private:
  126. CDmaElement< CDmeDag > m_Dag; // Dag node being controlled by the constraint
  127. CDmaVar< Vector > m_BasePosition; // Position of the slave when no constraint target is active
  128. CDmaVar< Quaternion> m_BaseOrientation; // Orientation of the slave when no constraint target is active
  129. };
  130. //-----------------------------------------------------------------------------
  131. // CDmeRigBaseConstraintOperator: Base class from which all constraints are
  132. // derived.
  133. //-----------------------------------------------------------------------------
  134. class CDmeRigBaseConstraintOperator : public CDmeOperator
  135. {
  136. DEFINE_ELEMENT( CDmeRigBaseConstraintOperator, CDmeOperator );
  137. public:
  138. // DERIVED CLASSES SHOULD OVERRIDE
  139. virtual EConstraintType GetConstraintType() const { Error( "Derived must implement" ); return CT_UNKNOWN; }
  140. virtual EAddType GetInputAttributeType() const { Error( "Derived must implement" ); return AA_TYPE_UNKNOWN; };
  141. virtual EAddType GetOutputAttributeType() const { Error( "Derived must implement" ); return AA_TYPE_UNKNOWN; };
  142. virtual void Operate() { Error( "Derived must implement" ); };
  143. // Determine if data has changed and the operator needs to be updated
  144. // FIXME: Each op type should check extra fields
  145. virtual bool IsDirty() const { return true; }
  146. // Perform any additional work which needs to be done after handles have been added
  147. virtual void PostHandlesAdded( bool bPreserveOffset ) {}
  148. // Determine if the the constraint has slave with the specified name
  149. virtual bool IsSlaveObject( char const *pchName ) const;
  150. // Get the attributes that the constraint reads data from, Inputs are CDmeDags (handles usually)
  151. virtual void GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs );
  152. // Get the attributes to which the attribute writes, Outputs are CDmeDags (bones or other CDmeRigHandles usually)
  153. virtual void GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs );
  154. // Disconnect the channels driving the slave dag nodes from the dag transforms and connect them to the constraint
  155. virtual void DisconnectTransformChannels();
  156. // Reconnect the base channels of each slave directly to the dag
  157. virtual void ReconnectTransformChannels();
  158. // Find all of the operators the evaluation of the constraint operator is dependent on
  159. virtual void GatherInputOperators( CUtlVector< CDmeOperator * > &operatorList );
  160. // Get a pointer to the dag node the constraint is controlling
  161. virtual const CDmeDag *GetSlave() const;
  162. // Add target handles to the the constraint with the specified weights
  163. void AddHandles( int nCount, CDmeDag *const pRigHandles[], const float *pflWeights, bool bPreserveOffset, CUtlVector< CDmeConstraintTarget* > *pTargetList );
  164. // Remove all target handles from the constraint
  165. void ClearHandles();
  166. // Set the dag node which the constraint is controlling
  167. void SetSlave( CDmeDag *pSlave );
  168. // Set the operating mode of the constraint
  169. void SetMode( RigOperatorMode_t mode );
  170. // Get the list of target handles used by the constraint
  171. const CDmaElementArray< CDmeConstraintTarget > &GetTargets() const { return m_Targets; }
  172. // Get the constraint slave
  173. const CDmeConstraintSlave* GetConstraintSlave() const { return m_Slave.GetElement(); }
  174. // Find the constraint target for the specified dag node
  175. CDmeConstraintTarget *FindConstraintTargetForDag( CDmeDag* pDag ) const;
  176. // Find all of the constraints that target the specified dag node
  177. static void FindDagConstraints( const CDmeDag *pDagNode, CUtlVector< CDmeRigBaseConstraintOperator* > &constraintList );
  178. // Find the constraint on the dag of the specified type
  179. static CDmeRigBaseConstraintOperator *FindDagConstraint( CDmeDag *pDag, EConstraintType constraintType );
  180. // Destroy the specified constraint and remove it from the animation set.
  181. static void DestroyConstraint( CDmeRigBaseConstraintOperator *pConstraint );
  182. // Remove all of the constraints from the specified dag node.
  183. static void RemoveConstraintsFromDag( CDmeDag *pDag );
  184. // Get the string name associated with the specified constraint type.
  185. static char const *ConstraintTypeName( EConstraintType eType );
  186. protected:
  187. // Add the specified type of attributes from the provided transform
  188. static void AddAttribute( CUtlVector< CDmAttribute * > &attrs, enum EAddType type, class CDmeTransform *pTxForm );
  189. // Add the position and orientation attributes the entire ancestry of the dag node.
  190. static void AddAncestorAttributes( CUtlVector< CDmAttribute * > &attrs, CDmeDag *pDag );
  191. // Compute the offsets of the specified target based on the relative transforms of the target to the slave
  192. virtual void ComputeOffset( Vector &vOffset, Quaternion &qOffset, CDmeConstraintTarget *pTarget, bool bPreserveOffset );
  193. // Compute the aggregate target position from the weighted target list and return the total weight
  194. float ComputeTargetPosition( Vector &wsTargetPosition );
  195. // Compute the aggregate target orientation from the weighted target list and return the total weight
  196. float ComputeTargetOrientation( Quaternion &wsTargetOrientation );
  197. // Disconnect the channels driving the specified slave from the dag and connect them to the constraint
  198. void DisconnectSlaveChannels( CDmeConstraintSlave *pSlave, int attributeFlags );
  199. // Reconnect the transform channels associated with the specified slave directly to the dag
  200. void ReconnectSlaveChannels( CDmeConstraintSlave *pSlave, int attributeFlags );
  201. protected:
  202. CDmaElementArray< CDmeConstraintTarget > m_Targets; // Set of target dag nodes used to calculate position and orientation
  203. CDmaElement< CDmeConstraintSlave > m_Slave; // Dag node who's position and/or orientation are controlled by the constraint
  204. CDmaVar< int > m_mode; // Operating mode of the constraint, determines data flow direction
  205. };
  206. //-----------------------------------------------------------------------------
  207. // CDmeRigPointConstraintOperator
  208. //-----------------------------------------------------------------------------
  209. class CDmeRigPointConstraintOperator : public CDmeRigBaseConstraintOperator
  210. {
  211. public:
  212. DEFINE_ELEMENT( CDmeRigPointConstraintOperator, CDmeRigBaseConstraintOperator );
  213. public:
  214. virtual EConstraintType GetConstraintType() const { return CT_POINT; }
  215. virtual void Operate();
  216. virtual EAddType GetInputAttributeType() const { return (EAddType)( AA_TYPE_POSITION | AA_TYPE_ORIENTATION ); } // Requires position and orientation, orientation is needed for offset
  217. virtual EAddType GetOutputAttributeType() const { return AA_TYPE_POSITION; } // Only writes position of destination bone
  218. };
  219. //-----------------------------------------------------------------------------
  220. // CDmeRigOrientConstraintOperator
  221. //-----------------------------------------------------------------------------
  222. class CDmeRigOrientConstraintOperator : public CDmeRigBaseConstraintOperator
  223. {
  224. public:
  225. DEFINE_ELEMENT( CDmeRigOrientConstraintOperator, CDmeRigBaseConstraintOperator );
  226. public:
  227. virtual EConstraintType GetConstraintType() const { return CT_ORIENT; }
  228. virtual void Operate();
  229. virtual EAddType GetInputAttributeType() const { return AA_TYPE_ORIENTATION; } // Uses just orientations of handles
  230. virtual EAddType GetOutputAttributeType() const { return AA_TYPE_ORIENTATION; } // Only writes orientation of destination bone
  231. };
  232. //-----------------------------------------------------------------------------
  233. // CDmeRigAimConstraintOperator
  234. //-----------------------------------------------------------------------------
  235. class CDmeRigAimConstraintOperator : public CDmeRigBaseConstraintOperator
  236. {
  237. public:
  238. DEFINE_ELEMENT( CDmeRigAimConstraintOperator, CDmeRigBaseConstraintOperator );
  239. public:
  240. virtual EConstraintType GetConstraintType() const { return CT_AIM; }
  241. virtual void Operate();
  242. virtual void GetInputAttributes( CUtlVector< CDmAttribute * > &attrs );
  243. virtual EAddType GetInputAttributeType() const { return AA_TYPE_POSITION; } // Uses just positions of handles
  244. virtual EAddType GetOutputAttributeType() const { return AA_TYPE_ORIENTATION; } // Only writes angle of destination bone
  245. virtual void PostHandlesAdded( bool bPreserveOffset );
  246. // Set the world up vector in the space of the provided dag node and update the offset
  247. void SetUpVector( const Vector &upVector, bool bPreserveOffset, const CDmeDag *pUpSpaceTarget );
  248. // Set the type of up vector, from CConstraintBones::AimConstraintUpType_t
  249. void SetUpType( int nUpType );
  250. private:
  251. // Calculate the orientation needed to make a transform with the specified forward vector
  252. void AimAt( const Vector &vecForward, const Vector &referenceUp, Quaternion &q );
  253. // Re-calculate the offset value based on the target location and the current orientation of the slave
  254. void UpdateOffset( bool bPreserveOffset );
  255. // Calculate the orientation to apply to the slave to make it look at the target position.
  256. float CalculateOrientation( Quaternion &targetOrientation );
  257. CDmaVar< Quaternion > m_AimOffset;
  258. CDmaVar< Vector > m_UpVector;
  259. CDmaElement< const CDmeDag > m_UpSpaceTarget;
  260. CDmaVar< int > m_UpType; // One of CConstraintBones::AimConstraintUpType_t
  261. };
  262. //-----------------------------------------------------------------------------
  263. // CDmeRigRotationConstraintOperator -- An operator for controlling the
  264. // orientation of a dag node using a series axis angle rotations.
  265. //-----------------------------------------------------------------------------
  266. class CDmeRigRotationConstraintOperator : public CDmeRigBaseConstraintOperator
  267. {
  268. public:
  269. DEFINE_ELEMENT( CDmeRigRotationConstraintOperator, CDmeRigBaseConstraintOperator );
  270. public:
  271. virtual EConstraintType GetConstraintType() const { return CT_ROTATION; }
  272. virtual EAddType GetInputAttributeType() const { return AA_TYPE_UNKNOWN; } // Does not use target input values
  273. virtual EAddType GetOutputAttributeType() const { return AA_TYPE_ORIENTATION; } // Only writes orientation of destination dag
  274. // Run the operator, this calculates the quaternion orientation by concatenating the axis angle rotations.
  275. virtual void Operate();
  276. // Get the list of input attributes the operation is dependent on this includes all of the axis values and rotations
  277. virtual void GetInputAttributes( CUtlVector< CDmAttribute * > &attrs );
  278. // Add a rotation axis
  279. int AddAxis( const Vector &axis );
  280. // Set the axis around which the rotation is to occur
  281. void SetAxis( const Vector &axis, int index);
  282. // Set current rotation value
  283. void SetRotation( float rotation, int index );
  284. private:
  285. CDmaArray< float > m_Rotations; // "rotation" : Rotation around the specified axis in degrees
  286. CDmaArray< Vector > m_Axies; // "axies" : Axis about which the rotation will occur
  287. };
  288. //-----------------------------------------------------------------------------
  289. // CDmeRigParentConstraintOperator
  290. //-----------------------------------------------------------------------------
  291. class CDmeRigParentConstraintOperator : public CDmeRigBaseConstraintOperator
  292. {
  293. public:
  294. DEFINE_ELEMENT( CDmeRigParentConstraintOperator, CDmeRigBaseConstraintOperator );
  295. public:
  296. virtual EConstraintType GetConstraintType() const { return CT_PARENT; }
  297. virtual void Operate();
  298. virtual EAddType GetInputAttributeType() const { return (EAddType)( AA_TYPE_POSITION | AA_TYPE_ORIENTATION); } // Uses both position and orientations of handles
  299. virtual EAddType GetOutputAttributeType() const { return (EAddType)( AA_TYPE_POSITION | AA_TYPE_ORIENTATION); } // Writes full transform of destination object
  300. private:
  301. // Compute the aggregate target position and orientation from the weighted target list and return the total weight
  302. float ComputeTargetPositionOrientation( Vector &wsTargetPos, Quaternion &wsTargetOrientation );
  303. // Compute the offsets of the specified target based on the relative transforms of the target to the slave
  304. virtual void ComputeOffset( Vector &vOffset, Quaternion &qOffset, CDmeConstraintTarget *pTarget, bool bPreserveOffset );
  305. };
  306. //-----------------------------------------------------------------------------
  307. // CDmeRigIKConstraintOperator
  308. //-----------------------------------------------------------------------------
  309. class CDmeRigIKConstraintOperator : public CDmeRigBaseConstraintOperator
  310. {
  311. public:
  312. DEFINE_ELEMENT( CDmeRigIKConstraintOperator, CDmeRigBaseConstraintOperator );
  313. public:
  314. virtual EConstraintType GetConstraintType() const { return CT_IK; }
  315. virtual void Operate();
  316. virtual EAddType GetInputAttributeType() const { return AA_TYPE_POSITION; } // Uses just positions of handles
  317. virtual EAddType GetOutputAttributeType() const { Assert( 0 ); return AA_TYPE_UNKNOWN; } // Only writes angle of destination bone
  318. // Overridden
  319. virtual void GetInputAttributes( CUtlVector< CDmAttribute * > &attrs );
  320. virtual void GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs );
  321. // Find all of the channels relevant to all of the target handles
  322. virtual void GatherInputOperators( CUtlVector< CDmeOperator * > &operatorList );
  323. // Disconnect the channels driving the slave dag nodes from the dag transforms and connect them to the constraint
  324. virtual void DisconnectTransformChannels();
  325. // Reconnect the base channels of each slave directly to the dag
  326. virtual void ReconnectTransformChannels();
  327. // Assign the joints that are to be controlled
  328. void SetJoints( CDmeDag *pStartJoint, CDmeDag *pMidJoint, CDmeDag *pEndJoint );
  329. // Set the pole vector which determines the direction the middle joint is to be moved within the plane
  330. void SetPoleVector( const Vector &worldPos );
  331. // Set the pole vector target, a dag node toward which the pole vector will point, overrides the standard pole vector.
  332. void SetPoleVectorTarget( CDmeDag *pPoleVectorTarget );
  333. // Validates that the start and end effector are set up and that there is only one intermediate bone between them forming a 2 bone ik chain.
  334. bool Setup( bool bPreserveOffset );
  335. // Get a pointer to the dag node the constraint is controlling
  336. virtual const CDmeDag *GetSlave() const;
  337. // Determine if the the constraint has slave with the specified name, for the ik constraint this is always false.
  338. virtual bool IsSlaveObject( char const *pchName ) const;
  339. private:
  340. // Compute the offsets of the specified target based on the relative transforms of the target to the slave
  341. virtual void ComputeOffset( Vector &vOffset, Quaternion &qOffset, CDmeConstraintTarget *pTarget, bool bPreserveOffset );
  342. // Calculate the orientation needed to make a transform with the specified forward vector
  343. void AimAt( const Vector &vecForward, const Vector &referenceUp, Quaternion &q );
  344. // Perform the 2 bone ik solve to get target orientation for the start and mid bones
  345. float CalculateOrientations( Quaternion &startBoneOrient, Quaternion &midBoneOrient, const Quaternion &startOffset, const Quaternion &midOffset );
  346. public:
  347. CDmaVar< Quaternion > m_StartOffsetRotation;
  348. CDmaVar< Quaternion > m_MidOffsetRotation;
  349. CDmaVar< Vector > m_PoleVector;
  350. CDmaElement< CDmeDag > m_PoleVectorTarget;
  351. CDmaElement< CDmeConstraintSlave > m_StartJoint;
  352. CDmaElement< CDmeConstraintSlave > m_MidJoint;
  353. CDmaElement< CDmeConstraintSlave > m_EndJoint;
  354. };
  355. //-----------------------------------------------------------------------------
  356. // CDmeRigTwistSlave
  357. //-----------------------------------------------------------------------------
  358. class CDmeRigTwistSlave : public CDmeConstraintSlave
  359. {
  360. DEFINE_ELEMENT( CDmeRigTwistSlave, CDmeConstraintSlave );
  361. public:
  362. // Sets the weight for this slave
  363. void SetWeight( float flWeight ) { m_flWeight = flWeight; }
  364. // Gets the weight for this slave
  365. float GetWeight() const { return m_flWeight; }
  366. protected:
  367. CDmaVar< float > m_flWeight;
  368. };
  369. //-----------------------------------------------------------------------------
  370. // CDmeRigTwistConstraintOperator
  371. //-----------------------------------------------------------------------------
  372. class CDmeRigTwistConstraintOperator : public CDmeRigBaseConstraintOperator
  373. {
  374. public:
  375. DEFINE_ELEMENT( CDmeRigTwistConstraintOperator, CDmeRigBaseConstraintOperator );
  376. public:
  377. // Returns the value of the m_bInverse attribute
  378. bool GetInverse() const { return m_bInverse; }
  379. // Sets the value of the m_bInverse attribute
  380. void SetInverse( bool bInverse ) { m_bInverse = bInverse; }
  381. // Returns the value of the m_vUpAxis attribute
  382. const Vector &GetUpAxis() const { return m_vUpAxis; }
  383. // Sets the value of the m_bInverse attribute
  384. void SetUpAxis( const Vector &vUpAxis ) { m_vUpAxis = vUpAxis; }
  385. // Get the Target dag that is the child joint
  386. bool SetTargets( CDmeDag *pDmeDagParent, CDmeDag *pDmeDagChild );
  387. // Get the Target dag that is the parent joint
  388. CDmeDag *GetParentTarget() const;
  389. // Get the Target dag that is the child joint
  390. CDmeDag *GetChildTarget() const;
  391. // Remove all slaves
  392. void ClearSlaves();
  393. // Add slave
  394. int AddSlave( CDmeDag *pDmeDagSlave, float flWeight );
  395. // Get slave count
  396. int SlaveCount() const { return m_eSlaves.Count(); }
  397. // Get slave count
  398. CDmeDag *GetSlaveDag( int i ) const;
  399. // Get slave count
  400. float GetSlaveWeight( int i ) const;
  401. // Get parent bind rotation
  402. const Quaternion &GetParentBindRotation() const { return m_qParentBindRotation; }
  403. // Get parent bind rotation
  404. void SetParentBindRotation( const Quaternion &qBindRotation );
  405. // Get child bind rotation
  406. const Quaternion &GetChildBindRotation() const { return m_qChildBindRotation; }
  407. // Get child bind rotation
  408. void SetChildBindRotation( const Quaternion &qBindRotation );
  409. // Get slave bind rotation
  410. const Quaternion &GetSlaveBindOrientation( int i ) const;
  411. // Get slave bind rotation
  412. void SetSlaveBindOrientation( const Quaternion &qBindRotation, int i );
  413. // From CDmeRigBaseConstraintOperator
  414. virtual EConstraintType GetConstraintType() const { return CT_TWIST; }
  415. virtual void Operate();
  416. virtual EAddType GetInputAttributeType() const { return (EAddType)( AA_TYPE_POSITION | AA_TYPE_ORIENTATION ); } // Requires position and orientation
  417. virtual EAddType GetOutputAttributeType() const { return AA_TYPE_ORIENTATION; } // Only writes orientation of destination bone
  418. // Overridden
  419. virtual void GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs );
  420. // Get a pointer to the dag node the constraint is controlling
  421. virtual const CDmeDag *GetSlave() const;
  422. // Determine if the the constraint has slave with the specified name, for the ik constraint this is always false.
  423. virtual bool IsSlaveObject( char const *pchName ) const;
  424. private:
  425. // Compute the offsets of the specified target based on the relative transforms of the target to the slave
  426. virtual void ComputeOffset( Vector &vOffset, Quaternion &qOffset, CDmeConstraintTarget *pTarget, bool bPreserveOffset );
  427. // Disconnect the channels driving the slave dag nodes from the dag transforms and connect them to the constraint
  428. virtual void DisconnectTransformChannels();
  429. // Reconnect the base channels of each slave directly to the dag
  430. virtual void ReconnectTransformChannels();
  431. CDmaVar< bool > m_bInverse;
  432. CDmaVar< Vector > m_vUpAxis;
  433. CDmaArray< float > m_flWeights;
  434. CDmaElementArray< CDmeRigTwistSlave > m_eSlaves;
  435. CDmaVar< Quaternion > m_qParentBindRotation;
  436. CDmaVar< Quaternion > m_qChildBindRotation;
  437. };
  438. #endif // DMERIGCONSTRAINTOPERATORS_H