IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Label.cs
1 using UnityEngine;
11 public class Label : Point{
12 
13 
14  public float dispAngle;
16  public GameObject annotationLabel;
20  public float[] angleToLeftAndRightCorner = new float[2];
22  public float angleToLeftLabel;
23  public float angleToRightLabel;
25  public Vector2[] corners = new Vector2[4];
27  public float weight;
29  public Label leftLabel;
30  public Label rightLabel;
31 
32  public Label()
33  {
34 
35  }
36 
41  public Label(float y, float x, Vector3 v, int p, float a, GameObject annoPoint)
42  {
43 
44  this.y = y;
45  this.x = x;
46 
47  this.planeNumber = p;
48 
49  this.position = v;
50 
51  this.angle = a;
52 
53  this.annotationPoint = annoPoint;
54 
55  annotationLabel = annotationPoint.GetComponent<Annotation>().getLabel();
56 
58  }
59 
60 
61 
65  public void moveToNewPosition()
66  {
67 
68  if (annotationLabel != null && annotationPoint != null)
69  {
70  if (!float.IsNaN(this.position.x) && !float.IsNaN(this.position.y) && !float.IsNaN(this.position.z))
71  {
72 
73  CanvasMovement lm = annotationLabel.GetComponent<CanvasMovement>();
74  lm.annotationPoint = annotationPoint;
75  lm.newPos = this.position;
76  }
77 
78  }
79  }
80 
84  public void calculateCornersOnPlane(GameObject meshNode, GameObject meshPositionNode, GameObject meshViewerBase)
85  {
86 
87 
88  float width = annotationLabel.GetComponent<RectTransform>().rect.width * annotationLabel.transform.parent.localScale.x * annotationLabel.GetComponent<RectTransform>().localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
89  float height = annotationLabel.GetComponent<RectTransform>().rect.height * annotationLabel.transform.parent.localScale.x * annotationLabel.GetComponent<RectTransform>().localScale.x * meshNode.transform.localScale.x * meshPositionNode.transform.localScale.x * meshViewerBase.transform.localScale.x;
90 
91  corners[0].x = x - width / 2;
92  corners[0].y = y + height / 2;
93 
94  corners[1].x = x + width / 2;
95  corners[1].y = y + height / 2;
96 
97  corners[2].x = x - width / 2;
98  corners[2].y = y - height / 2;
99 
100  corners[3].x = x + width / 2;
101  corners[3].y = y - height / 2;
102 
103  }
104 
108  public void calculateAngleToLeftAndRight(Vector3 xdirection, Vector3 ydirection, Vector3 planeOrigin)
109  {
110 
111  if(angle > 0 && angle <= 90)
112  {
113  angleToLeftAndRightCorner[0] = Vector3.Angle(corners[0].x * xdirection + corners[0].y * ydirection, this.position - planeOrigin);
114  angleToLeftAndRightCorner[1] = Vector3.Angle(corners[3].x * xdirection + corners[3].y * ydirection, this.position - planeOrigin);
115 
116  }
117  else if (angle > 90 && angle <= 180)
118  {
119  angleToLeftAndRightCorner[0] = Vector3.Angle(corners[1].x * xdirection + corners[1].y * ydirection, this.position - planeOrigin);
120  angleToLeftAndRightCorner[1] = Vector3.Angle(corners[2].x * xdirection + corners[2].y * ydirection, this.position - planeOrigin);
121  }
122  else if(angle > 180 && angle <= 270)
123  {
124  angleToLeftAndRightCorner[0] = Vector3.Angle(corners[3].x * xdirection + corners[3].y * ydirection, this.position - planeOrigin);
125  angleToLeftAndRightCorner[1] = Vector3.Angle(corners[0].x * xdirection + corners[0].y * ydirection, this.position - planeOrigin);
126  }
127  else
128  {
129  angleToLeftAndRightCorner[0] = Vector3.Angle(corners[2].x * xdirection + corners[2].y * ydirection, this.position - planeOrigin);
130  angleToLeftAndRightCorner[1] = Vector3.Angle(corners[1].x * xdirection + corners[1].y * ydirection, this.position - planeOrigin);
131  }
132 
133 
134  }
135 
139  public void adaptLabelToZooming(float meshScale, float labelscale) // die größe der Labels sollten unabhängig vom zoomen sein..
140  { // ist jetzt im canvasmovement..
141  if(annotationLabel != null)
142  {
143  annotationLabel.GetComponent<RectTransform>().localScale = new Vector3(labelscale / meshScale, labelscale / meshScale, labelscale / meshScale);
144  }
145 
146  }
147 
154  public float calculateOffset()
155  {
156 
157  float offset = 0;
158 
159  float height = (corners[0] - corners[2]).magnitude;
160  float width = (corners[0] - corners[1]).magnitude;
161 
162  float a = (height / 2) + Mathf.Sqrt((height / 4) + (width / 4));
163  float b = Mathf.Sqrt(a * (height / 2));
164  float epsilon = (width / (a * 2));
165 
166 
167 
168  if (angle >= 0 && angle <= 270)
169  {
170 
171  float phi = 270 - angle;
172  phi = Mathf.Deg2Rad * phi;
173 
174  float r = b / (Mathf.Sqrt(1 - epsilon * epsilon * Mathf.Cos(phi) * Mathf.Cos(phi)));
175 
176  offset = r;
177 
178 
179  }
180  else{
181 
182  float phi = 360 + (270 - angle);
183  phi = Mathf.Deg2Rad * phi;
184 
185  float r = b / (Mathf.Sqrt(1 - epsilon * epsilon * Mathf.Cos(phi) * Mathf.Cos(phi)));
186 
187  offset = r;
188 
189  }
190 
191 
192  return offset;
193 
194  }
195 
199  public void calculateWeight(float weightAngleSizeRatio)
200  {
201 
202  float angleSize = angleToLeftAndRightCorner[0] + angleToLeftAndRightCorner[1];
203 
204  weight = weightAngleSizeRatio * angleSize;
205 
206 
207  }
208 }
float angleToLeftLabel
Definition: Label.cs:22
float[] angleToLeftAndRightCorner
Definition: Label.cs:20
Vector2[] corners
Definition: Label.cs:25
void calculateCornersOnPlane(GameObject meshNode, GameObject meshPositionNode, GameObject meshViewerBase)
hier werden die Positionen der Ecken eines Annotationlabel berechnet
Definition: Label.cs:84
Point pointOnPlane
Definition: Label.cs:18
GameObject annotationLabel
Definition: Label.cs:16
Point.
Definition: Point.cs:8
void calculateAngleToLeftAndRight(Vector3 xdirection, Vector3 ydirection, Vector3 planeOrigin)
hier wird berechnet welchen Abstand in Grad die linke und rechte Ecke zum Mittelpunkt der Labels hat ...
Definition: Label.cs:108
Label(float y, float x, Vector3 v, int p, float a, GameObject annoPoint)
Hat einen int Parameter.
Definition: Label.cs:41
GameObject annotationPoint
Definition: Point.cs:15
Label.
Definition: Label.cs:11
void moveToNewPosition()
Hier wird das GameObject Annotationlabel an eine neue position verschoben.
Definition: Label.cs:65
float calculateOffset()
Offset berechnung.
Definition: Label.cs:154
float angleToRightLabel
Definition: Label.cs:23
float angle
Definition: Point.cs:12
void adaptLabelToZooming(float meshScale, float labelscale)
hier wird das Annotationlabel an das Zoomen des Nutzers angepasst
Definition: Label.cs:139
float weight
Definition: Label.cs:27
Vector3 position
Definition: Point.cs:11
float dispAngle
Definition: Label.cs:14
void calculateWeight(float weightAngleSizeRatio)
Gewichtsberechnung.
Definition: Label.cs:199