Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        //Defaults the UI to be Invisible
        UIright.SetActive(false);
        UIleft.SetActive(false);
        //Server Manager Object
        cbm = new ClientBTManager();
        //Packets
        cbm.PacketReceived += Recieved;
        //connected
        cbm.Connected += OnConnect;
        cbm.Initialize();

        mainCamera = Camera.main;
        //gives indexed for each index
        points = new Vector3[9];
        objs   = new GameObject[9];

        left  = new Hand();
        right = new Hand();

        //fills each vector array
        for (int i = 0; i < 9; i++)
        {
            //creates a sphere
            objs[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            //size of the object
            objs[i].transform.localScale = new Vector3(0.02f, 0.02f, 0.02f);
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < 9; i++)
        {
            Vector3 p = leapOffset + rotation * points[i];
            objs[i].transform.position = ToUnityCoords(points[i]);//mainCamera.transform.position + mainCamera.transform.rotation * p;
        }

        left.palmPos  = ToUnityCoords(points[0]);
        left.palmNorm = ToUnityCoordsDir(points[1]);

        right.palmPos  = ToUnityCoords(points[2]);
        right.palmNorm = ToUnityCoordsDir(points[3]);

        //finds angle for area that the UI for the left hand will be visible
        //Debug.Log(Vector3.Angle(left.palmNorm, -mainCamera.transform.forward));
        if (Vector3.Angle(left.palmNorm, -mainCamera.transform.forward) < 30.0f)
        {
            //sets the UI as visible when the parameters are met
            UIleft.transform.position = left.palmPos;
            Vector3 dir = (left.palmPos - mainCamera.transform.position).normalized;
            UIleft.transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
            UIleft.SetActive(true);
        }
        else
        {
            //sets Sthe UI as invisible when the parameters are met
            UIleft.SetActive(false);
        }

        //finds angle for the area that the UI for the right hand will be visible
        if (Vector3.Angle(right.palmNorm, -mainCamera.transform.forward) < 30.0f)
        {
            //sets the UI as visible when the parameters are met
            UIright.transform.position = right.palmPos;
            Vector3 dir = (right.palmPos - mainCamera.transform.position).normalized;
            UIright.transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
            UIright.SetActive(true);
        }
        else
        {
            //sets the UI as invisible when the parameters are met
            UIright.SetActive(false);
        }
    }