Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (turnTable == null)
        {
            return;
        }


        // Keypress for confused users
        if (Input.GetKeyDown("c"))
        {
            disableSpinner = !disableSpinner;
        }

        // Reset color of icons
        if (leftIcon != null)
        {
            leftIcon.GetComponent <Image>().color = standardColor;
        }

        if (rightIcon != null)
        {
            rightIcon.GetComponent <Image>().color = standardColor;
        }



        bool isDisabled = disableSpinner;

        // For each haptic device.
        for (int ii = 0; ii < hapticDevices.Length; ii++)
        {
            GameObject hapticDevice = hapticDevices [ii];
            if (hapticDevice == null)
            {
                continue;
            }
            if (hapticDevice.GetComponent <HapticPlugin>() == null)
            {
                Assert.IsNotNull(hapticDevice.GetComponent <HapticPlugin>());
                continue;
            }

            // Don't rotate if we're picking something up.
            // (This seems like it might be useful, but in practice, it's just confusing.)
            HapticGrabber grabber = hapticDevice.GetComponent <HapticPlugin>().hapticManipulator.GetComponent <HapticGrabber>();
            if (grabber != null && grabber.isGrabbing())
            {
                isDisabled = true;
            }


            // Determine the X value, relative to the screen...
            float x = 0.0f;
            x  = cam.GetComponent <Camera>().WorldToScreenPoint(hapticDevice.GetComponent <HapticPlugin>().stylusPositionWorld).x;
            x -= (Screen.width / 2.0f);

            // Determine the threshhold, relative to the screen.
            float T = (Screen.width / 2.0f) - Screen.width * threshold;


            // If the X value is greater than the threshold, rotate the "turnTable" object.
            if (Mathf.Abs(x) > T && !isDisabled)
            {
                float mag   = Mathf.Min(Mathf.Abs(x), 10 * Screen.width * threshold);
                float delta = (mag - T) * (Mathf.Abs(x) / x);
                delta /= Screen.width;

                turnTable.transform.Rotate(0, -speed * delta * Time.deltaTime, 0);

                // Light up the icon
                if (leftIcon != null && x < 0)
                {
                    leftIcon.GetComponent <Image>().color = usedColor;
                }

                if (rightIcon != null && x > 0)
                {
                    rightIcon.GetComponent <Image>().color = usedColor;
                }
            }
        }


        // If rotation is disabled, for any reason, hide the icons.
        if (leftIcon != null)
        {
            leftIcon.SetActive(!isDisabled);
        }

        if (rightIcon != null)
        {
            rightIcon.SetActive(!isDisabled);
        }
    }
Exemplo n.º 2
0
    public void SetMeshManagerMember(GameObject[] HeartPart)
    {
        for (int i = 0; i < Length; i++)
        {
            MultiMeshManager.Instance.Parts[i] = HeartPart[i].transform.GetChild(0).gameObject;
            MultiMeshManager.Instance.Parts[i].transform.localPosition = Vector3.zero;
            MultiMeshManager.Instance.Transforms[i] = MultiMeshManager.Instance.Parts[i].transform;
        }
        MultiMeshManager.Instance.MeshUpdate();

        long start = DateTime.Now.Ticks;

        float      xMin, yMin, zMin, xMax, yMax, zMax;
        BinaryTree binaryTree = new BinaryTree();

        binaryTree.copyMeshFromOriginal(MultiMeshManager.Instance.Meshes[0]);

        xMin = float.MaxValue; xMax = float.MinValue; yMin = float.MaxValue; yMax = float.MinValue; zMin = float.MaxValue; zMax = float.MinValue;
        Vector3[] savedVertices;
        int       length = MultiMeshManager.Instance.Meshes[0].vertices.Length;

        int[] triangles = MultiMeshManager.Instance.Meshes[0].triangles;
        binaryTree.root.vertices = new int[length];
        binaryTree.root.length   = length;
        binaryTree.root.faces    = new int[triangles.Length / 3];
        for (int i = 0; i < length; i++)
        {
            binaryTree.root.vertices[i] = i;
        }
        //BinaryTree.Initialize();
        savedVertices = MultiMeshManager.Instance.Meshes[0].vertices;
        for (int i = 0; i < binaryTree.root.vertices.Length; i++)
        {
            if (xMin > savedVertices[binaryTree.root.vertices[i]].x)
            {
                xMin = savedVertices[binaryTree.root.vertices[i]].x;
            }
            if (xMax < savedVertices[binaryTree.root.vertices[i]].x)
            {
                xMax = savedVertices[binaryTree.root.vertices[i]].x;
            }
            if (yMin > savedVertices[binaryTree.root.vertices[i]].y)
            {
                yMin = savedVertices[binaryTree.root.vertices[i]].y;
            }
            if (yMax < savedVertices[binaryTree.root.vertices[i]].y)
            {
                yMax = savedVertices[binaryTree.root.vertices[i]].y;
            }
            if (zMin > savedVertices[binaryTree.root.vertices[i]].z)
            {
                zMin = savedVertices[binaryTree.root.vertices[i]].z;
            }
            if (zMax < savedVertices[binaryTree.root.vertices[i]].z)
            {
                zMax = savedVertices[binaryTree.root.vertices[i]].z;
            }
        }
        binaryTree.root.maxPos.Set(xMax, yMax, zMax);
        binaryTree.root.minPos.Set(xMin, yMin, zMin);
        for (int i = 0; i < triangles.Length / 3; i++)
        {
            binaryTree.root.faces[i] = i;
        }

        /*GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
         * cube.transform.position = (binaryTree.root.minPos + binaryTree.root.maxPos) / 2;
         * cube.GetComponent<Renderer>().material.color = new Color(0.5f, 0, 0.5f, 0.1f);
         *
         * cube.transform.localScale = new Vector3(xMax - xMin, yMax - yMin, zMax - zMin);
         * cube.GetComponent<Renderer>().material.shader = Shader.Find("Transparent/Diffuse");*/


        binaryTree.root.curDepth = 1;
        binaryTree.root.index    = 0;
        BinaryTree.savedNode     = binaryTree.root;
        BinaryTree.MakeInitialChild(BinaryTree.savedNode);

        /*Mesh mesh = MultiMeshManager.Instance.Meshes[0];
         * for (int i = 0; i < binaryTree.root.vertices.Length/3; i++)
         * {
         *  //Debug.DrawLine(transform.TransformPoint(mesh.vertices[i]), transform.TransformPoint(mesh.vertices[i]) + transform.TransformVector(mesh.normals[i]));
         *
         *  Debug.Log(i.ToString() + "번째 normal : " + mesh.normals[i]);
         *  GameObject a = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         *  a.transform.position = transform.TransformPoint(mesh.vertices[i]) + mesh.normals[i];
         *  a.transform.localScale = Vector3.one * 0.05f;
         *  a.name = "normal" + i.ToString();
         * }*/

        long end = DateTime.Now.Ticks;

        Debug.Log("ImportMesh tick timer: " + (double)(end - start) / 10000000.0f);
        HapticGrabber.meshChecker();
    }