KubiPL

POIAngleIssue

Jan 26th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. for (int i = 0; i < loc.Length; i++) //Pass thru whole localizations in DB
  2.             {
  3.                 //POI position relative to user pos
  4.                 float y = (float)(loc[i].x - lat);
  5.                 float x = (float)(loc[i].y - lng);
  6.  
  7.                 Vector2 pos = new Vector2(x, y);
  8.                 double dist = DistanceAlgorithm.DistanceBetweenPlaces(lng, lat, loc[i].y, loc[i].x); //Distance from user to point in meters
  9.  
  10.                 Debug.Log(dist);
  11.  
  12.                 if (dist < m_POIMinDistance) //Stop drawing closer objects i.e. 10 meters
  13.                     continue;
  14.  
  15.                 Vector2 fromVector = Vector2.up; // North direction (0, 1)
  16.                 Vector2 toVector = pos;
  17.  
  18.                 float ang = Vector2.Angle(fromVector, toVector); //Get angle between north and POI based
  19.                 Vector3 cross = Vector3.Cross(fromVector, toVector); //Cross production to maintain proper angle
  20.  
  21.                 if (cross.z > 0)
  22.                     ang = 360 - ang; //Got angle
  23.  
  24.                 Debug.Log(ang);
  25.  
  26.                 //Force point on the circle
  27.                 x = m_POIScale * m_POIDistanceFactor * Mathf.Cos(ang);
  28.                 y = m_POIScale * m_POIDistanceFactor * Mathf.Sin(ang);
  29.                 pos = new Vector2(x, y); //Apply scaled positions to vector
  30.  
  31.                 //Create POI prefab
Advertisement
Add Comment
Please, Sign In to add comment