예제 #1
0
    private List <int> FindEdgeSubVertices(EdgeVertex_old p1, EdgeVertex_old p2, float scaleAmount)
    {
        List <int> subEdgeVertices = new List <int>();

        subEdgeVertices.Add(p1.listLoc);
        Vector3 pt1      = p1.transform.position;
        Vector3 pt2      = p2.transform.position;
        Vector3 distance = (pt2 - pt1).normalized;

        for (int i = 1; i < scaleAmount; i++)
        {
            Vector3 overlapPos = new Vector3(pt1.x + (1 * distance.x * i),
                                             pt1.y + (1 * distance.y * i),
                                             pt1.z + (1 * distance.z * i));

            Collider[] hitCollider = Physics.OverlapSphere(overlapPos, .25f);
            foreach (Collider collider in hitCollider)
            {
                EdgeVertex_old tp = collider.gameObject.GetComponent <EdgeVertex_old>();
                if (tp)
                {
                    subEdgeVertices.Add(tp.listLoc);
                    break;
                }
            }
        }

        subEdgeVertices.Add(p2.listLoc);
        return(subEdgeVertices);
    }
예제 #2
0
 private void OnMouseDown()
 {
     if (GameManager.SharedInstance.PlayMode)
     {
         return;
     }
     //Debug.Log(ptID);
     if (!_activePoint)
     {
         isActivePoint = true;
         _activePoint  = this;
         CleanAdjacentPointLists();
         ToggleSelectablePoints(false);
         coroutine = PreviewSelectablePoints();
         StartCoroutine(coroutine);
         _rend.enabled = true;
     }
     else if (_isActiveSelectable)
     {
         GameManager.SharedInstance.edgeManager.GenerateEdge(_activePoint, this);
         _activePoint.isActivePoint = false;
         _activePoint._rend.enabled = false;
         StopCoroutine(_activePoint.coroutine);
         ToggleSelectablePoints(true);
         _activePoint._onPoint = false;
         _activePoint          = null;
         _rend.enabled         = true;
     }
 }
예제 #3
0
    private void EdgeUtil(Graph graph, EdgeVertex_old tp1, EdgeVertex_old tp2, float scaleAmount)
    {
        var edgeSubVerts = FindEdgeSubVertices(tp1, tp2, scaleAmount);

        //FormEdgesFromSubVerts
        for (int i = 0; i < edgeSubVerts.Count - 1; i++)
        {
            graph.addEdge(edgeSubVerts[i], edgeSubVerts[i + 1]);
        }

        //TODO: figure out early exit for no edge being drawn
    }
예제 #4
0
    private bool GenerateSelectableVertex(Vector3 pos)
    {
        foreach (var point in _points)
        {
            if (point == pos)
            {
                return(false);
            }
        }

        GameObject edgePoint = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        Destroy(edgePoint.GetComponent <SphereCollider>());
        EdgeVertex_old tp = edgePoint.AddComponent <EdgeVertex_old>();

        tp.ptID        = "Pt" + _nextPtID;
        edgePoint.name = tp.ptID;
        tp.listLoc     = _nextPtID;

        if (Array.Exists(_initTPLocs, i => _nextPtID == i))
        {
            _initTPs.Add(_nextPtID, tp);
        }

        _nextPtID++;

        Renderer rend = edgePoint.GetComponent <Renderer>();

        rend.material.shader      = Shader.Find("Unlit/ColorZAlways");
        rend.material.renderQueue = 2350;
        rend.enabled = false;

        SphereCollider sphereCollider = edgePoint.AddComponent <SphereCollider>();

        sphereCollider.radius = .75f;

        edgePoint.transform.position   = pos;
        edgePoint.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);

        edgePoint.transform.parent = verticesHolder.transform;

        return(true);
    }
예제 #5
0
    //TODO: properly use the addEdge function to make use of the bool and avoid creating edge game object
    public void GenerateEdge(EdgeVertex_old tp1, EdgeVertex_old tp2)
    {
        Vector3 p1    = tp1.transform.position;
        Vector3 p2    = tp2.transform.position;
        int     pt1ID = tp1.listLoc;
        int     pt2ID = tp2.listLoc;

        float xRot = 90;
        float yRot = 0;
        //use the mid point of the two points to position the prefab since the anchor is the center of the quad aka the
        //center of our line
        Vector3 midPoint = Vector3.zero;

        midPoint = (p1 + p2) / 2;

        //To make quads always visible to the (isometric) camera there are some specific rotation angles needed. When a
        //line is moving only along the x-axis it's y rot needs to be 90 and when a line is moving along the y-axis only
        //it's y-rot is 90 and it's x-rot is 180. These will be standard values since (for now) we're not rotating the
        //camera.
        Vector3 distance = p2 - p1;
        float   scaleAmount;
        bool    xAxisEdge = false, yAxisEdge = false, zAxisEdge = false;

        if (Mathf.Abs(distance.x) > 0)
        {
            yRot        = 90;
            scaleAmount = Mathf.Abs(distance.x);
            xAxisEdge   = true;
        }
        else if (Mathf.Abs(distance.y) > 0)
        {
            xRot        = 180;
            yRot        = 90;
            scaleAmount = Mathf.Abs(distance.y);
            yAxisEdge   = true;
        }
        else
        {
            scaleAmount = Mathf.Abs(distance.z);
            zAxisEdge   = true;
        }

        string xGraphKey = p1.x.ToString();
        string yGraphKey = p1.y.ToString();
        string zGraphKey = p1.z.ToString();

        if (xAxisEdge)
        {
            EdgeUtil(_yGraphs[yGraphKey], tp1, tp2, scaleAmount);
            EdgeUtil(_zGraphs[zGraphKey], tp1, tp2, scaleAmount);

            FaceGenUtil(_yGraphs[yGraphKey]);
            FaceGenUtil(_zGraphs[zGraphKey]);
        }
        else if (yAxisEdge)
        {
            EdgeUtil(_xGraphs[xGraphKey], tp1, tp2, scaleAmount);
            EdgeUtil(_zGraphs[zGraphKey], tp1, tp2, scaleAmount);

            FaceGenUtil(_xGraphs[xGraphKey]);
            FaceGenUtil(_zGraphs[zGraphKey]);
        }
        else if (zAxisEdge)
        {
            EdgeUtil(_xGraphs[xGraphKey], tp1, tp2, scaleAmount);
            EdgeUtil(_yGraphs[yGraphKey], tp1, tp2, scaleAmount);

            FaceGenUtil(_xGraphs[xGraphKey]);
            FaceGenUtil(_yGraphs[yGraphKey]);
        }

        /*TODO: optimization idea; check overlap sphere for midpoint, if edge already present (e.g. larger overlapping edge)
         * or just the same edge, don't instantiate*/
        GameObject line =
            Instantiate(linePrefab, midPoint, Quaternion.Euler(xRot, yRot, 0));
        Transform lineTransform = line.transform;

        lineTransform.parent = gameObject.transform;
        var localScale = lineTransform.localScale;

        lineTransform.localScale = new Vector3(localScale.x,
                                               localScale.y * scaleAmount,
                                               localScale.z);
    }
예제 #6
0
    private void FillAdjacentList(List <EdgeVertex_old> adjacentList, Vector3 axis)
    {
        Vector3 tpPos = transform.position;
        //Check for adjacent points in positive axis dir
        Vector3 overlapPos = new Vector3(tpPos.x + axis.x, tpPos.y + axis.y, tpPos.z + axis.z);

        Collider[] hitCollider = Physics.OverlapSphere(overlapPos, .25f);
        int        i           = 1;

        while (hitCollider.Length > 0)
        {
            bool foundTp = false;
            foreach (Collider collider in hitCollider)
            {
                EdgeVertex_old tp = collider.gameObject.GetComponent <EdgeVertex_old>();
                if (tp)
                {
                    adjacentList.Add(tp);
                    foundTp = true;
                    break;
                }
            }
            if (!foundTp)
            {
                break;
            }
            i++;
            overlapPos = new Vector3(tpPos.x + axis.x * i,
                                     tpPos.y + axis.y * i,
                                     tpPos.z + axis.z * i);
            hitCollider = Physics.OverlapSphere(overlapPos, .25f);
        }

        //Check for adjacent points in negative axis dir
        overlapPos  = new Vector3(tpPos.x - axis.x, tpPos.y - axis.y, tpPos.z - axis.z);
        hitCollider = Physics.OverlapSphere(overlapPos, .25f);
        i           = 1;
        while (hitCollider.Length > 0)
        {
            bool foundTp = false;
            foreach (Collider collider in hitCollider)
            {
                EdgeVertex_old tp = collider.gameObject.GetComponent <EdgeVertex_old>();
                if (tp)
                {
                    adjacentList.Add(tp);
                    foundTp = true;
                    break;
                }
            }
            if (!foundTp)
            {
                break;
            }
            i++;
            overlapPos = new Vector3(tpPos.x - axis.x * i,
                                     tpPos.y - axis.y * i,
                                     tpPos.z - axis.z * i);
            hitCollider = Physics.OverlapSphere(overlapPos, .25f);
        }
    }