Last active
May 13, 2018 04:41
-
-
Save wwdablu/2d858e1051d8e364837efaf816fe53c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Camera FirstPersonCamera; | |
public GameObject DetectedPlanePrefab; | |
public GameObject DiabloGameObject; | |
void Update () { | |
_UpdateApplicationLifecycle(); | |
// Hide snackbar when currently tracking at least one plane. | |
Session.GetTrackables<DetectedPlane>(m_AllPlanes); | |
bool showSearchingUI = true; | |
for (int i = 0; i < m_AllPlanes.Count; i++) | |
{ | |
if (m_AllPlanes[i].TrackingState == TrackingState.Tracking) | |
{ | |
showSearchingUI = false; | |
break; | |
} | |
} | |
// If the player has not touched the screen, we are done with this update. | |
Touch touch; | |
if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) | |
{ | |
return; | |
} | |
// Raycast against the location the player touched to search for planes. | |
TrackableHit hit; | |
TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | | |
TrackableHitFlags.FeaturePointWithSurfaceNormal; | |
if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) | |
{ | |
// Use hit pose and camera pose to check if hittest is from the | |
// back of the plane, if it is, no need to create the anchor. | |
if ((hit.Trackable is DetectedPlane) && | |
Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, | |
hit.Pose.rotation * Vector3.up) < 0) | |
{ | |
Debug.Log("Hit at back of the current DetectedPlane"); | |
} | |
else | |
{ | |
var diabloGameObj = Instantiate(DiabloGameObject, hit.Pose.position, hit.Pose.rotation); | |
diabloGameObj.transform.Rotate(0, k_ModelRotation, 0, Space.Self); | |
var anchor = hit.Trackable.CreateAnchor(hit.Pose); | |
diabloGameObj.transform.parent = anchor.transform; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment