public bool addConnection(GameObject connection, bool drawnTowardConnection)
    {
        /*
         * TODO:
         * Remove freedomLine and plane if a new connection is added when a constraint already exists
         */
        if (connectionList.Contains(connection))
        {
            return(false);
        }
        if (connection.CompareTag("Intermediate"))
        {
            return(false);
        }

        //first, generate a hemisphere
        bool dirTowardConnection = false;

        if (connection.CompareTag("Input") || connection.CompareTag("Output"))
        {
            dirTowardConnection = calculateForceDirection(this.intermediatePoint, connection);
        }
        else
        {
            dirTowardConnection = drawnTowardConnection;
        }

        Vector3    scale      = new Vector3(5, 5, 5);
        GameObject hemisphere = Hemisphere.CreateHemisphere(hemisphereMaterial1, intermediatePoint.transform.position, connection.transform.position, dirTowardConnection, scale);

        connectionList.Add(connection);
        hemisphereList.Add(hemisphere);
        hemisphere.transform.parent     = intermediatePoint.transform;
        hemisphere.transform.localScale = scale;
        truncatedHemisphere             = truncate(hemisphere, truncatedHemisphere);
        return(true);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        getClosestPoint();
        preview.transform.position   = closestPoint;
        preview.transform.localScale = gameObject.transform.lossyScale;

        isColliding = false;
        preview.SetActive(true);
        //check if our preview is colliding with a placed sphere
        foreach (Transform transform in ((Networking)Networking.GetComponent(typeof(Networking))).allTransformList)
        {
            //print(dist);
            if (transform.position == closestPoint)
            {
                isColliding      = true;
                currCollidingObj = transform.gameObject;
                Color color = ((Renderer)transform.gameObject.GetComponent <Renderer>()).material.color;
                color.a = 1;
                ((Renderer)transform.gameObject.GetComponent <Renderer>()).material.color = color;
            }
            else
            {
                Color color = ((Renderer)transform.gameObject.GetComponent <Renderer>()).material.color;
                color.a = 0.353F;
                ((Renderer)transform.gameObject.GetComponent <Renderer>()).material.color = color;
            }
        }

        if (OVRInput.GetDown(OVRInput.Button.One)) //Places the initial sphere
        {
            forceCanvas.SetActive(true);
            if (isColliding && (currCollidingObj.CompareTag("Input") || currCollidingObj.CompareTag("Output")))
            {
                originSphere  = currCollidingObj;
                createdOrigin = false;
            }

            else if (!isColliding)
            {
                originSphere  = createPoint();
                createdOrigin = true;
            }
            else
            {
                return;
            }

            originSet       = true;
            currLine        = new VectorLine("NewForceLine", new List <Vector3>(), 30.0f);
            currLine.endCap = "Arrow";
            currLine.Draw3DAuto();
            currLine.points3.Add(originSphere.transform.position);
            currLine.points3.Add(originSphere.transform.position);
            currLine.SetColor(Color.blue);
        }

        if (OVRInput.Get(OVRInput.Button.One) && originSet)
        {
            origin = originSphere.transform.position;
            dest   = closestPoint;

            if (origin != Vector3.zero && dest != Vector3.zero)
            {
                currLine.points3[0] = dest;
                currLine.points3[1] = origin;
                Vector3 dest_local   = domain.transform.InverseTransformPoint(dest);
                Vector3 origin_local = domain.transform.InverseTransformPoint(origin);
                forceVectorLH = dest_local - origin_local;
                if (forceVectorLH.magnitude > 1)
                {
                    forceVectorLH.Normalize();
                }
                forceVectorRH  = new Vector3(forceVectorLH.x, forceVectorLH.y, -forceVectorLH.z);
                forceText.text = forceVectorRH.x.ToString("F4") + "\n" + forceVectorRH.y.ToString("F4") + "\n" + forceVectorRH.z.ToString("F4") + "\n" + forceVectorRH.magnitude.ToString("F4") + "\n";
            }
        }

        if (OVRInput.GetUp(OVRInput.Button.One) && originSet)
        {
            forceCanvas.SetActive(false);
            originSet = false;
            GameObject destSphere;
            GameObject InputOutputPoint;
            GameObject forcePoint;
            if (createdOrigin && (!isColliding || (isColliding && !(currCollidingObj.CompareTag("Input") || currCollidingObj.CompareTag("Output")))))
            {
                VectorLine.Destroy(ref currLine);
                ((Networking)Networking.GetComponent(typeof(Networking))).forceTransformList.Remove(originSphere.transform);
                Destroy(originSphere);
                createdOrigin = false;
                return;
            }
            else if (!createdOrigin && isColliding)
            {
                VectorLine.Destroy(ref currLine);
                createdOrigin = false;
                return;
            }
            else if (isColliding && createdOrigin)
            {
                destSphere       = currCollidingObj;
                InputOutputPoint = currCollidingObj;
                forcePoint       = originSphere;
            }
            else
            {
                destSphere       = createPoint();
                InputOutputPoint = originSphere;
                forcePoint       = destSphere;
            }

            if (InputOutputPoint.GetComponent <InputOutputInfo>().GetForcePoint() != null) //we already have a forcepoint
            {
                VectorLine.Destroy(ref currLine);
                Networking.GetComponent <Networking>().forceTransformList.Remove(forcePoint.transform);
                Destroy(forcePoint);
                createdOrigin = false;
                return;
            }

            GameObject vectorLineObj = GameObject.Find("NewForceLine");
            //vectorLineObj.transform.parent = forcePoint.transform;
            vectorLineObj.name = "ForceLine";
            //add to our force vector
            domain.GetComponent <InitLines>().forceVectorList.Add(forceVectorLH);

            //ForcePointInfo
            forcePoint.GetComponent <ForcePointInfo>().Setup(InputOutputPoint, currLine, createdOrigin);

            //InputOutputInfo
            Vector3    scale      = new Vector3(10, 10, 10);
            GameObject hemisphere = Hemisphere.CreateHemisphere(hemisphereMaterial, InputOutputPoint.transform.position, forcePoint.transform.position, !createdOrigin, scale);
            InputOutputPoint.GetComponent <InputOutputInfo>().Setup(InputOutputPoint, forcePoint, hemisphere, forceVectorRH, createdOrigin);
            hemisphere.transform.parent     = forcePoint.transform;
            hemisphere.transform.localScale = scale;
            createdOrigin = false;
        }
    }
Beispiel #3
0
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            hemisphere1 = Hemisphere.CreateHemisphere(hemisphereMaterial1, pos.transform.position, target1.transform.position, false);
            //updatePos = true;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            hemisphere2 = Hemisphere.CreateHemisphere(hemisphereMaterial2, pos.transform.position, target2.transform.position, false);
            final1      = Hemisphere.GetIntersection(hemisphere1, hemisphere2, truncatedHemisphereMaterial, true);
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            dottedLine = new VectorLine("dotted", new List <Vector3>(), texture, 16.0f);
            dottedLine.points3.Add(pos.transform.position);
            dottedLine.points3.Add(freedomTarget.transform.position);
            dottedLine.textureScale = 1.00f;
            dottedLine.Draw3DAuto();
            lineObj = GameObject.Find("dotted");
            plane   = GameObject.CreatePrimitive(PrimitiveType.Cube);
            plane.transform.localScale = new Vector3(10, 10, 0.001F);
            plane.transform.rotation   = Quaternion.LookRotation(origin.transform.position - plane.transform.position);
            plane.transform.position   = pos.transform.position;
            plane.GetComponent <MeshRenderer>().sharedMaterial = mat;

            updatePos = true;
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            ToggleView();
        }

        if (updatePos)
        {
            hemisphere1.transform.rotation = Quaternion.LookRotation(target1.transform.position - hemisphere1.transform.position);
            hemisphere2.transform.rotation = Quaternion.LookRotation(target2.transform.position - hemisphere2.transform.position);

            Vector3 euler = hemisphere1.transform.rotation.eulerAngles;
            hemisphere1.transform.eulerAngles = new Vector3(euler.z, euler.y + 90F, euler.x);
            euler = hemisphere2.transform.rotation.eulerAngles;
            hemisphere2.transform.eulerAngles = new Vector3(euler.z, euler.y + 90F, euler.x);
            dottedLine.points3[0]             = pos.transform.position;
            dottedLine.points3[1]             = freedomTarget.transform.position;
            plane.transform.rotation          = Quaternion.LookRotation(origin.transform.position - freedomTarget.transform.position);
            //freedomPos.transform.position = Physics.ClosestPoint(freedomTarget.transform.position, origin.GetComponent<Collider>(), origin.transform.position, origin.transform.rotation);

            //int layerMask = 1 << LayerMask.NameToLayer("hemisphere");
            //Collider[] list = Physics.OverlapSphere(freedomPos.transform.position, freedomPos.transform.localScale.x, layerMask);
            //print(list.Length);
            //if (list.Length == 2)
            //{
            //    lineObj.SetActive(true);
            //}
            //else
            //{
            //    lineObj.SetActive(false);
            //}

            if (InTruncation(origin, freedomTarget))
            {
                lineObj.SetActive(true);
            }
            else
            {
                lineObj.SetActive(false);
            }
        }
        demoLine.points3[0] = target1.transform.position;
        demoLine.points3[1] = pos.transform.position;
        demoLine.points3[2] = target2.transform.position;
        demoLine.points3[3] = pos.transform.position;
    }