Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using GoogleARCore;
- using UnityEngine;
- /// <summary>
- /// Controller for AugmentedImage example.
- /// </summary>
- /// <remarks>
- /// In this sample, we assume all images are static or moving slowly with
- /// a large occupation of the screen. If the target is actively moving,
- /// we recommend to check <see cref="AugmentedImage.TrackingMethod"/> and
- /// render only when the tracking method equals to
- /// <see cref="AugmentedImageTrackingMethod.FullTracking"/>.
- /// See details in <a href="https://developers.google.com/ar/develop/c/augmented-images/">
- /// Recognize and Augment Images</a>
- /// </remarks>
- public class AugmentedImageExampleController : MonoBehaviour
- {
- public Transform CubeTransform;
- private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();
- public float cubeWidth = 0.064f;
- public void Update()
- {
- // Get updated augmented images for this frame.
- Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages);
- foreach (var image in m_TempAugmentedImages)
- {
- if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking)
- {
- CubeTransform.position = image.CenterPose.position - image.CenterPose.up * cubeWidth / 2f;
- CubeTransform.rotation = image.CenterPose.rotation;
- switch (image.Name)
- {
- case "Front":
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
- break;
- case "Left":
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, -90f);
- break;
- case "Right":
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, 90f);
- break;
- case "Top":
- break;
- case "Back":
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, 180f);
- break;
- case "Bottom":
- CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 180f);
- break;
- default:
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement