Ejemplo n.º 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;
 }
Ejemplo n.º 2
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 = ButtonType.ToString();
     data.deviceName = ButtonName.ToString();
     VRPNEventManager.StartListeningButton(ButtonType, ButtonName, Record);
     isRecording = true;
 }
Ejemplo n.º 3
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 = AnalogType.ToString();
     data.deviceName = AnalogName.ToString();
     VRPNEventManager.StartListeningAnalog(AnalogType, AnalogName, Record);
     isRecording = true;
 }
Ejemplo n.º 4
0
 //Initialize VRPNEventManager in Awake
 void Awake()
 {
     //init VRPNEventManager
     #pragma warning disable 0219
     VRPNEventManager getInstance = VRPNEventManager.instance;
     #pragma warning restore 0219
 }
Ejemplo n.º 5
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;
        }
    }
Ejemplo n.º 6
0
 //Auxiliar method that sends last frame report
 private void sendingReport(VRPNAnalog.AnalogReportNew lastReport)
 {
     VRPNAnalog.AnalogReport newReport  = new VRPNAnalog.AnalogReport();
     VRPNManager.TimeVal     newMsgTime = new VRPNManager.TimeVal();
     newMsgTime.tv_sec     = (UInt32)lastReport.msg_time.tv_sec;
     newMsgTime.tv_usec    = (UInt32)lastReport.msg_time.tv_usec;
     newReport.msg_time    = newMsgTime;
     newReport.num_channel = lastReport.num_channel;
     newReport.channel     = lastReport.channel;
     VRPNEventManager.TriggerEventAnalog(data.deviceType, data.deviceName, newReport);
 }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        // Ensure device is ready
        if (!initialized && !StartAnalog())
        {
            return;
        }

        // Check for new reports and process
        if (VRPNAnalogNumReports(AnalogName.ToString()) > 0)
        {
            // Get Reports
            int num = MaxReports;
            VRPNAnalogReports(AnalogName.ToString(), reportsPtr, ref num, LastReport, purgeReports);
            AnalogReport[] reports = new AnalogReport[num];

            // Process Reports
            int    i;
            string reportString = AnalogName.ToString();
            string messageString;
            for (i = 0; i < num; i++)
            {
                reports[i] = (AnalogReport)Marshal.PtrToStructure(reportsPtr[i], typeof(AnalogReport));
                if (i == num - 1)
                {
                    //Trigger analog sensor event in event manager
                    //Only the last one is send, one for frame
                    VRPNEventManager.TriggerEventAnalog(AnalogType.ToString(), AnalogName.ToString(), reports[i]);
                }
                messageString = "<";
                for (int j = 0; j < reports[i].num_channel; j++)
                {
                    messageString += " " + reports[i].channel[j] + ",";
                }
                messageString += ">" + " @ " + reports[i].msg_time.tv_sec + "." + reports[i].msg_time.tv_usec;
                if (ShowDebug)
                {
                    reportString += "/n" + messageString;
                }
            }

            if (ShowDebug)
            {
                debug_text = reportString;
            }

            // Only need time value of most recent report
            if (num > 0 && useLastReportTime)
            {
                LastReport.tv_sec  = reports[num - 1].msg_time.tv_sec;
                LastReport.tv_usec = reports[num - 1].msg_time.tv_usec;
            }
        }
    }
Ejemplo n.º 8
0
    //Public method that allows to stop recording
    //It saves the reports list in the indicated path
    public void StopRecording()
    {
        VRPNEventManager.StopListeningTracker(TrackerType, TrackerName, Record);
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(path);

        bf.Serialize(file, data);
        file.Close();
        data        = new VRPNTracker.TrackerReports();
        firstReport = true;
        isRecording = false;
    }
Ejemplo n.º 9
0
 //Auxiliar method that sends last frame report for each button
 private void sendingReports(Dictionary <int, VRPNButton.ButtonReportNew> lastReports)
 {
     foreach (KeyValuePair <int, VRPNButton.ButtonReportNew> pair in lastReports)
     {
         VRPNButton.ButtonReport newReport  = new VRPNButton.ButtonReport();
         VRPNManager.TimeVal     newMsgTime = new VRPNManager.TimeVal();
         newMsgTime.tv_sec  = (UInt32)pair.Value.msg_time.tv_sec;
         newMsgTime.tv_usec = (UInt32)pair.Value.msg_time.tv_usec;
         newReport.msg_time = newMsgTime;
         newReport.button   = pair.Value.button;
         newReport.state    = pair.Value.state;
         VRPNEventManager.TriggerEventButton(data.deviceType, data.deviceName, newReport);
     }
 }
Ejemplo n.º 10
0
 //Auxiliar method that sends last frame report for each sensor
 private void sendingReports(Dictionary <int, VRPNTracker.TrackerReportNew> lastReports)
 {
     foreach (KeyValuePair <int, VRPNTracker.TrackerReportNew> pair in lastReports)
     {
         VRPNTracker.TrackerReport newReport  = new VRPNTracker.TrackerReport();
         VRPNManager.TimeVal       newMsgTime = new VRPNManager.TimeVal();
         newMsgTime.tv_sec  = (UInt32)pair.Value.msg_time.tv_sec;
         newMsgTime.tv_usec = (UInt32)pair.Value.msg_time.tv_usec;
         newReport.msg_time = newMsgTime;
         newReport.pos      = pair.Value.pos;
         newReport.quat     = pair.Value.quat;
         newReport.sensor   = pair.Value.sensor;
         VRPNEventManager.TriggerEventTracker(data.deviceType, data.deviceName, newReport);
     }
 }
Ejemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        // Ensure device is ready
        if (!initialized && !StartButton())
        {
            return;
        }

        // Check for new reports and process
        if (VRPNButtonNumReports(ButtonName.ToString()) > 0)
        {
            // Get Reports
            int num = MaxReports;
            VRPNButtonReports(ButtonName.ToString(), reportsPtr, ref num, LastReport, ButtonNumber, purgeReports);
            ButtonReport[] reports = new ButtonReport[num];

            // Process Reports
            int    i;
            string reportString = ButtonName.ToString();
            for (i = 0; i < num; i++)
            {
                reports[i] = (ButtonReport)Marshal.PtrToStructure(reportsPtr[i], typeof(ButtonReport));
                //Trigger button event in event manager
                VRPNEventManager.TriggerEventButton(ButtonType.ToString(), ButtonName.ToString(), reports[i]);
                if (ShowDebug)
                {
                    reportString += "\n " + reports[i].button + "->" + reports[i].state + " @ " + reports[i].msg_time.tv_sec + "." + reports[i].msg_time.tv_usec;
                }
            }

            if (ShowDebug)
            {
                debug_text = reportString;
            }

            // Only need time value of most recent report
            if (num > 0 && useLastReportTime)
            {
                LastReport.tv_sec  = reports[num - 1].msg_time.tv_sec;
                LastReport.tv_usec = reports[num - 1].msg_time.tv_usec;
            }
        }
    }