Ejemplo n.º 1
0
        void OnVREvent(VREvent e)
        {
            // only respond to tracker move events
            if ((e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "TrackerMove"))
            {
                string trackerName = e.Name.Remove(e.Name.IndexOf("_Move"), 5);
                if (!trackersToIgnore.Contains(trackerName))
                {
                    float[]    data = e.GetFloatArrayData("Transform");
                    Matrix4x4  m    = VRConvert.ToMatrix4x4(data);
                    Vector3    pos  = m.GetTranslation();
                    Quaternion rot  = m.GetRotation();

                    if (!cursors.ContainsKey(trackerName))
                    {
                        GameObject newCursorObj = Instantiate(cursorPrefab);
                        TextMesh   label        = newCursorObj.GetComponentInChildren <TextMesh>();
                        if (label != null)
                        {
                            label.text = trackerName;
                        }
                        cursors[trackerName] = newCursorObj;
                    }
                    GameObject cursorObj = cursors[trackerName];
                    cursorObj.transform.position = pos;
                    cursorObj.transform.rotation = rot;
                }
            }
        }
Ejemplo n.º 2
0
    // Called whenever an ImageUpdate event is received via MinVR
    void OnImageUpdate(MinVR.VREvent e)
    {
        // access the image data buffer from the event
        float[] buffer = e.GetFloatArrayData("Buffer");

        // copy data into an array of colors
        int w = 100;
        int h = 100;

        Color[] colors = new Color[w * h];
        int     bindex = 0;
        int     cindex = 0;

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                colors[cindex] = new Color(buffer[bindex + 0], buffer[bindex + 1], buffer[bindex + 2], 1.0f);
                cindex++;
                bindex += 3;
            }
        }

        tex.SetPixels(colors);
        tex.Apply();

        // connect texture to material of GameObject this script is attached to
        GetComponent <Renderer>().material.mainTexture = tex;
    }
Ejemplo n.º 3
0
        private void ProcessCallbacks(VREvent e)
        {
            // These "unfiltered" callbacks are called for every event
            for (int ucb = 0; ucb < genericCallbacksUnfiltered.Count; ucb++)
            {
                genericCallbacksUnfiltered[ucb].Invoke(e);
            }


            // These callbacks are passed the enitre event data structure, which can really contain anything.
            if (genericCallbacks.ContainsKey(e.Name))
            {
                for (int cb = 0; cb < genericCallbacks[e.Name].Count; cb++)
                {
                    genericCallbacks[e.Name][cb].Invoke(e);
                }
            }


            // For these callbacks, we know the type of data, so we pull it out of the dataindex here to
            // make it a bit easier for the user.

            if ((analogCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "AnalogUpdate"))
            {
                for (int cb = 0; cb < analogCallbacks[e.Name].Count; cb++)
                {
                    analogCallbacks[e.Name][cb].Invoke(e.GetFloatData("AnalogValue"));
                }
            }

            if ((buttonDownCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                ((e.GetStringData("EventType") == "ButtonDown") || (e.GetStringData("EventType") == "ButtonTouch")))
            {
                for (int cb = 0; cb < buttonDownCallbacks[e.Name].Count; cb++)
                {
                    buttonDownCallbacks[e.Name][cb].Invoke();
                }
            }

            if ((buttonUpCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                ((e.GetStringData("EventType") == "ButtonUp") || (e.GetStringData("EventType") == "ButtonUntouch")))
            {
                for (int cb = 0; cb < buttonUpCallbacks[e.Name].Count; cb++)
                {
                    buttonUpCallbacks[e.Name][cb].Invoke();
                }
            }

            if ((cursorCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "CursorMove"))
            {
                float[] pos  = e.GetFloatArrayData("Position");
                float[] npos = e.GetFloatArrayData("NormalizedPosition");
                for (int cb = 0; cb < cursorCallbacks[e.Name].Count; cb++)
                {
                    cursorCallbacks[e.Name][cb].Invoke(new Vector3(pos[0], pos[1], pos[2]), new Vector3(npos[0], npos[1], npos[2]));
                }
            }

            if ((trackerCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "TrackerMove"))
            {
                float[]    data = e.GetFloatArrayData("Transform");
                Matrix4x4  m    = VRConvert.ToMatrix4x4(data);
                Vector3    pos  = m.GetTranslation();
                Quaternion rot  = m.GetRotation();
                for (int cb = 0; cb < trackerCallbacks[e.Name].Count; cb++)
                {
                    trackerCallbacks[e.Name][cb].Invoke(pos, rot);
                }
            }
        }