private void CreateCylinderTargets() { int trackableDataArrayLength = QCARWrapper.Instance.DataSetGetNumTrackableType(TypeMapping.GetTypeID(typeof(CylinderTarget)), this.mDataSetPtr); if (trackableDataArrayLength > 0) { IntPtr trackableDataArray = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(SimpleTargetData)) * trackableDataArrayLength)); if (QCARWrapper.Instance.DataSetGetTrackablesOfType(TypeMapping.GetTypeID(typeof(CylinderTarget)), trackableDataArray, trackableDataArrayLength, this.mDataSetPtr) == 0) { Debug.LogError("Could not create Cylinder Targets"); } else { for (int i = 0; i < trackableDataArrayLength; i++) { IntPtr ptr = new IntPtr(trackableDataArray.ToInt32() + (i * Marshal.SizeOf(typeof(SimpleTargetData)))); SimpleTargetData data = (SimpleTargetData)Marshal.PtrToStructure(ptr, typeof(SimpleTargetData)); if (!this.mTrackablesDict.ContainsKey(data.id)) { int capacity = 0x80; StringBuilder trackableName = new StringBuilder(capacity); QCARWrapper.Instance.DataSetGetTrackableName(this.mDataSetPtr, data.id, trackableName, capacity); CylinderTarget target = new CylinderTargetImpl(trackableName.ToString(), data.id, this); this.mTrackablesDict[data.id] = target; } } Marshal.FreeHGlobal(trackableDataArray); } } }
private void CreateCylinderTargets() { // Allocate array for all Cylinder Targets. int numCylinderTargets = QCARWrapper.Instance.DataSetGetNumTrackableType( (int)TrackableType.CYLINDER_TARGET, mDataSetPtr); if (numCylinderTargets > 0) { IntPtr cylinderTargetDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SimpleTargetData)) * numCylinderTargets); // Copy Cylinder Target properties from native. if (QCARWrapper.Instance.DataSetGetTrackablesOfType((int)TrackableType.CYLINDER_TARGET, cylinderTargetDataPtr, numCylinderTargets, mDataSetPtr) == 0) { Debug.LogError("Could not create Cylinder Targets"); return; } // Create Cylinder Target Behaviours. for (int i = 0; i < numCylinderTargets; ++i) { IntPtr trackablePtr = new IntPtr(cylinderTargetDataPtr.ToInt32() + i * Marshal.SizeOf(typeof(SimpleTargetData))); SimpleTargetData trackableData = (SimpleTargetData) Marshal.PtrToStructure(trackablePtr, typeof(SimpleTargetData)); // Do not overwrite existing Trackables. if (mTrackablesDict.ContainsKey(trackableData.id)) { continue; } // QCAR support names up to 64 characters in length, but here we allocate // a slightly larger buffer: int nameLength = 128; System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength); QCARWrapper.Instance.DataSetGetTrackableName(mDataSetPtr, trackableData.id, trackableName, nameLength); CylinderTarget cylinderTarget = new CylinderTargetImpl(trackableName.ToString(), trackableData.id, this); // Add newly created Multi Target to dictionary. mTrackablesDict[trackableData.id] = cylinderTarget; } Marshal.FreeHGlobal(cylinderTargetDataPtr); } }
private void CreateCylinderTargets() { // Allocate array for all Cylinder Targets. int numCylinderTargets = QCARWrapper.Instance.DataSetGetNumTrackableType( (int)TrackableType.CYLINDER_TARGET, mDataSetPtr); if (numCylinderTargets > 0) { IntPtr cylinderTargetDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof (SimpleTargetData))*numCylinderTargets); // Copy Cylinder Target properties from native. if (QCARWrapper.Instance.DataSetGetTrackablesOfType((int) TrackableType.CYLINDER_TARGET, cylinderTargetDataPtr, numCylinderTargets, mDataSetPtr) == 0) { Debug.LogError("Could not create Cylinder Targets"); return; } // Create Cylinder Target Behaviours. for (int i = 0; i < numCylinderTargets; ++i) { IntPtr trackablePtr = new IntPtr(cylinderTargetDataPtr.ToInt32() + i* Marshal.SizeOf(typeof (SimpleTargetData))); SimpleTargetData trackableData = (SimpleTargetData) Marshal.PtrToStructure(trackablePtr, typeof (SimpleTargetData)); // Do not overwrite existing Trackables. if (mTrackablesDict.ContainsKey(trackableData.id)) { continue; } // QCAR support names up to 64 characters in length, but here we allocate // a slightly larger buffer: int nameLength = 128; System.Text.StringBuilder trackableName = new System.Text.StringBuilder(nameLength); QCARWrapper.Instance.DataSetGetTrackableName(mDataSetPtr, trackableData.id, trackableName, nameLength); CylinderTarget cylinderTarget = new CylinderTargetImpl(trackableName.ToString(), trackableData.id, this); // Add newly created Multi Target to dictionary. mTrackablesDict[trackableData.id] = cylinderTarget; } Marshal.FreeHGlobal(cylinderTargetDataPtr); } }