Skip to content

Commit f0fce1d

Browse files
committed
Cache rotationOffset
1 parent ee4ab21 commit f0fce1d

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Assets/WebXR/Scripts/WebXRController.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,22 @@ private void OnHandUpdate(WebXRHandData handData)
183183
transform.localPosition = handData.joints[0].position;
184184
transform.localRotation = handData.joints[0].rotation;
185185

186+
Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);
187+
186188
for(int i=0; i<=WebXRHandData.LITTLE_PHALANX_TIP; i++)
187189
{
188190
if (handData.joints[i].enabled)
189191
{
190192
if (handJoints.ContainsKey(i))
191193
{
192-
handJoints[i].localPosition = GetJointLocalPosition(handData.joints[i].position, handData.joints[0].position, handData.joints[0].rotation);
193-
handJoints[i].localRotation = GetJointLocalRotation(handData.joints[i].rotation, handData.joints[0].rotation);
194+
handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
195+
handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
194196
}
195197
else
196198
{
197199
var clone = Instantiate(handJointPrefab,
198-
GetJointLocalPosition(handData.joints[i].position, handData.joints[0].position, handData.joints[0].rotation),
199-
GetJointLocalRotation(handData.joints[i].rotation, handData.joints[0].rotation),
200+
rotationOffset * (handData.joints[i].position - handData.joints[0].position),
201+
rotationOffset * handData.joints[i].rotation,
200202
transform);
201203
if (handData.joints[i].radius > 0f)
202204
{
@@ -213,16 +215,6 @@ private void OnHandUpdate(WebXRHandData handData)
213215
}
214216
}
215217

216-
private Vector3 GetJointLocalPosition(Vector3 position, Vector3 originPosition, Quaternion originRotation)
217-
{
218-
return Quaternion.Inverse(originRotation) * (position-originPosition);
219-
}
220-
221-
private Quaternion GetJointLocalRotation(Quaternion rotation, Quaternion originRotation)
222-
{
223-
return Quaternion.Inverse(originRotation) * rotation;
224-
}
225-
226218
private WebXRControllerHand handFromString(string handValue)
227219
{
228220
WebXRControllerHand handParsed = WebXRControllerHand.NONE;

0 commit comments

Comments
 (0)