Exemplo n.º 1
0
 public void Delete()
 {
     // Go through links and delete all linerenderers
     for (int j = 0; j < points.Count; j++)
     {
         PointMass temp  = (PointMass)points [j];
         ArrayList links = temp.links;
         for (int i = 0; i < links.Count; i++)
         {
             PointLink link = (PointLink)links [i];
             link.Destroy();
         }
     }
     // Destroy all spheres
     foreach (PointMass p in points)
     {
         GameObject sphere = p.pointrender;
         if (sphere != null)
         {
             Destroy(sphere);
         }
     }
     // Destroy this
     Destroy(gameObject);
 }
Exemplo n.º 2
0
 public void Render()
 {
     // render all links coming from this point
     for (int i = 0; i < links.Count; i++)
     {
         PointLink currlink = (PointLink)links [i];
         currlink.Render();
     }
     if (isVisible)
     {
         pointrender.transform.position = new Vector3(position.x, position.y, 0);
     }
 }
Exemplo n.º 3
0
    // called multiple times per frame
    public bool SolveConstraints()
    {
        // Stretch or pull all points from links
        for (int i = 0; i < links.Count; i++)
        {
            PointLink currlink = (PointLink)links [i];
            currlink.Solve();
        }

        // Skip most if point is anchored (cannot change)
        if (!anchored)
        {
            // Boundary Constraints, true return deletes the goat
            if (position.y < -4f)
            {
                return(true);
            }
            if (position.y > 11f)
            {
                return(true);
            }
            if (position.x > 11f)
            {
                return(true);
            }
            if (position.x < -11f)
            {
                return(true);
            }

            // Constraints to hit mountain
            CreateMountain   mountain = (CreateMountain)gi.GetComponent("CreateMountain");
            TriangleStruct[] left     = mountain.lefttriangles;
            TriangleStruct[] right    = mountain.righttriangles;
            TriangleStruct   top      = mountain.toptriangle;

            if (position.y <= 2.0f)
            {
                // left
                if (position.x >= -5.0f && position.x <= -1.0f)
                {
                    for (int i = 0; i < left.Length; i++)
                    {
                        TriangleStruct lefttri = (TriangleStruct)left [i];
                        if (lefttri.PointInTriangle(position))
                        {
                            position = lefttri.Relocate(position);
                            if (isAnchor)
                            {
                                anchored = true;
                                anchor   = position;
                            }
                        }
                    }
                }
                // right
                else if (position.x >= 1.0f && position.x <= 5.0f)
                {
                    for (int i = 0; i < right.Length; i++)
                    {
                        TriangleStruct righttri = (TriangleStruct)right [i];
                        if (righttri.PointInTriangle(position))
                        {
                            position = righttri.Relocate(position);
                            if (isAnchor)
                            {
                                anchored = true;
                                anchor   = position;
                            }
                        }
                    }
                }
                // middle
                else if (position.x >= -1.0f && position.x <= 1.0f)
                {
                    if (top.PointInTriangle(position))
                    {
                        position = top.Relocate(position);
                        if (isAnchor)
                        {
                            anchored = true;
                            anchor   = position;
                        }
                    }
                }
            }
        }
        // pin to mountain if anchored by a foot
        if (anchored)
        {
            position = anchor;
        }
        return(false);
    }
Exemplo n.º 4
0
 public void RemoveLink(PointLink l)
 {
     links.Remove(l);
 }
Exemplo n.º 5
0
    // creates a link between this point and another
    public void AttachTo(PointMass p, float restingdist, float stiff, bool visible, Color c)
    {
        PointLink link = new PointLink(this, p, restingdist, stiff, visible, c);

        links.Add(link);
    }