Exemplo n.º 1
0
 //This is the listener that is called by the event manager
 //It transforms and adds the received report to the reports list
 void Record(string name, VRPNTracker.TrackerReport report)
 {
     if (firstReport)
     {
         firstTime_sec = report.msg_time.tv_sec;
         firstTime_usec = report.msg_time.tv_usec;
         firstReport = false;
     }
     if (report.msg_time.tv_usec < firstTime_usec)
     {
         report.msg_time.tv_sec = report.msg_time.tv_sec - (firstTime_sec + 1);
         report.msg_time.tv_usec = (report.msg_time.tv_usec + 1000000) - firstTime_usec;
     }
     else
     {
         report.msg_time.tv_sec = report.msg_time.tv_sec - firstTime_sec;
         report.msg_time.tv_usec = report.msg_time.tv_usec - firstTime_usec;
     }
     VRPNTracker.TrackerReportNew newReport = new VRPNTracker.TrackerReportNew();
     VRPNManager.TimeValNew newMsgTime = new VRPNManager.TimeValNew();
     newMsgTime.tv_sec = (int)report.msg_time.tv_sec;
     newMsgTime.tv_usec = (int)report.msg_time.tv_usec;
     newReport.msg_time = newMsgTime;
     newReport.pos = report.pos;
     newReport.quat = report.quat;
     newReport.sensor = report.sensor;
     data.list.Add(newReport);
 }
Exemplo n.º 2
0
    void CreateBodyWithoutRD()
    {
        // Assuming 58 sensors for a body, without reference
        GameObject[] objs = new GameObject[59];
        GameObject   prev;

        // sensor 0 comes in ref...
        for (int i = 0; i < 59; i++)
        {
            objs[i]      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            objs[i].name = ((Neuron.NeuronBones)i).ToString();
            objs[i].transform.position   = displ[i];
            objs[i].transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
            VRPNTracker tr = objs[i].AddComponent <VRPNTracker>();
            tr.tracker = tracker;
            tr.server  = server;
            tr.sensor  = i;
            if (i == (int)Neuron.NeuronBones.RightUpLeg || i == (int)Neuron.NeuronBones.LeftUpLeg || i == (int)Neuron.NeuronBones.Spine)
            {
                prev = objs[(int)Neuron.NeuronBones.Hips];
            }
            else if (i == (int)Neuron.NeuronBones.RightShoulder || i == (int)Neuron.NeuronBones.LeftShoulder)
            {
                prev = objs[(int)Neuron.NeuronBones.Spine3];
            }
            else if (i == (int)Neuron.NeuronBones.RightHandThumb1 || i == (int)Neuron.NeuronBones.RightInHandIndex ||
                     i == (int)Neuron.NeuronBones.RightInHandMiddle || i == (int)Neuron.NeuronBones.RightInHandRing || i == (int)Neuron.NeuronBones.RightInHandPinky)
            {
                prev = objs[(int)Neuron.NeuronBones.RightHand];
            }
            else if (i == (int)Neuron.NeuronBones.LeftHandThumb1 || i == (int)Neuron.NeuronBones.LeftInHandIndex ||
                     i == (int)Neuron.NeuronBones.LeftInHandMiddle || i == (int)Neuron.NeuronBones.LeftInHandRing || i == (int)Neuron.NeuronBones.LeftInHandPinky)
            {
                prev = objs[(int)Neuron.NeuronBones.LeftHand];
            }
            else
            {
                if (i != 0)
                {
                    prev = objs[i - 1];
                }
                else
                {
                    prev = refCube;
                }
            }

            //            if( !(i>= (int)Neuron.NeuronBones.Head && i<= (int)Neuron.NeuronBones.Spine3) )
            //            {
            objs[i].transform.parent = prev.transform;
            //            }
        }
        objs[(int)Neuron.NeuronBones.Hips].transform.parent = objs[0].transform;
        //        objs[(int)Neuron.NeuronBones.Spine].transform.parent = objs[(int)Neuron.NeuronBones.Hips].transform;
    }
Exemplo n.º 3
0
 // Adds Trackers and TransfromDisplays to new GameObjects
 private void SetUpDisplayTrackers()
 {
     foreach (var displayTracker in displayTrackerConfigs)
     {
         GameObject  gameObject = new GameObject(displayTracker.tracker.id + ", " + displayTracker.display.id);
         VRPNTracker tracker    = gameObject.AddComponent <VRPNTracker>();
         tracker.trackerID = displayTracker.tracker.id;
         TransformDisplay display = gameObject.AddComponent <TransformDisplay>();
         display.displayIDs = new List <string>(1)
         {
             displayTracker.display.id
         };
     }
 }
    protected override void Awake()
    {
        if (_ConnectionType == ConnectionTypes.DirectConnection)
        {
            _tracker              = gameObject.AddComponent <VRPNTracker>();
            _tracker.TrackerName  = _VRPNSettings.ServerName;
            _tracker.TrackerType  = VRPNManager.Tracker_Types.vrpn_Tracker_Liberty;
            _tracker.SensorNumber = _VRPNSettings.Sensor;
        }
        if (_manager == null)
        {
            _manager = gameObject.AddComponent <VRPNManager>();
            _manager.ServerAddress = _VRPNSettings.ServerIPAdress;
        }
        _managerIndex++;

        base.Awake();
    }
Exemplo n.º 5
0
    /// <summary>
    /// Creates Trackers and Transform displays automatically.
    /// </summary>
    private void CreateTrackerToDisplays()
    {
        // For creating the trackers
        var trackerToDisplays = new Dictionary <string, TransformOffAxis>();

        // Check every display for a tracker
        foreach (JSONNode displayJSON in platformJSON["displays"].AsArray)
        {
            JSONNode trackerJSON = displayJSON["tracker"];

            if (trackerJSON != null)
            {
                // Get the ids
                string trackerID = trackerJSON.Value;
                string displayID = displayJSON["id"];

                // If the tracker already exists
                if (trackerToDisplays.ContainsKey(trackerID))
                {
                    trackerToDisplays[trackerID].displayIDs.Add(displayID);
                }
                else
                {
                    // Create the tracking object
                    GameObject trackedObject = new GameObject(displayID + "-TransformDisplay");

                    // Set up the tracker
                    VRPNTracker tracker = trackedObject.AddComponent <VRPNTracker>();
                    tracker.trackerID = trackerID;

                    // Set up the display
                    var transformDisplay = trackedObject.AddComponent <TransformOffAxis>();
                    transformDisplay.displayIDs = new List <string>()
                    {
                        displayID
                    };

                    // Add it to the dictionary
                    trackerToDisplays.Add(trackerID, transformDisplay);
                }
            }
        }
    }
Exemplo n.º 6
0
    //VRPNTrackerRecording Constructor
    public VRPNTrackerRecording(string nName, float nTime, VRPNTracker.TrackerReports nData)
    {
        name = nName;
        reportTime = nTime;
        data = nData;

        e = data.list.GetEnumerator();

        while (e.MoveNext())
        {
            VRPNTracker.TrackerReportNew report = e.Current;
            int test;
            if (!sensors.TryGetValue(report.sensor, out test))
            {
                sensors.Add(report.sensor, report.sensor);
            }
            lastTime = report.msg_time.tv_sec + (report.msg_time.tv_usec / 1000000f);
        }

        e = data.list.GetEnumerator();
    }
 void Start()
 {
     index = global_count;
     global_count++;
     global_index    = global_count;
     state_string    = new string[4];
     state_string[0] = "fov";
     state_string[1] = "rotate";
     state_string[2] = "xy";
     state_string[3] = "xz";
     tracker         = (VRPNTracker)GetComponent(typeof(VRPNTracker));
     sensorPosition  = tracker.SensorOffset.localPosition;
     sensorRotation  = tracker.SensorOffset.localRotation;
     if (Camera.main == null)
     {
         Debug.Log("No camera found");
     }
     else
     {
         fieldOfView = Camera.main.fieldOfView;
         Component planeRender = GetComponentInChildren(typeof(Renderer));
         if (planeRender != null)
         {
             plane = planeRender.gameObject.transform;
         }
     }
     if (tracker == null)
     {
         Debug.Log("No tracker found");
     }
     else
     {
         savedApply = tracker.ApplyTracking;
         savedDebug = tracker.ShowDebug;
     }
 }
Exemplo n.º 8
0
    //Método que se encarga de estar pendiente de los mensajes (posición y orientación) que se envían desde el tracker del dispositivo
    void CambioEnUnTracker(string name, VRPNTracker.TrackerReport report)
    {
        //Info para el Log
        if (estaMostrandoInfoTracker)
        {
            string text;
            text = "Name: " + name + " Sensor: " + report.sensor;
            for (int i = 0; i < report.pos.Length; i++)
            {
                text = text + " Pos " + i + ": " + report.pos[i];
            }
            for (int i = 0; i < report.quat.Length; i++)
            {
                text = text + " Quat " + i + ": " + report.quat[i];
            }
            Debug.Log(text);
        }

        //Si el control que se está revisando es el izquierdo
        if (sensor == 0 && report.sensor == 0)
        {
            //Posición: Notar que 'y' y 'z' se encuentran intercambiados
            this.transform.position = new Vector3((float)report.pos[0] * 10, (float)report.pos[2] * 10, (float)report.pos[1] * 10);
            //Rotación: Notar que es un cuaternión y no ángulos de euler, y que nuevamente 'y' y 'z' se encuentran intercambiados, además que 'x', 'y', y 'z' se encuentran invertidos
            this.transform.localRotation = new Quaternion(-1 * (float)report.quat[0], -1 * (float)report.quat[2], -1 * (float)report.quat[1], (float)report.quat[3]);
        }
        //Si el control que se está revisando es el derecho
        else if (sensor == 1 && report.sensor == 1)
        {
            //Posición: Notar que 'y' y 'z' se encuentran intercambiados
            this.transform.position = new Vector3((float)report.pos[0] * 10, (float)report.pos[2] * 10, (float)report.pos[1] * 10);
            //Rotación: Notar que es un cuaternión y no ángulos de euler, y que nuevamente 'y' y 'z' se encuentran intercambiados, además que 'x', 'y', y 'z' se encuentran invertidos
            this.transform.localRotation = new Quaternion(-1 * (float)report.quat[0], -1 * (float)report.quat[2], -1 * (float)report.quat[1], (float)report.quat[3]);
        }
    }
    //Método que se encarga de estar pendiente de los mensajes (posición y orientación) que se envían desde el tracker del dispositivo
    void trackerUpdate(string name, VRPNTracker.TrackerReport report)
    {
        //if (sensor == 0 && report.sensor == 0 || sensor == 1 && report.sensor == 1)
        if (sensor == 0 && report.sensor == 0 || sensor == 1 && report.sensor == 1)
        {

            //Posición: Notar que 'y' y 'z' se encuentran intercambiados
            //this.transform.position = new Vector3((float)report.pos[0] * 10, (float)report.pos[2] * 10, (float)report.pos[1] * 10);
            //Rotación: Notar que es un cuaternión y no ángulos de euler, y que nuevamente 'y' y 'z' se encuentran intercambiados, además que 'x', 'y', y 'z' se encuentran invertidos
            this.transform.localRotation = new Quaternion(-1 * (float)report.quat[0], -1 * (float)report.quat[2], -1 * (float)report.quat[1], (float)report.quat[3]);
            currentRotation = new Quaternion(-1 * (float)report.quat[0], -1 * (float)report.quat[2], -1 * (float)report.quat[1], (float)report.quat[3]);
        }
    }
Exemplo n.º 10
0
    void Start () {
    	index = global_count;
    	global_count++;
    	global_index = global_count;
    	state_string = new string[4];
    	state_string[0] = "fov";
    	state_string[1] = "rotate";
    	state_string[2] = "xy";
    	state_string[3] = "xz";
		tracker = (VRPNTracker)GetComponent(typeof(VRPNTracker));
    	sensorPosition = tracker.SensorOffset.localPosition;
    	sensorRotation = tracker.SensorOffset.localRotation;
    	if (Camera.main == null)
    		Debug.Log("No camera found");
    	else
    	{
    		fieldOfView = Camera.main.fieldOfView;
    		Component planeRender = GetComponentInChildren(typeof(Renderer));
    		if (planeRender != null)
    			plane = planeRender.gameObject.transform;
    	}
    	if (tracker == null)
    		Debug.Log("No tracker found");
    	else
    		{
    		savedApply = tracker.ApplyTracking;
    		savedDebug = tracker.ShowDebug;
    		}
    }
Exemplo n.º 11
0
    void CreateTrackers()
    {
        // Assuming sensors for a body, not including a reference
        if (takeHipsDisplacement)
        {
            objs = new GameObject[(int)NeuronBones.NumOfBones + 1];
        }
        else
        {
            objs = new GameObject[(int)NeuronBones.NumOfBones];
        }
        GameObject prev;

        for (int i = 0; i < (int)NeuronBones.NumOfBones; i++)
        {
            objs[i]      = new GameObject();
            objs[i].name = ((NeuronBones)i).ToString();
            VRPNTracker tr = objs[i].AddComponent <VRPNTracker>();
            tr.tracker = tracker;
            tr.server  = server;
            if (secondSuit)
            {
                tr.sensor = i + 60;
            }
            else
            {
                tr.sensor = i;
            }
            // Me parece que no es necesario, porque el esqueleto debe tener la jerarquia...

            /*
             * if (i == (int)BoneNames.RightUpLeg || i == (int)BoneNames.LeftUpLeg || i == (int)BoneNames.Spine)
             * {
             *  prev = objs[(int)BoneNames.Hips];
             * }
             * else if (i == (int)BoneNames.RightShoulder || i == (int)BoneNames.LeftShoulder)
             * {
             *  prev = objs[(int)BoneNames.Spine3];
             * }
             * else if (i == (int)BoneNames.RightHandThumb1 || i == (int)BoneNames.RightInHandIndex ||
             *  i == (int)BoneNames.RightInHandMiddle || i == (int)BoneNames.RightInHandRing || i == (int)BoneNames.RightInHandPinky)
             * {
             *  prev = objs[(int)BoneNames.RightHand];
             * }
             * else if (i == (int)BoneNames.LeftHandThumb1 || i == (int)BoneNames.LeftInHandIndex ||
             *  i == (int)BoneNames.LeftInHandMiddle || i == (int)BoneNames.LeftInHandRing || i == (int)BoneNames.LeftInHandPinky)
             * {
             *  prev = objs[(int)BoneNames.LeftHand];
             * }
             * else
             * {
             *  if (i != 0)
             *      prev = objs[i - 1];
             *  else
             *      prev = gameObject;
             * }
             *
             * objs[i].transform.parent = prev.transform;
             */
        }
        if (takeHipsDisplacement)
        {
            objs[(int)NeuronBones.NumOfBones]      = new GameObject();
            objs[(int)NeuronBones.NumOfBones].name = "HipsDisplacement";
            VRPNTracker tr = objs[(int)NeuronBones.NumOfBones].AddComponent <VRPNTracker>();
            tr.tracker = tracker;
            tr.server  = server;
            tr.sensor  = (int)NeuronBones.NumOfBones; // Assuming 59
        }
    }