VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_GrabNode.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEditor;
5 
6 /// <summary>
7 /// Namespace of the arc-vr-phys package
8 /// </summary>
9 namespace AVR.Phys {
10  /// <summary>
11  /// Represents a grabbable node on an AVR_Grabbable. Nodes have preset poses/constraints for the hand that are applied when grabbed.
12  /// </summary>
13  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_phys_1_1_a_v_r___grab_node.html")]
14  [ExecuteInEditMode]
15  public class AVR_GrabNode : AVR.Core.AVR_Behaviour
16  {
17  [Range(0f, 1f)]
18  public float index_pose = 0.0f;
19  [Range(0f, 1f)]
20  public float middle_pose = 0.0f;
21  [Range(0f, 1f)]
22  public float ring_pose = 0.0f;
23  [Range(0f, 1f)]
24  public float pinky_pose = 0.0f;
25  [Range(0f, 1f)]
26  public float thumb_pose = 0.0f;
27 
28  public float allowed_pitch = 0.0f;
29  public float allowed_yaw = 0.0f;
30  public float allowed_roll = 0.0f;
31 
32  [Range(-1f, 1f)]
33  public float pitch_test = 0.0f;
34  [Range(-1f, 1f)]
35  public float roll_test = 0.0f;
36  [Range(-1f, 1f)]
37  public float yaw_test = 0.0f;
38 
39  public float override_radius = 0.1f;
40 
42 
43  public void Awake() {
44  master = GetComponentInParent<AVR.Phys.AVR_Grabbable>();
45  }
46 
47  public Quaternion get_target_rotation(Quaternion hand_rot) {
48  // Hand rotation * local node rotation (relative to the master grabbable). This is the rotation the grabbed object should have
49  // if allowed pitch, yaw and roll were to be 0
50  Quaternion zeroAngRot = hand_rot * (Quaternion.Inverse(transform.rotation) * master.transform.rotation);
51 
52  // Rotation of the master grabbable. This is the rotation the object should have if allowd yaw pitch and roll were to be >360.
53  Quaternion fullAngRot = master.transform.rotation;
54 
55  // Rotation from zeroAng to fullAng
56  Quaternion fromToRot = fullAngRot * Quaternion.Inverse(zeroAngRot);
57 
58  // Clamping rotation by yaw pitch roll values
59  fromToRot = AVR.Core.Utils.Geom.ClampQuaternionRotation(fromToRot, new Vector3(allowed_pitch, allowed_yaw, allowed_roll));
60 
61  return zeroAngRot * fromToRot;
62  }
63  }
64 }
AVR.Phys.AVR_Grabbable master
Definition: AVR_GrabNode.cs:41
Represents a grabbable object.
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
Represents a grabbable node on an AVR_Grabbable. Nodes have preset poses/constraints for the hand tha...
Definition: AVR_GrabNode.cs:15
Quaternion get_target_rotation(Quaternion hand_rot)
Definition: AVR_GrabNode.cs:47