NRTrackableImage.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using UnityEngine;
  13. /// <summary> A trackable image in the real world detected by NRInternel. </summary>
  14. public class NRTrackableImage : NRTrackable
  15. {
  16. internal NRTrackableImageSubsystem TrackableImageSubsystem
  17. {
  18. get
  19. {
  20. return NRSessionManager.Instance.TrackableFactory.TrackableImageSubsystem;
  21. }
  22. }
  23. /// <summary> Constructor. </summary>
  24. /// <param name="nativeHandle"> Handle of the native.</param>
  25. /// <param name="nativeInterface"> The native interface.</param>
  26. internal NRTrackableImage(UInt64 nativeHandle) : base(nativeHandle)
  27. {
  28. }
  29. /// <summary>
  30. /// Gets the position and orientation of the marker's center in Unity world space. </summary>
  31. /// <returns> The center pose. </returns>
  32. public override Pose GetCenterPose()
  33. {
  34. if (NRFrame.SessionStatus != SessionState.Running)
  35. {
  36. return Pose.identity;
  37. }
  38. var native_pose = TrackableImageSubsystem.GetCenterPose(TrackableNativeHandle);
  39. return ConversionUtility.ApiWorldToUnityWorld(native_pose);
  40. }
  41. /// <summary> Gets the width of marker. </summary>
  42. /// <value> The extent x coordinate. </value>
  43. public float ExtentX
  44. {
  45. get
  46. {
  47. return Size.x;
  48. }
  49. }
  50. /// <summary> Gets the height of marker. </summary>
  51. /// <value> The extent z coordinate. </value>
  52. public float ExtentZ
  53. {
  54. get
  55. {
  56. return Size.y;
  57. }
  58. }
  59. /// <summary> Get the size of trackable image. size of trackable imag(width、height). </summary>
  60. /// <value> The size. </value>
  61. public Vector2 Size
  62. {
  63. get
  64. {
  65. if (NRFrame.SessionStatus != SessionState.Running)
  66. {
  67. return Vector2.zero;
  68. }
  69. return TrackableImageSubsystem.GetSize(TrackableNativeHandle);
  70. }
  71. }
  72. }
  73. }