public void RegisterSingleMarker(TrackerSingleMarker marker)
 {
     if (marker.enabled)
     {
         String uniqueName;
         int    config_flags = 0;
         config_flags |= marker.Config();
         for (int j = 0; j < marker.options.Length; j++)
         {
             config_flags |= (int)marker.options[j];
         }
         if (marker.id >= 0)
         {
             uniqueName = marker.id.ToString();
         }
         else
         {
             uniqueName     = marker.MarkerType.ToString();
             learningMarker = marker;
         }
         TRACKER_registerSingleMarker(handle, uniqueName, marker.id, marker.data, marker.Size.x, marker.Size.y, config_flags);
         if (ShowDebug)
         {
             Console.WriteLine("Registering marker " + marker.name + " as " + uniqueName);
         }
         markers[uniqueName] = marker;
     }
 }
    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
    }
    public void RegisterSingleMarker(TrackerSingleMarker marker)
    {
 		if (marker.enabled)
  		{
 			String uniqueName;
			int config_flags = 0;
  			config_flags |= marker.Config();
  			for (int j=0; j<marker.options.Length; j++)
  				config_flags |= (int)marker.options[j];
			if (marker.id >= 0)
				uniqueName = marker.id.ToString();
			else
			{
				uniqueName = marker.MarkerType.ToString();
				learningMarker = marker;
			}
			TRACKER_registerSingleMarker(handle,uniqueName,marker.id,marker.data,marker.Size.x,marker.Size.y,config_flags);
  			if (ShowDebug)
  				Console.WriteLine("Registering marker " + marker.name + " as " + uniqueName);
   			markers[uniqueName] = marker;
  		}
    }
Example #4
0
 public void AddMarker(TrackerMarker marker)
 {
     markers.Add(marker);
 }
Example #5
0
 public void AddMarker(TrackerMarker marker)
 {
     markers.Add(marker);
 }