void Update() { // Perform marker image tracking uint markerCount = stringWrapper.Update(); // Handle detected markers for (uint i = 0; i < markerCount; i++) { // Fetch tracker data for this marker StringWrapper.MarkerInfo markerInfo = stringWrapper.GetDetectedMarkerInfo(i); if (markerInfo.imageID < markerObjects.Length) { // Orient the camera according to the marker transform.parent = markerObjects[markerInfo.imageID].transform; transform.localRotation = Quaternion.Inverse(markerInfo.rotation); transform.localPosition = transform.localRotation * -markerInfo.position; lastSpottedTime = Time.time; break; } } // Marker not spotted? Point camera away if (lastSpottedTime != Time.time) { transform.localPosition = new Vector3(1000000, 0, 0); transform.localRotation = Quaternion.identity; } }
void Update() { // Perform marker image tracking uint markerCount = stringWrapper.Update(); // Handle detected markers for (uint i = 0; i < markerCount; i++) { // Fetch tracker data for this marker StringWrapper.MarkerInfo markerInfo = stringWrapper.GetDetectedMarkerInfo(i); if (markerInfo.imageID < rootObjects.Length && rootObjects[markerInfo.imageID] != null) { rootObjects[markerInfo.imageID].transform.localPosition = markerInfo.position; rootObjects[markerInfo.imageID].transform.localRotation = markerInfo.rotation; lastSpottedTimes[markerInfo.imageID] = Time.time; if (!rootObjects[markerInfo.imageID].active) { rootObjects[markerInfo.imageID].SetActiveRecursively(true); } } } // Deactivate rootObjects for lost markers for (uint i = 0; i < rootObjects.Length; i++) { if (rootObjects[i].active) { if (Time.time - lastSpottedTimes[i] > 2) { // Marker has been out of view for a while; Deactivate it rootObjects[i].SetActiveRecursively(false); } else if (Time.time != lastSpottedTimes[i]) { // Marker wasn't spotted this frame; Hide it rootObjects[i].transform.localPosition = new Vector3(1000000, 0, 0); } } } }