public void RegisterMultiMarker(TrackerMultiMarker 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]; } uniqueName = "_" + marker.GetInstanceID().ToString(); string filepath = ""; if (marker.Filename.Length > 0) { filepath = Plugins.CreateFileFromAsset(marker.Filename); TRACKER_registerMultiMarker(handle, uniqueName, filepath, config_flags); } else { Console.WriteLine("Error: TrackerMultiMarker requires Filename"); } if (ShowDebug) { Console.WriteLine("Registering marker " + marker.name + " as " + uniqueName); } markers[uniqueName] = marker; } }
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; }
void ParseConfigFile() { Debug.Log("VRPNManager: ParseConfigFile"); int index = 0; ArrayList potential_names = new ArrayList(); try { //recreate config file from txt file in Assets/Resources string filepath = Plugins.CreateFileFromAsset(ConfigFile); //print ("configuration read file: " + filepath); FileStream reads = new FileStream(filepath, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(reads); string line = sr.ReadLine(); bool write = false; while ((line = sr.ReadLine()) != null) { if (write && (line.StartsWith("#") || line == "")) { write = false; } bool active = line.StartsWith("vrpn_"); if (active || line.StartsWith("#vrpn_")) { string[] splitResult = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (!potential_names.Contains(splitResult[1])) { potential_names.Add(splitResult[1]); } if (active) { try { Enum.Parse(typeof(Tracker_Types), splitResult[0]); write = true; } catch {} } } if (write) { string[] holder = ConfigLines; ConfigLines = new string[index + 1]; Array.Copy(holder, ConfigLines, index); ConfigLines[index++] = line; } } reads.Close(); } catch (FileNotFoundException e) { throw(e); } }
void ParseConfigFile() { //Debug.Log("VRPNManager: ParseConfigFile"); int index = 0; ArrayList potential_names = new ArrayList(); try { //recreate config file from txt file in Assets/Resources string filepath = Plugins.CreateFileFromAsset(ConfigFile); //print ("configuration read file: " + filepath); FileStream reads = new FileStream(filepath, System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(reads); string line = sr.ReadLine(); bool write = false; while ((line = sr.ReadLine()) != null) { if (write && (line.StartsWith("#") || line == "")) { write = false; } bool active = line.StartsWith("vrpn_"); if (active || line.StartsWith("#vrpn_")) { string[] splitResult = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (!potential_names.Contains(splitResult[1])) { potential_names.Add(splitResult[1]); } if (active) { try { Enum.Parse(typeof(Tracker_Types), splitResult[0]); write = true; } catch {} } } if (write) { string[] holder = ConfigLines; ConfigLines = new string[index + 1]; Array.Copy(holder, ConfigLines, index); ConfigLines[index++] = line; } } reads.Close(); bool changed = false; index = 0; potential_names.Sort(); foreach (string s in potential_names) { try { if (index != (int)Enum.Parse(typeof(VRPNDeviceConfig.Device_Names), s)) { changed = true; } } catch { changed = true; } index++; } if (changed) { //Debug.Log("updating device names in VRPNDeviceConfig.cs"); string filename = Application.dataPath + "/../Assets/Plugins/VRPNWrapper/VRPNDeviceConfig.cs"; FileStream write_stream = new FileStream(filename, System.IO.FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(write_stream); sw.WriteLine("using System;"); sw.WriteLine("public class VRPNDeviceConfig"); sw.WriteLine("{"); sw.Write(" public enum Device_Names { "); bool first = true; foreach (string s in potential_names) { if (!first) { sw.Write(","); } sw.Write("\n "+ s); first = false; } sw.Write(" };\n"); sw.WriteLine("}"); sw.Flush(); sw.Close(); } } catch (FileNotFoundException e) { throw(e); } }