Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     CurrentPloygon = new Ploygon()
     {
         IsFinished = false,
         Root       = new GameObject(),
         Points     = new List <Vector3>()
     };
 }
Beispiel #2
0
    /// <summary>
    /// Calculate an area of geometry
    /// </summary>
    /// <param name="ploygon"></param>
    /// <returns></returns>
    float CalculatePloygonArea(Ploygon ploygon)
    {
        var s = 0.0f;
        var i = 1;
        var n = ploygon.Points.Count;

        for (; i < n - 1; i++)
        {
            s += CalculateTriangleArea(ploygon.Points[0], ploygon.Points[i], ploygon.Points[i + 1]);
        }
        return(0.5f * Mathf.Abs(s));
    }
Beispiel #3
0
 /// <summary>
 /// reset current unfinished geometry
 /// </summary>
 public void Reset()
 {
     if (CurrentPloygon != null && !CurrentPloygon.IsFinished)
     {
         Destroy(CurrentPloygon.Root);
         CurrentPloygon = new Ploygon()
         {
             IsFinished = false,
             Root       = new GameObject(),
             Points     = new List <Vector3>()
         };
     }
 }
Beispiel #4
0
    float CalculatePloygonArea(Ploygon ploygon)
    {
        var s = 0.0f;
        var i = 1;
        var n = ploygon.Points.Count;

        for (; i < n - 1; i++)
        {
            s += CalculateTriangleArea(ploygon.Points[0], ploygon.Points[i], ploygon.Points[i + 1]);
        }

        //This should trigger mesh coloring
        //VertsColor(ploygon.Root);

        return(0.5f * Mathf.Abs(s));
    }
Beispiel #5
0
    /// <summary>
    ///  handle new point users place
    /// </summary>
    /// <param name="LinePrefab"></param>
    /// <param name="PointPrefab"></param>
    /// <param name="TextPrefab"></param>
    public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject TextPrefab)
    {
        var hitPoint = GazeManager.Instance.HitInfo.point;
        var point    = (GameObject)Instantiate(PointPrefab, hitPoint, Quaternion.identity);
        var newPoint = new Point
        {
            Position = hitPoint,
            Root     = point
        };

        if (CurrentPloygon.IsFinished)
        {
            CurrentPloygon = new Ploygon()
            {
                IsFinished = false,
                Root       = new GameObject(),
                Points     = new List <Vector3>()
            };

            CurrentPloygon.Points.Add(newPoint.Position);
            newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
        }
        else
        {
            CurrentPloygon.Points.Add(newPoint.Position);
            newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
            if (CurrentPloygon.Points.Count > 1)
            {
                var index     = CurrentPloygon.Points.Count - 1;
                var centerPos = (CurrentPloygon.Points[index] + CurrentPloygon.Points[index - 1]) * 0.5f;
                var direction = CurrentPloygon.Points[index] - CurrentPloygon.Points[index - 1];
                var distance  = Vector3.Distance(CurrentPloygon.Points[index], CurrentPloygon.Points[index - 1]);
                var line      = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
                line.transform.localScale = new Vector3(distance, 0.005f, 0.005f);
                line.transform.Rotate(Vector3.down, 90f);
                line.transform.parent = CurrentPloygon.Root.transform;
            }
        }
    }