Example #1
0
 public void OnAButtonPress(SteamVR_Action_Boolean action, SteamVR_Input_Sources source)
 {
     rightMenuShow = !rightMenuShow;
     RightHandCanvas.GetComponent <Canvas>().enabled = rightMenuShow;
     handVibrate.Execute(0f, 0.2f, 60f, 0.4f, source);
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        LeftHand.GetComponent <SphereCollider>().enabled = currFunction == Functions.Scale;

        RightHand.GetComponent <SphereCollider>().enabled = currFunction == Functions.Scale;
        RightHand.GetComponent <LineRenderer>().enabled   = currFunction == Functions.Add ||
                                                            currFunction == Functions.Colour || leftMenuShow;

        LeftHand.GetComponent <LineRenderer>().enabled = rightMenuShow;

        LeftHandCanvas.SetActive(leftMenuShow);
        RightHandCanvas.SetActive(rightMenuShow);

        // Menu
        leftRay.origin  = LeftHand.transform.position;
        rightRay.origin = RightHand.transform.position;

        leftRay.direction  = -1f * LeftHand.transform.up;
        rightRay.direction = -1f * RightHand.transform.up;

        foreach (GameObject i in buttons)
        {
            i.GetComponent <Button>().image.color = Color.white;
        }

        if (leftMenuShow)
        {
            RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, RightHand.transform.position + RightHand.transform.up * -0.2f });

            if (Physics.Raycast(rightRay, out RaycastHit rightHit, 0.2f, (1 << 5)))
            {
                if (rightHit.collider.gameObject.CompareTag("Button"))
                {
                    rightHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsRightTriggerDown)
                    {
                        switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Cut":
                            currFunction = Functions.Cut;
                            break;

                        case "Add":
                            currFunction = Functions.Add;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Add);
                            break;

                        case "Remove":
                            currFunction = Functions.Remove;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Remove);
                            break;

                        case "Colour":
                            currFunction = Functions.Colour;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Colour);
                            break;

                        case "Scale":
                            currFunction = Functions.Scale;
                            ProxyScale.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.3f;

                            ogVoxelSize = Voxel.VoxelSize;

                            ProxyScale.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                            ScaleTool1.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * -0.05f + ProxyScale.transform.right * -0.05f + ProxyScale.transform.forward * 0.05f;
                            ScaleTool2.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * 0.05f + ProxyScale.transform.right * 0.05f + ProxyScale.transform.forward * -0.05f;
                            origScaleDistance             = Vector3.Distance(ScaleTool1.transform.position, ScaleTool2.transform.position);

                            break;

                        case "Translate":
                            currFunction = Functions.Translate;
                            TranslateControl.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.4f;
                            break;

                        case "Rotate":
                            currFunction = Functions.Rotate;
                            break;
                        }

                        if (currFunction == Functions.Scale)
                        {
                            switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                            {
                            case "Scale +":
                                Voxel.VoxelSize += 0.01f;
                                polygon.RecomputeChunks();
                                break;

                            case "Scale -":
                                Voxel.VoxelSize -= 0.01f;
                                polygon.RecomputeChunks();
                                break;
                            }
                        }

                        IsRightTriggerDown = leftMenuShow = LeftHandCanvas.GetComponent <Canvas>().enabled = false;
                    }
                }

                RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, rightHit.point });
            }
        }
        else
        {
            RightHand.GetComponent <LineRenderer>().SetPositions(new[] { Vector3.zero, Vector3.zero });
        }

        if (rightMenuShow)
        {
            LeftHand.GetComponent <LineRenderer>().SetPositions(new[] { LeftHand.transform.position, LeftHand.transform.position + LeftHand.transform.up * -0.2f });

            if (Physics.Raycast(leftRay, out RaycastHit leftHit, 0.2f, (1 << 5)))
            {
                if (leftHit.collider.gameObject.CompareTag("Button"))
                {
                    leftHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsLeftTriggerDown)
                    {
                        switch (leftHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Cube":
                            polygon.InitCube();
                            break;

                        case "Sphere":
                            polygon.InitSphere();
                            break;

                        case "Clear":
                            polygon.ClearChunks();
                            break;
                        }
                        IsLeftTriggerDown = rightMenuShow = RightHandCanvas.GetComponent <Canvas>().enabled =
                            LeftHand.GetComponent <LineRenderer>().enabled = false;
                    }
                }

                LeftHand.GetComponent <LineRenderer>().SetPositions(new[] { LeftHand.transform.position, leftHit.point });
            }
        }
        //Menu

        // Switch tools
        switch (currFunction)
        {
        case Functions.Scale:
            if (ScalingTool.LeftCollision && IsLeftTriggerDown && ScalingTool.RightCollision && IsRightTriggerDown)
            {
                scaleMode = true;
            }

            scalingDistance = Vector3.Distance(ScaleTool1.transform.position, ScaleTool2.transform.position) - origScaleDistance;
            ProxyScale.transform.localScale = new Vector3(0.1f + scalingDistance / 10f,
                                                          0.1f + scalingDistance / 10f, 0.1f + scalingDistance / 10f);

            if (scaleMode && !IsLeftTriggerDown && !IsRightTriggerDown)
            {
                Voxel.VoxelSize = ogVoxelSize + scalingDistance / 10f;
                ogVoxelSize     = Voxel.VoxelSize;
                polygon.RecomputeChunks();
                scaleMode = false;
                ProxyScale.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                ScaleTool1.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * -0.05f +
                                                ProxyScale.transform.right * -0.05f +
                                                ProxyScale.transform.forward * 0.05f;

                ScaleTool2.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * 0.05f +
                                                ProxyScale.transform.right * 0.05f +
                                                ProxyScale.transform.forward * -0.05f;
            }
            break;

        case Functions.Translate:
            // If colliding spheres and right trigger down then move control to match tool position then move polygon by delta value
            TranslateTool.SetActive(true);
            TranslateControl.SetActive(true);
            if (TranslateTool.GetComponent <SphereTranslate>().collideWithControl)
            {
                if (IsRightTriggerDown)
                {
                    Vector3 prevPos = TranslateControl.transform.position;

                    TranslateControl.transform.position = TranslateTool.transform.position;

                    polygon.transform.position += TranslateTool.transform.position - prevPos;
                    translateMode = true;
                }
                else if (translateMode)
                {
                    TranslateControl.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.4f;
                    translateMode = false;
                }
            }

            break;

        case Functions.Colour:
        case Functions.Add:
            if (Physics.Raycast(rightRay, out RaycastHit rightHit, 0.2f, (1 << 5)))
            {
                if (rightHit.collider.gameObject.CompareTag("Button"))
                {
                    rightHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsRightTriggerDown)
                    {
                        switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Black":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(0);
                            break;

                        case "Blue":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(1);
                            break;

                        case "Green":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(2);
                            break;

                        case "Red":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(3);
                            break;

                        case "Yellow":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(4);
                            break;

                        case "Purple":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(5);
                            break;

                        case "Turquoise":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(6);
                            break;

                        case "White":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(7);
                            break;
                        }
                    }
                }

                RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, rightHit.point });
            }
            else
            {
                RightHand.GetComponent <LineRenderer>().SetPositions(new [] { Vector3.zero, Vector3.zero });
            }

            break;
        }