Advertisement
daserge

MagiDice ARCore tracking

May 15th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using GoogleARCore;
  3. using UnityEngine;
  4.  
  5. /// <summary>
  6. /// Controller for AugmentedImage example.
  7. /// </summary>
  8. /// <remarks>
  9. /// In this sample, we assume all images are static or moving slowly with
  10. /// a large occupation of the screen. If the target is actively moving,
  11. /// we recommend to check <see cref="AugmentedImage.TrackingMethod"/> and
  12. /// render only when the tracking method equals to
  13. /// <see cref="AugmentedImageTrackingMethod.FullTracking"/>.
  14. /// See details in <a href="https://developers.google.com/ar/develop/c/augmented-images/">
  15. /// Recognize and Augment Images</a>
  16. /// </remarks>
  17. public class AugmentedImageExampleController : MonoBehaviour
  18. {
  19.     public Transform CubeTransform;
  20.  
  21.     private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();
  22.     public float cubeWidth = 0.064f;
  23.  
  24.     public void Update()
  25.     {
  26.         // Get updated augmented images for this frame.
  27.         Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages);
  28.  
  29.         foreach (var image in m_TempAugmentedImages)
  30.         {
  31.             if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking)
  32.             {
  33.                 CubeTransform.position = image.CenterPose.position - image.CenterPose.up * cubeWidth / 2f;
  34.                 CubeTransform.rotation = image.CenterPose.rotation;
  35.                 switch (image.Name)
  36.                 {
  37.                     case "Front":
  38.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
  39.                         break;
  40.                     case "Left":
  41.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
  42.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, -90f);
  43.                         break;
  44.                     case "Right":
  45.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
  46.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, 90f);
  47.                         break;
  48.                     case "Top":
  49.                         break;
  50.                     case "Back":
  51.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 90f);
  52.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.up, 180f);
  53.                         break;
  54.                     case "Bottom":
  55.                         CubeTransform.RotateAround(CubeTransform.position, CubeTransform.right, 180f);
  56.                         break;
  57.                     default:
  58.                         break;
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement