2 using System.Collections;
3 using UnityEngine.EventSystems;
7 public GameObject arrow1;
8 public GameObject arrow2;
10 public float maxScale = 15f;
11 public float minScale = 0.5f;
13 private bool reScale =
false;
14 private Vector3 rescaleDirection;
16 public void rescaleAnnotation(BaseEventData eventData) {
17 PointerEventData data = eventData as PointerEventData;
18 if (data.button != PointerEventData.InputButton.Left) {
21 rescaleDirection = Vector3.Scale(arrow1.transform.localPosition,arrow1.transform.localPosition).normalized;
25 public void stopRescale(BaseEventData eventData) {
26 PointerEventData data = eventData as PointerEventData;
27 if (data.button != PointerEventData.InputButton.Left) {
33 private void rescaleMesh() {
34 InputDevice inputDevice = InputDeviceManager.instance.currentInputDevice;
35 Plane intersectPlane =
new Plane ();
37 Ray intersectRay = inputDevice.createRay ();
39 intersectRay.origin = inputDevice.getEventCamera ().transform.position;
42 Vector3 camAnnoVec = (intersectRay.origin -
this.transform.position);
43 Vector3 globalDir = this.transform.TransformDirection (rescaleDirection);
44 Vector3 planeVec = Vector3.Cross (globalDir, camAnnoVec);
45 Vector3 normal = Vector3.Cross (globalDir, planeVec);
48 intersectPlane.SetNormalAndPosition (normal, this.transform.position);
50 if (intersectPlane.Raycast (intersectRay, out dist)) {
51 Vector3 intersectPoint = intersectRay.GetPoint (dist);
53 intersectPoint = this.transform.InverseTransformPoint (intersectPoint);
56 intersectPoint = Vector3.Scale (intersectPoint, rescaleDirection);
58 intersectPoint = Vector3.Scale (intersectPoint, intersectPoint.normalized);
59 Vector3 newScale = (intersectPoint.normalized * intersectPoint.magnitude) * 2;
61 if (newScale.magnitude > maxScale || newScale.magnitude < minScale) {
65 arrow2.transform.localPosition = 0.5f * newScale + newScale.normalized;
66 arrow1.transform.localPosition = -1f * arrow2.transform.localPosition;
68 Vector3 actScale = this.GetComponentInParent<
Annotation> ().getMeshScale ();
70 newScale = actScale - Vector3.Scale (actScale, rescaleDirection) + newScale;
73 this.GetComponentInParent<Annotation> ().rescaleMesh (newScale);
81 Vector3 scale = this.GetComponentInParent<
Annotation> ().getMeshScale ();
82 Vector3 rescaleDir = Vector3.Scale(arrow1.transform.localPosition,arrow1.transform.localPosition).normalized;
83 scale = Vector3.Scale (rescaleDir, scale);
84 arrow2.transform.localPosition = 0.5f * scale + scale.normalized;
85 arrow1.transform.localPosition = -1f * arrow2.transform.localPosition;
88 public void Update() {
89 this.transform.rotation = this.GetComponentInParent<
Annotation>().myAnnotationMesh.transform.rotation;