Browse Source

Exposing weighted nlerp

TheComet 8 years ago
parent
commit
073f7ef571
3 changed files with 25 additions and 2 deletions
  1. 0 2
      Source/Urho3D/IK/IK.h
  2. 21 0
      Source/Urho3D/IK/IKEffector.cpp
  3. 4 0
      Source/Urho3D/IK/IKEffector.h

+ 0 - 2
Source/Urho3D/IK/IK.h

@@ -25,8 +25,6 @@
  *  - Actually implement tolerance.
  *  - Target angle in addition to target position -> use weighted angles
  *    approach
- *  - Nlerp weighted effectors using total chain length + root node as axis
- *    of rotation (so arm moves in a circle, for example)
  *  - Fix rotation issue with shared sub-base nodes -> rotations need to be
  *    averaged.
  *  - Add support for manually updating initial pose.

+ 21 - 0
Source/Urho3D/IK/IKEffector.cpp

@@ -43,6 +43,7 @@ IKEffector::IKEffector(Context* context) :
     ikEffector_(NULL),
     chainLength_(0),
     weight_(1.0f),
+    weightedNlerp_(false),
     inheritParentRotation_(false),
     weightedChildrotations_(false)
 {
@@ -63,6 +64,7 @@ void IKEffector::RegisterObject(Context* context)
     URHO3D_ACCESSOR_ATTRIBUTE("Target Position", GetTargetPosition, SetTargetPosition, Vector3, Vector3::ZERO, AM_DEFAULT);
     URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Target Rotation", GetTargetRotationEuler, SetTargetRotationEuler, Vector3, Vector3::ZERO, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Weight", GetWeight, SetWeight, float, 1.0, AM_DEFAULT);
+    URHO3D_ACCESSOR_ATTRIBUTE("Nlerp Weight", DoWeightedNlerp, SetWeightedNlerp, bool, false, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Inherit Parent Rotation", DoInheritParentRotation, SetInheritParentRotation, bool, false, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Weighted Child Rotations", DoWeightedChildRotations, SetWeightedChildRotations, bool, false, AM_DEFAULT);
 }
@@ -172,6 +174,24 @@ void IKEffector::SetWeight(float weight)
         ikEffector_->weight = weight_;
 }
 
+// ----------------------------------------------------------------------------
+bool IKEffector::DoWeightedNlerp() const
+{
+    return weightedNlerp_;
+}
+
+// ----------------------------------------------------------------------------
+void IKEffector::SetWeightedNlerp(bool enable)
+{
+    weightedNlerp_ = enable;
+    if (ikEffector_ != NULL)
+    {
+        ikEffector_->flags &= ~EFFECTOR_WEIGHT_NLERP;
+        if (enable)
+            ikEffector_->flags |= EFFECTOR_WEIGHT_NLERP;
+    }
+}
+
 // ----------------------------------------------------------------------------
 bool IKEffector::DoInheritParentRotation() const
 {
@@ -273,6 +293,7 @@ void IKEffector::SetEffector(ik_effector_t* effector)
         effector->target_rotation = QuatUrho2IK(targetRotation_);
         effector->weight = weight_;
         effector->chain_length = chainLength_;
+        SetWeightedNlerp(weightedNlerp_);
     }
 }
 

+ 4 - 0
Source/Urho3D/IK/IKEffector.h

@@ -95,6 +95,9 @@ public:
     float GetWeight() const;
     void SetWeight(float weight);
 
+    bool DoWeightedNlerp() const;
+    void SetWeightedNlerp(bool enable);
+
     bool DoInheritParentRotation() const;
     void SetInheritParentRotation(bool enable);
 
@@ -118,6 +121,7 @@ private:
     Quaternion targetRotation_;
     unsigned chainLength_;
     float weight_;
+    bool weightedNlerp_;
     bool inheritParentRotation_;
     bool weightedChildrotations_;
 };