Fixed execution order issue, removed unused filter and added support for external IK targets.

This commit is contained in:
Emiliana 2021-02-23 23:04:52 +01:00
parent 07fd56fef8
commit 7d923f8176
4 changed files with 51 additions and 107 deletions

View file

@ -7,6 +7,8 @@ namespace OpenSee {
public class OpenSeeKinematicInterpolation : MonoBehaviour
{
public float interpolateClamp = 1f;
private Vector3 lastPos;
private Vector3 lastPosV;
private double lastT;
@ -29,15 +31,19 @@ public class OpenSeeKinematicInterpolation : MonoBehaviour
private double updateT;
private double interpolateT;
private int ready = 0;
public void UpdateKI(double newT, Vector3 newPos, Quaternion newRot) {
Interpolate();
if (newT - currentT > 3f)
ready = 0;
currentPos = transform.localPosition;
currentRot = OpenSeeIKTarget.PrettyEuler(currentRot, transform.localRotation.eulerAngles);
float dTNow = (float)(interpolateT - updateT);
if (interpolateT - updateT > 0) {
currentPosV = (currentPos - lastPos) / dTNow;
currentRotV = (currentRot - lastRot) / dTNow;
if (interpolateT - updateT > 0 || ready < 1) {
currentPosV = (currentPos - lastPos) / dT;
currentRotV = (currentRot - lastRot) / dT;
} else {
currentPosV = Vector3.zero;
currentRotV = Vector3.zero;
@ -64,6 +70,8 @@ public class OpenSeeKinematicInterpolation : MonoBehaviour
coeffRotB = ((6f*(currentRotV * dT + dT * lastRotV - 2f * currentRot + 2f * lastRot)) / dTPow3)/6f;
updateT = Time.time;
if (ready <= 2)
ready++;
}
float InterpolateValue(float dTNow, float dTNowPow2, float dTNowPow3, float a, float b, float x1, float x2, float v1, float v2) {
@ -72,12 +80,12 @@ public class OpenSeeKinematicInterpolation : MonoBehaviour
void Interpolate() {
interpolateT = Time.time;
if (interpolateT == updateT)
if (interpolateT == updateT || ready <= 2)
return;
float dTNow = (float)(interpolateT - updateT);
if (dTNow >= dT) {
transform.localPosition = Vector3.LerpUnclamped(lastPos, currentPos, Mathf.Min((float)(dTNow / dT), 2f));
transform.localEulerAngles = Vector3.LerpUnclamped(lastRot, currentRot, Mathf.Min((float)(dTNow / dT), 2f));
transform.localPosition = Vector3.LerpUnclamped(lastPos, currentPos, Mathf.Min((float)(dTNow / dT), interpolateClamp));
transform.localEulerAngles = Vector3.LerpUnclamped(lastRot, currentRot, Mathf.Min((float)(dTNow / dT), interpolateClamp));
} else {
float dTNowPow2 = Mathf.Pow(dTNow, 2);
float dTNowPow3 = Mathf.Pow(dTNow, 3);
@ -92,7 +100,7 @@ public class OpenSeeKinematicInterpolation : MonoBehaviour
}
}
public void LateUpdate() {
public void Update() {
Interpolate();
}
}