Exemple #1
0
 //Public method that allows to start recording in the indicated path
 //It registers the listener method in the event manager
 public void StartRecording()
 {
     data.deviceType = TrackerType.ToString();
     data.deviceName = TrackerName.ToString();
     VRPNEventManager.StartListeningTracker(TrackerType, TrackerName, Record);
     isRecording = true;
 }
Exemple #2
0
    void GetAveragePosQuat()
    {
        int num = MaxReports;

        VRPNTrackerPosReports(TrackerName.ToString(), repsPtr, ref num);
        float[] repsSum   = new float[7];
        int     repsCount = 0;

        TrackerReport[] reps = new TrackerReport[num];
        Dictionary <int, VRPNTracker.TrackerReport> lastReports = new Dictionary <int, VRPNTracker.TrackerReport>();

        for (int i = 0; i < num; i++)
        {
            reps[i] = (TrackerReport)Marshal.PtrToStructure(repsPtr[i], typeof(TrackerReport));
            if (reps[i].sensor == SensorNumber && VRPNManager.TimeValGreater(ref reps[i].msg_time, ref LastReport))
            {
                repsSum[0]        += (float)reps[i].pos[0];
                repsSum[1]        += (float)reps[i].pos[1];
                repsSum[2]        += (float)reps[i].pos[2];
                repsSum[3]        += (float)reps[i].quat[2];
                repsSum[4]        += -(float)reps[i].quat[1];
                repsSum[5]        += (float)reps[i].quat[0];
                repsSum[6]        += (float)reps[i].quat[3];
                LastReport.tv_sec  = reps[i].msg_time.tv_sec;
                LastReport.tv_usec = reps[i].msg_time.tv_usec;
                repsCount++;
            }
            VRPNTracker.TrackerReport test;
            if (lastReports.TryGetValue(reps[i].sensor, out test))
            {
                lastReports[reps[i].sensor] = reps[i];
            }
            else
            {
                lastReports.Add(reps[i].sensor, reps[i]);
            }
        }
        foreach (KeyValuePair <int, VRPNTracker.TrackerReport> pair in lastReports)
        {
            //Trigger tracker event in event manager
            VRPNEventManager.TriggerEventTracker(TrackerType.ToString(), TrackerName.ToString(), pair.Value);
        }
        if (repsCount > 0)
        {
            trackerPos.x  = repsSum[0] / (float)repsCount;
            trackerPos.y  = repsSum[1] / (float)repsCount;
            trackerPos.z  = repsSum[2] / (float)repsCount;
            trackerQuat.x = repsSum[3] / (float)repsCount;
            trackerQuat.y = repsSum[4] / (float)repsCount;
            trackerQuat.z = repsSum[5] / (float)repsCount;
            trackerQuat.w = repsSum[6] / (float)repsCount;
        }
        else
        {
            trackerPos  = lastPos;
            trackerQuat = lastQuat;
        }
    }
Exemple #3
0
    //To add a listener for Trackers
    public static void StartListeningTracker(VRPNManager.Tracker_Types deviceType, VRPNDeviceConfig.Device_Names deviceName, UnityAction <string, VRPNTracker.TrackerReport> listener)
    {
        if (eventManager == null)
        {
            Debug.LogError("There needs to be one active EventManger script on a GameObject in your scene.");
            return;
        }
        VRPNTrackerEvent thisEvent = null;

        if (instance.eventDictionaryTracker.TryGetValue(deviceType.ToString() + " " + deviceName.ToString(), out thisEvent))
        {
            thisEvent.AddListener(listener);
        }
        else
        {
            thisEvent = new VRPNTrackerEvent();
            thisEvent.AddListener(listener);
            instance.eventDictionaryTracker.Add(deviceType.ToString() + " " + deviceName.ToString(), thisEvent);
        }
    }