AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GrabbableMultiJoint.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
7 {
9  {
10  [SerializeField]
11  private float blendSpeed = 10f;
12 
13  protected override void OnGrabStay()
14  {
15  base.OnGrabStay();
16  Vector3 averagePosition = transform.position;
17  Quaternion averageRotation = transform.rotation;
18  int numGrabbers = activeGrabbers.Count;
19  float weightPerGrabber = 1f / numGrabbers;
20 
21  for (var i = 0; i < activeGrabbers.Count; i++)
22  {
23  var activeGrabber = (Grabber)activeGrabbers[i];
24  averagePosition = Vector3.Lerp(averagePosition, activeGrabber.GrabHandle.position, weightPerGrabber);
25  averageRotation = Quaternion.Lerp(averageRotation, activeGrabber.GrabHandle.rotation, weightPerGrabber);
26  }
27 
28  transform.position = Vector3.Lerp(transform.position, averagePosition, Time.deltaTime * blendSpeed);
29  transform.rotation = Quaternion.Lerp(transform.rotation, averageRotation, Time.deltaTime * blendSpeed);
30  }
31 
32  //the next three functions provide basic behaviour. Extend from this base script in order to provide more specific functionality.
33 
34  protected override void AttachToGrabber(BaseGrabber grabber)
35  {
36  GetComponent<Rigidbody>().isKinematic = true;
37  if (!activeGrabbers.Contains(grabber))
38  {
39  activeGrabbers.Add(grabber);
40  }
41  }
42 
43  protected override void DetachFromGrabber(BaseGrabber grabber)
44  {
45  Debug.Log("Detaching form grabber");
46  }
47 
48  protected override void Update()
49  {
50  base.Update();
51  if (GrabState == GrabStateEnum.Inactive && activeGrabbers.Count == 0)
52  {
53  GetComponent<Rigidbody>().isKinematic = false;
54  GetComponent<Rigidbody>().useGravity = true;
55  }
56  }
57  }
58 }
Intended usage: scripts that inherit from this can be attached to the controller, or any object with ...
Definition: BaseGrabber.cs:18
//Intended Usage// Attach a "grabbable_x" script (a script that inherits from this) to any object tha...
override void OnGrabStay()
Called every frame while StayGrab is active
Extends its behaviour from BaseGrabber. This is non-abstract script that&#39;s actually attached to the g...
Definition: Grabber.cs:16