예제 #1
0
        public void AddSphere(Circumcircle s)
        {
            if (s.ghost)
            {
                ghostSpheres++;
            }

            foreach (Cell c in s.verts)
            {
                if (c != this)
                {
                    VoronoiEdge v = FindEdge(c);

                    if (v != null)
                    {
                        v.SpherePair = s;
                    }
                    else
                    {
                        v = new VoronoiEdge(c, s);
                        edges.Add(v);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Flips spheres.
        /// Used for orienting clockwise.
        /// </summary>
        public void Flip()
        {
            Circumcircle c = spherePair;

            spherePair = sphere;
            sphere     = c;
        }
예제 #3
0
 /// <summary>
 /// Removes sphere from edge.
 /// </summary>
 /// <returns><c>true</c>, if edge now contains no spheres, <c>false</c> otherwise.</returns>
 /// <param name="s">S.</param>
 public bool RemovingOnlySphere(Circumcircle s)
 {
     if (sphere == s)
     {
         if (spherePair == null)
         {
             return(true);
         }
         else
         {
             ReduceSpheres();
         }
     }
     else if (spherePair == s)
     {
         if (sphere == null)
         {
             return(true);
         }
         else
         {
             spherePair = null;
         }
     }
     return(false);
 }
예제 #4
0
 /// <summary>
 /// Checks whether this edge contains the sphere.
 /// </summary>
 /// <returns><c>true</c>, if sphere was contained, <c>false</c> otherwise.</returns>
 /// <param name="s">S.</param>
 public bool ContainsSphere(Circumcircle s)
 {
     if (sphere == s || spherePair == s)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #5
0
        /// <summary>
        /// Setup for mesh creation.
        /// Sorts edge list into a sequential chain clockwise and adds vertices into mesh.
        /// </summary>
        // TODO: look into using a clean list instead of reshuffling
        public void MeshSetup()
        {
            if (!root)
            {
                PrepareFirstEdge();

                mesh = new CellMesh(point, edges.Count);

                Circumcircle current = edges[0].SpherePair;
                VoronoiEdge  next;                                                              //not really needed but it works while it's here

                mesh.AddVert(edges[0].Sphere.Circumcenter);

                int i = 0, j = 0;

                do
                {
                    mesh.AddVert(current.Circumcenter);

                    j = i;
                    i++;

                    //searching for next edge in the chain
                    do
                    {
                        j++;
                        if (j >= edges.Count)
                        {
                            Debug.Log("no matching edge found");
                        }
                    }while(current != edges[j].Sphere && current != edges[j].SpherePair);

                    // moving edge to the point it should be in the list if it isn't already there
                    if (i != j)
                    {
                        next = edges[j];
                        edges.RemoveAt(j);
                        edges.Insert(i, next);
                    }

                    // checking for it's orientation
                    if (current == edges[i].SpherePair)
                    {
                        edges[i].Flip();
                    }

                    current = edges[i].SpherePair;
                }while(current != edges[0].Sphere);

                mesh.ComputeUVs();
            }
        }
예제 #6
0
        /// <summary>
        /// Checks for Sphere collision.
        /// </summary>
        /// <returns><c>true</c>, if cell is inside sphere, <c>false</c> otherwise.</returns>
        /// <param name="c">C.</param>
        /// <param name="s">S.</param>
        private bool SphereCollision(Cell c, Circumcircle s)
        {
            Vector3 dif = c.point - s.Circumcenter;

            if (dif.sqrMagnitude <= s.circumradiusSquared)                                                                      //using square mag for xz plane
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        public void RemoveSphere(Circumcircle s)
        {
            if (s.ghost)
            {
                ghostSpheres--;
            }

            for (int i = edges.Count - 1; i >= 0; i--)
            {
                if (edges[i].ContainsSphere(s) && edges[i].RemovingOnlySphere(s))
                {
                    edges.RemoveAt(i);
                }
            }
        }
예제 #8
0
 public void ReduceSpheres()
 {
     sphere     = spherePair;
     spherePair = null;
 }
예제 #9
0
 public VoronoiEdge(Cell c2, Circumcircle s1)
 {
     cellPair = c2;
     sphere   = s1;
 }