Skip to content

Commit

Permalink
fix(Utilities): use local space for velocity estimation samples
Browse files Browse the repository at this point in the history
The Velocity Estimator was using world space to determine the samples
for velocity and angular velocity, which would cause problems if the
Velocity Estimator was attached to a GameObject that's parent was
rotated.

It could be seen in the Unity SDK by simply rotating the CameraRig
around the Y axis and then the throwing mechanism would throw
things in the wrong direction.

The solution is to simply use local space for position and rotation
as then the actual object the Velocity Estimator is attached to
will be used for the relative position and rotation.
  • Loading branch information
thestonefox committed Aug 19, 2017
1 parent 9a959f0 commit 3e05056
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Assets/VRTK/Scripts/Utilities/VRTK_VelocityEstimator.cs
Expand Up @@ -137,8 +137,8 @@ protected virtual IEnumerator EstimateVelocity()
{
currentSampleCount = 0;

Vector3 previousPosition = transform.position;
Quaternion previousRotation = transform.rotation;
Vector3 previousPosition = transform.localPosition;
Quaternion previousRotation = transform.localRotation;
while (true)
{
yield return new WaitForEndOfFrame();
Expand All @@ -149,8 +149,8 @@ protected virtual IEnumerator EstimateVelocity()
int w = currentSampleCount % angularVelocitySamples.Length;
currentSampleCount++;

velocitySamples[v] = velocityFactor * (transform.position - previousPosition);
Quaternion deltaRotation = transform.rotation * Quaternion.Inverse(previousRotation);
velocitySamples[v] = velocityFactor * (transform.localPosition - previousPosition);
Quaternion deltaRotation = transform.localRotation * Quaternion.Inverse(previousRotation);

float theta = 2.0f * Mathf.Acos(Mathf.Clamp(deltaRotation.w, -1.0f, 1.0f));
if (theta > Mathf.PI)
Expand All @@ -166,8 +166,8 @@ protected virtual IEnumerator EstimateVelocity()

angularVelocitySamples[w] = angularVelocity;

previousPosition = transform.position;
previousRotation = transform.rotation;
previousPosition = transform.localPosition;
previousRotation = transform.localRotation;
}
}
}
Expand Down

0 comments on commit 3e05056

Please sign in to comment.