forked from bepu/bepuphysics1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SingleBoneAngularMotor.cs
32 lines (26 loc) · 1.26 KB
/
SingleBoneAngularMotor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using BEPUutilities;
namespace BEPUik
{
public class SingleBoneAngularMotor : SingleBoneConstraint
{
/// <summary>
/// Gets or sets the target orientation to apply to the target bone.
/// </summary>
public Quaternion TargetOrientation;
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobian = new Matrix3x3();
angularJacobian = Matrix3x3.Identity;
//Error is in world space. It gets projected onto the jacobians later.
Quaternion errorQuaternion;
Quaternion.Conjugate(ref TargetBone.Orientation, out errorQuaternion);
Quaternion.Multiply(ref TargetOrientation, ref errorQuaternion, out errorQuaternion);
float angle;
Vector3 angularError;
Quaternion.GetAxisAngleFromQuaternion(ref errorQuaternion, out angularError, out angle);
Vector3.Multiply(ref angularError, angle, out angularError);
//This is equivalent to projecting the error onto the angular jacobian. The angular jacobian just happens to be the identity matrix!
Vector3.Multiply(ref angularError, errorCorrectionFactor, out velocityBias);
}
}
}