예제 #1
0
    TrackerReport MarshalPtrToTrackerReport(IntPtr ptr)
    {
        int[]         intVals   = new int[2];
        float[]       floatVals = new float[8];
        TrackerReport result    = new TrackerReport();

        Marshal.Copy(ptr, intVals, 0, 2);
        Marshal.Copy((IntPtr)((int)ptr + 8), floatVals, 0, 8);
        result.id     = intVals[0];
        result.type   = intVals[1];
        result.pos.x  = floatVals[0];
        result.pos.y  = floatVals[1];
        result.pos.z  = floatVals[2];
        result.quat.x = floatVals[3];
        result.quat.y = floatVals[4];
        result.quat.z = floatVals[5];
        result.quat.w = floatVals[6];
        result.conf   = floatVals[7];
        Marshal.Copy((IntPtr)((int)ptr + 40), floatVals, 0, 8);
        result.corner0.x = floatVals[0];
        result.corner0.y = floatVals[1];
        result.corner1.x = floatVals[2];
        result.corner1.y = floatVals[3];
        result.corner2.x = floatVals[4];
        result.corner2.y = floatVals[5];
        result.corner3.x = floatVals[6];
        result.corner3.y = floatVals[7];
        result.area      = Marshal.ReadInt32((IntPtr)((int)ptr + 72));
        result.data      = Marshal.ReadIntPtr((IntPtr)((int)ptr + 76));
        return(result);
    }
예제 #2
0
    void Start()
    {
        //allocate unmanaged memory for tracker reports
        repsPtr = new IntPtr[MaxReports];
        TrackerReport report = new TrackerReport();

        report.sensor  = 0;
        report.pos     = new double[3];
        report.quat    = new double[4];
        report.quat[3] = 1.0f;
        for (int i = 0; i < MaxReports; i++)
        {
            repsPtr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TrackerReport)));
            Marshal.StructureToPtr(report, repsPtr[i], true);
        }
        if (DeviceToUnity == null || SensorOffset == null)
        {
            if (DeviceToUnity == null)
            {
                Console.WriteLine("Warning: DeviceToUnity field not referencing a transform");
            }
            if (SensorOffset == null)
            {
                Console.WriteLine("Warning: SensorOffset field not referencing a transform");
            }
        }

        // Setup last report time memory
        LastReport = new VRPNManager.TimeVal();
    }
예제 #3
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;
        }
    }
예제 #4
0
    void Awake()
    {
        //allocate unmanaged memory for tracker reports
        repsPtr = new IntPtr[MaxReports];
        TrackerReport report = new TrackerReport();

        report.pos     = new Vector3();
        report.quat    = new Quaternion();
        report.corner0 = new Vector2();
        report.corner1 = new Vector2();
        report.corner2 = new Vector2();
        report.corner3 = new Vector2();
        report.conf    = 0.0f;
        report.area    = 0;
        for (int i = 0; i < MaxReports; i++)
        {
            repsPtr[i]  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TrackerReport)));
            report.data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * 256);
            Marshal.WriteIntPtr((IntPtr)((int)repsPtr[i] + 76), report.data);
            //Marshal.StructureToPtr(report, repsPtr[i], true); not working in .NET 1.1
        }
        int config_flags = 0;

        for (int i = 0; i < options.Length; i++)
        {
            config_flags |= (int)options[i];
        }
        foreach (TrackerMarker marker in FindObjectsOfType(typeof(TrackerMarker)))
        {
            if (marker.enabled)
            {
                config_flags |= marker.Config();
            }
        }
        string filepath = Plugins.CreateFileFromAsset(CalibrationFile);

        TRACKER_createTracker(filepath, config_flags, ref handle);
        if (handle >= 0)
        {
            if (Threshold > 0)
            {
                TRACKER_setThreshold(handle, Threshold);
            }
            if (ShowDebug)
            {
                        #if !UNITY_IPHONE
                debug_text   = new string[debug_buffer_max];
                debug_writer = new StringWriter();
                Console.SetOut(debug_writer);
                        #endif
                Console.WriteLine("Tracker Initialized");
            }
        }
        debug_flag = ShowDebug;
    }
예제 #5
0
    void GetAveragePosQuat()
    {
        int num = MaxReports;

        VRPNTrackerPosReports(TrackerName, repsPtr, ref num);


        float[] repsSum   = new float[7];
        int     repsCount = 0;

        TrackerReport[] reps = new TrackerReport[num];
        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++;
            }
        }
        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;


            if (trackerPos != Vector3.zero || trackerQuat != Quaternion.identity)
            {
                _lastReportTime = Time.unscaledTime;
            }
        }
        else
        {
            trackerPos  = lastPos;
            trackerQuat = lastQuat;
        }
    }
예제 #6
0
    void GetLatestPosQuat()
    {
        VRPNTrackerPosReport(TrackerName.ToString(), repsPtr[0], IntPtr.Zero, SensorNumber);
        TrackerReport rep = (TrackerReport)Marshal.PtrToStructure(repsPtr[0], typeof(TrackerReport));

        trackerPos.x       = (float)rep.pos[0];
        trackerPos.y       = (float)rep.pos[1];
        trackerPos.z       = (float)rep.pos[2];
        trackerQuat.x      = (float)rep.quat[2];
        trackerQuat.y      = -(float)rep.quat[1];
        trackerQuat.z      = (float)rep.quat[0];
        trackerQuat.w      = (float)rep.quat[3];
        LastReport.tv_sec  = rep.msg_time.tv_sec;
        LastReport.tv_usec = rep.msg_time.tv_usec;
    }
예제 #7
0
    void UpdateMarkers()
    {
        foreach (DictionaryEntry marker in markers)
        {
            ((TrackerMarker)marker.Value).visible = false;
        }
        int          num    = MaxReports;
        Pixel_Format format = Pixel_Format.PIXEL_FORMAT_RGB;

        if (CameraNode.m_depth == 32 && CameraNode.m_pixelFormat == 32993)
        {
            format = Pixel_Format.PIXEL_FORMAT_BGRA;
        }
        TRACKER_getReports(handle, CameraNode.m_vidpointer_byte, CameraNode.m_width, CameraNode.m_height, (int)format, repsPtr, ref num);
        if (num > 0)
        {
            TrackerReport[] reps = new TrackerReport[num];
            for (int i = 0; i < num; i++)
            {
                                #if UNITY_IPHONE
                reps[i] = MarshalPtrToTrackerReport(repsPtr[i]);                         // PtrToStructure not working in .NET 1.1
                                #else
                reps[i] = (TrackerReport)Marshal.PtrToStructure(repsPtr[i], typeof(TrackerReport));
                                #endif
                //Convert to left-handed coordinates
                Console.WriteLine("x:" + reps[i].quat[0] + " y:" + reps[i].quat[1] + " z:" + reps[i].quat[2] + " w:" + reps[i].quat[3]);
                reps[i].pos[1]  = -reps[i].pos[1];
                reps[i].quat[0] = -reps[i].quat[0];
                reps[i].quat[2] = -reps[i].quat[2];
                TrackerMarker marker = null;
                if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
                {
                    marker = (TrackerMarker)markers[Marshal.PtrToStringAnsi(reps[i].data)];
                }
                else
                {
                    marker = (TrackerMarker)markers[reps[i].id.ToString()];
                }
                if (ShowDebug)
                {
                    string debug_line = "Target type: ";
                    if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
                    {
                        debug_line += "Multi data:" + Marshal.PtrToStringAnsi(reps[i].data);
                    }
                    else
                    {
                        debug_line += ((TrackerMarker.Marker_Type)reps[i].type).ToString();
                        debug_line += " id:" + reps[i].id;
                    }
                    debug_line += " conf:" + reps[i].conf + " area:" + reps[i].area;
                    debug_line += " pos:" + reps[i].pos;
                    debug_line += " ori:" + reps[i].quat.eulerAngles;
                    Console.WriteLine(debug_line);
                }
                if (marker != null && marker.Behavior == TrackerMarker.Behavior_Flags.WorldFixed)
                {
                    Camera.main.transform.localPosition = marker.transform.rotation * Quaternion.Inverse(reps[i].quat) * (-reps[i].pos) + marker.transform.position;
                    Camera.main.transform.localRotation = marker.transform.rotation * Quaternion.Inverse(reps[i].quat);
                    if (reps[i].type <= (int)TrackerMarker.Marker_Type.Split)
                    {
                        TrackerSingleMarker singleMarker = marker as TrackerSingleMarker;
                        singleMarker.confidence = reps[i].conf;
                        singleMarker.corners[0] = reps[i].corner0;
                        singleMarker.corners[1] = reps[i].corner1;
                        singleMarker.corners[2] = reps[i].corner2;
                        singleMarker.corners[3] = reps[i].corner3;
                        singleMarker.area       = reps[i].area;
                    }
                    marker.visible = true;
                    reps[i].type   = 0;
                }
            }
            float maxArea     = 0.0f;
            int   learningNum = -1;
            for (int i = 0; i < num; i++)
            {
                if (reps[i].type != 0)
                {
                    TrackerMarker marker = null;
                    if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
                    {
                        marker = (TrackerMarker)markers[Marshal.PtrToStringAnsi(reps[i].data)];
                    }
                    else
                    {
                        marker = (TrackerMarker)markers[reps[i].id.ToString()];
                    }
                    if (marker == null && learningMarker != null)
                    {
                        if (reps[i].conf * reps[i].area > maxArea)
                        {
                            maxArea     = reps[i].conf * reps[i].area;
                            learningNum = i;
                        }
                    }
                    if (marker != null && marker.enabled)
                    {
                        marker.transform.localPosition = Camera.main.transform.TransformPoint(reps[i].pos);
                        marker.transform.localRotation = Camera.main.transform.rotation * reps[i].quat;
                        if (reps[i].type <= (int)TrackerMarker.Marker_Type.Split)
                        {
                            TrackerSingleMarker singleMarker = marker as TrackerSingleMarker;
                            singleMarker.confidence = reps[i].conf;
                            singleMarker.corners[0] = reps[i].corner0;
                            singleMarker.corners[1] = reps[i].corner1;
                            singleMarker.corners[2] = reps[i].corner2;
                            singleMarker.corners[3] = reps[i].corner3;
                            singleMarker.area       = reps[i].area;
                        }
                        marker.visible = true;
                    }
                }
            }
            if (learningNum >= 0)
            {
                learningMarker.transform.localPosition = Camera.main.transform.TransformPoint(reps[learningNum].pos);
                learningMarker.transform.localRotation = Camera.main.transform.rotation * reps[learningNum].quat;
                if (reps[learningNum].type <= (int)TrackerMarker.Marker_Type.Split)
                {
                    TrackerSingleMarker singleMarker = learningMarker as TrackerSingleMarker;
                    singleMarker.confidence = reps[learningNum].conf;
                    singleMarker.corners[0] = reps[learningNum].corner0;
                    singleMarker.corners[1] = reps[learningNum].corner1;
                    singleMarker.corners[2] = reps[learningNum].corner2;
                    singleMarker.corners[3] = reps[learningNum].corner3;
                    singleMarker.area       = reps[learningNum].area;
                    singleMarker.id         = reps[learningNum].id;
                    singleMarker.data       = Marshal.PtrToStringAnsi(reps[learningNum].data);
                    singleMarker.confidence = reps[learningNum].conf;
                    singleMarker.area       = reps[learningNum].area;
                }
                learningMarker.visible = true;
            }
        }
                #if !UNITY_IPHONE
        if (ShowDebug)
        {
            debug_writer.Flush();
            string buffer = debug_writer.ToString();
            if (buffer.Length > 0)
            {
                StringReader strReader = new StringReader(buffer);
                string       line;
                while (true)
                {
                    line = strReader.ReadLine();
                    if (line == null || line.Length == 0)
                    {
                        break;
                    }
                    debug_text[debug_buffer_pos] = line;
                    debug_buffer_pos++;
                    if (debug_index < 0 && debug_index > debug_lines - debug_buffer_max)
                    {
                        debug_index--;
                    }
                    if (debug_buffer_pos >= debug_buffer_max)
                    {
                        debug_buffer_pos = 0;
                    }
                }
                debug_writer.Close();
                debug_writer = new StringWriter();
                Console.SetOut(debug_writer);
            }
        }
        #endif
    }
예제 #8
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;
		}
	}
예제 #9
0
    void Start () {
    	//allocate unmanaged memory for tracker reports
		repsPtr = new IntPtr[MaxReports];
		TrackerReport report = new TrackerReport();
		report.sensor = 0;
     	report.pos = new double[3];
     	report.quat = new double[4];
		report.quat[3] = 1.0f;
		for(int i=0; i<MaxReports ; i++)
		{
			repsPtr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TrackerReport)));
			Marshal.StructureToPtr(report, repsPtr[i], true);
		}
    	if (DeviceToUnity == null || SensorOffset == null)
    	{
    		if (DeviceToUnity == null)
    			Console.WriteLine("Warning: DeviceToUnity field not referencing a transform");
    		if (SensorOffset == null)
    			Console.WriteLine("Warning: SensorOffset field not referencing a transform");
    	}
        
        // Setup last report time memory 
		LastReport = new VRPNManager.TimeVal();  
    }
예제 #10
0
	TrackerReport MarshalPtrToTrackerReport(IntPtr ptr)
	{
		int[] intVals = new int[2];
		float[] floatVals = new float[8];
		TrackerReport result = new TrackerReport();
		Marshal.Copy(ptr,intVals,0,2);
		Marshal.Copy((IntPtr)((int)ptr+8),floatVals,0,8);
		result.id = intVals[0];
		result.type = intVals[1];
		result.pos.x = floatVals[0];
		result.pos.y = floatVals[1];
		result.pos.z = floatVals[2];
		result.quat.x = floatVals[3];
		result.quat.y = floatVals[4];
		result.quat.z = floatVals[5];
		result.quat.w = floatVals[6];
		result.conf = floatVals[7];
		Marshal.Copy((IntPtr)((int)ptr+40),floatVals,0,8);
		result.corner0.x = floatVals[0];
		result.corner0.y = floatVals[1];
		result.corner1.x = floatVals[2];
		result.corner1.y = floatVals[3];
		result.corner2.x = floatVals[4];
		result.corner2.y = floatVals[5];
		result.corner3.x = floatVals[6];
		result.corner3.y = floatVals[7];
		result.area = Marshal.ReadInt32((IntPtr)((int)ptr+72));
		result.data = Marshal.ReadIntPtr((IntPtr)((int)ptr+76));
		return result;
	}
예제 #11
0
	void UpdateMarkers ()
	{
        foreach( DictionaryEntry marker in markers )
            ((TrackerMarker)marker.Value).visible = false;
		int num = MaxReports;
		Pixel_Format format = Pixel_Format.PIXEL_FORMAT_RGB;
		if (CameraNode.m_depth == 32 && CameraNode.m_pixelFormat == 32993)
			format = Pixel_Format.PIXEL_FORMAT_BGRA;
		TRACKER_getReports(handle,CameraNode.m_vidpointer_byte,CameraNode.m_width,CameraNode.m_height,(int)format,repsPtr,ref num);
		if (num > 0)
		{
			TrackerReport[] reps = new TrackerReport[num];
			for(int i=0; i<num ; i++)
			{
				#if UNITY_IPHONE
					reps[i] = MarshalPtrToTrackerReport(repsPtr[i]); // PtrToStructure not working in .NET 1.1
				#else
					reps[i] = (TrackerReport)Marshal.PtrToStructure(repsPtr[i],typeof(TrackerReport)); 
				#endif
				//Convert to left-handed coordinates
				Console.WriteLine("x:" + reps[i].quat[0] + " y:" + reps[i].quat[1] + " z:" + reps[i].quat[2] + " w:" + reps[i].quat[3]);
				reps[i].pos[1] = -reps[i].pos[1];
				reps[i].quat[0] = -reps[i].quat[0];
				reps[i].quat[2] = -reps[i].quat[2];
				TrackerMarker marker = null;
				if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
					marker = (TrackerMarker)markers[Marshal.PtrToStringAnsi(reps[i].data)];
				else
					marker = (TrackerMarker)markers[reps[i].id.ToString()];
	  			if (ShowDebug)
	  			{
					string debug_line = "Target type: ";
					if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
						debug_line += "Multi data:" + Marshal.PtrToStringAnsi(reps[i].data);
					else
					{
						debug_line += ((TrackerMarker.Marker_Type)reps[i].type).ToString();
						debug_line += " id:" + reps[i].id;
					} 
					debug_line += " conf:" + reps[i].conf + " area:" + reps[i].area;
					debug_line += " pos:" + reps[i].pos;
					debug_line += " ori:" + reps[i].quat.eulerAngles;
    				Console.WriteLine(debug_line);
 				}	  							
				if (marker != null && marker.Behavior == TrackerMarker.Behavior_Flags.WorldFixed)
				{
  					Camera.main.transform.localPosition = marker.transform.rotation*Quaternion.Inverse(reps[i].quat)*(-reps[i].pos) + marker.transform.position;
  					Camera.main.transform.localRotation = marker.transform.rotation*Quaternion.Inverse(reps[i].quat);
					if (reps[i].type <= (int)TrackerMarker.Marker_Type.Split)
					{
  						TrackerSingleMarker singleMarker = marker as TrackerSingleMarker;
  						singleMarker.confidence = reps[i].conf;
  						singleMarker.corners[0] = reps[i].corner0;
  						singleMarker.corners[1] = reps[i].corner1;
  						singleMarker.corners[2] = reps[i].corner2;
  						singleMarker.corners[3] = reps[i].corner3;
  						singleMarker.area = reps[i].area;
					}
  					marker.visible = true;
  					reps[i].type = 0;
  				}
  			}
  			float maxArea = 0.0f;
  			int learningNum = -1;
			for(int i=0; i<num ; i++)
			{
				if (reps[i].type != 0)
				{
					TrackerMarker marker = null;
					if (reps[i].type > (int)TrackerMarker.Marker_Type.Split)
						marker = (TrackerMarker)markers[Marshal.PtrToStringAnsi(reps[i].data)];
					else
						marker = (TrackerMarker)markers[reps[i].id.ToString()];
					if (marker == null && learningMarker != null)
					{
						if (reps[i].conf*reps[i].area > maxArea)
						{
							maxArea = reps[i].conf*reps[i].area;
							learningNum = i;
						}
					}
	  				if (marker != null && marker.enabled)
	  				{
	  					marker.transform.localPosition = Camera.main.transform.TransformPoint(reps[i].pos);
	  					marker.transform.localRotation = Camera.main.transform.rotation*reps[i].quat;
						if (reps[i].type <= (int)TrackerMarker.Marker_Type.Split)
						{
	  						TrackerSingleMarker singleMarker = marker as TrackerSingleMarker;
	  						singleMarker.confidence = reps[i].conf;
	  						singleMarker.corners[0] = reps[i].corner0;
	  						singleMarker.corners[1] = reps[i].corner1;
	  						singleMarker.corners[2] = reps[i].corner2;
	  						singleMarker.corners[3] = reps[i].corner3;
	  						singleMarker.area = reps[i].area;
						}
	  					marker.visible = true;
	  				}
				}
  			}
  			if (learningNum >= 0)
  			{
	  			learningMarker.transform.localPosition = Camera.main.transform.TransformPoint(reps[learningNum].pos);
	  			learningMarker.transform.localRotation = Camera.main.transform.rotation*reps[learningNum].quat;
				if (reps[learningNum].type <= (int)TrackerMarker.Marker_Type.Split)
				{
 					TrackerSingleMarker singleMarker = learningMarker as TrackerSingleMarker;
					singleMarker.confidence = reps[learningNum].conf;
					singleMarker.corners[0] = reps[learningNum].corner0;
					singleMarker.corners[1] = reps[learningNum].corner1;
					singleMarker.corners[2] = reps[learningNum].corner2;
					singleMarker.corners[3] = reps[learningNum].corner3;
					singleMarker.area = reps[learningNum].area;
	  				singleMarker.id = reps[learningNum].id;
	  				singleMarker.data = Marshal.PtrToStringAnsi(reps[learningNum].data);
	  				singleMarker.confidence = reps[learningNum].conf;
	  				singleMarker.area = reps[learningNum].area;
				}
	  			learningMarker.visible = true;
  			}
  				
		}
		#if !UNITY_IPHONE
    	if (ShowDebug) 
    	{
    		debug_writer.Flush();
    		string buffer = debug_writer.ToString();
    		if (buffer.Length > 0) 
    		{
   		     	StringReader strReader = new StringReader(buffer);
   		     	string line;
    	    	while(true) 
    	    	{
    	    		line = strReader.ReadLine();
    	    		if (line == null || line.Length == 0)
    	    			break;
	        		debug_text[debug_buffer_pos] = line;
	        		debug_buffer_pos++;
	        		if (debug_index < 0 && debug_index > debug_lines - debug_buffer_max)
	        			debug_index--;
	        		if (debug_buffer_pos >= debug_buffer_max)
	        			debug_buffer_pos = 0;
    	    	}
    			debug_writer.Close();
    			debug_writer = new StringWriter();
    			Console.SetOut(debug_writer);
    		}
    	}
    	#endif
    }
예제 #12
0
    void Awake() 
    {
    	//allocate unmanaged memory for tracker reports
		repsPtr = new IntPtr[MaxReports];
		TrackerReport report = new TrackerReport();
     	report.pos = new Vector3();
     	report.quat = new Quaternion();
     	report.corner0 = new Vector2();
     	report.corner1 = new Vector2();
     	report.corner2 = new Vector2();
     	report.corner3 = new Vector2();
     	report.conf = 0.0f;
     	report.area = 0;
		for(int i=0; i<MaxReports ; i++)
		{
			repsPtr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TrackerReport)));
			report.data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte))*256);
			Marshal.WriteIntPtr((IntPtr)((int)repsPtr[i]+76),report.data);
			//Marshal.StructureToPtr(report, repsPtr[i], true); not working in .NET 1.1
		}
		int config_flags = 0;
		for (int i=0; i<options.Length; i++)
			config_flags |= (int)options[i];
  		foreach (TrackerMarker marker in FindObjectsOfType(typeof(TrackerMarker)))
   			if (marker.enabled)
  				config_flags |= marker.Config();
   		string filepath = Plugins.CreateFileFromAsset(CalibrationFile);
		TRACKER_createTracker(filepath,config_flags,ref handle);
		if (handle >= 0)
		{
			if (Threshold > 0)
				TRACKER_setThreshold(handle,Threshold);
			if (ShowDebug) 
			{
	         	#if !UNITY_IPHONE
	         	debug_text = new string[debug_buffer_max];
	        	debug_writer = new StringWriter();
	         	Console.SetOut(debug_writer);
	         	#endif
	         	Console.WriteLine("Tracker Initialized");
			}
		}
     	debug_flag = ShowDebug;
    }