1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 #ifndef DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_ORIGINS_H_ 5 #define DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_ORIGINS_H_ 6 7 #include <windows.perception.spatial.h> 8 #include <wrl.h> 9 10 #include <memory> 11 #include <vector> 12 13 #include "base/callback_list.h" 14 #include "base/macros.h" 15 16 namespace device { 17 class WMRTimestamp; 18 19 class WMRCoordinateSystem { 20 public: 21 virtual ~WMRCoordinateSystem() = default; 22 virtual bool TryGetTransformTo( 23 const WMRCoordinateSystem* other, 24 ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) = 0; 25 virtual ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem* 26 GetRawPtr() const; 27 }; 28 29 class WMRCoordinateSystemImpl : public WMRCoordinateSystem { 30 public: 31 explicit WMRCoordinateSystemImpl( 32 Microsoft::WRL::ComPtr< 33 ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem> 34 coordinates); 35 ~WMRCoordinateSystemImpl() override; 36 37 bool TryGetTransformTo( 38 const WMRCoordinateSystem* other, 39 ABI::Windows::Foundation::Numerics::Matrix4x4* this_to_other) override; 40 41 ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem* GetRawPtr() 42 const override; 43 44 private: 45 Microsoft::WRL::ComPtr< 46 ABI::Windows::Perception::Spatial::ISpatialCoordinateSystem> 47 coordinates_; 48 49 DISALLOW_COPY_AND_ASSIGN(WMRCoordinateSystemImpl); 50 }; 51 52 class WMRStationaryOrigin { 53 public: 54 virtual ~WMRStationaryOrigin() = default; 55 56 virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() = 0; 57 }; 58 59 class WMRStationaryOriginImpl : public WMRStationaryOrigin { 60 public: 61 explicit WMRStationaryOriginImpl( 62 Microsoft::WRL::ComPtr< 63 ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference> 64 stationary_origin); 65 ~WMRStationaryOriginImpl() override; 66 67 std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() override; 68 69 private: 70 Microsoft::WRL::ComPtr< 71 ABI::Windows::Perception::Spatial::ISpatialStationaryFrameOfReference> 72 stationary_origin_; 73 74 DISALLOW_COPY_AND_ASSIGN(WMRStationaryOriginImpl); 75 }; 76 77 class WMRAttachedOrigin { 78 public: 79 virtual ~WMRAttachedOrigin() = default; 80 81 virtual std::unique_ptr<WMRCoordinateSystem> TryGetCoordinatesAtTimestamp( 82 const WMRTimestamp* timestamp) = 0; 83 }; 84 85 class WMRAttachedOriginImpl : public WMRAttachedOrigin { 86 public: 87 explicit WMRAttachedOriginImpl( 88 Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial:: 89 ISpatialLocatorAttachedFrameOfReference> 90 attached_origin); 91 ~WMRAttachedOriginImpl() override; 92 93 std::unique_ptr<WMRCoordinateSystem> TryGetCoordinatesAtTimestamp( 94 const WMRTimestamp* timestamp) override; 95 96 private: 97 Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial:: 98 ISpatialLocatorAttachedFrameOfReference> 99 attached_origin_; 100 101 DISALLOW_COPY_AND_ASSIGN(WMRAttachedOriginImpl); 102 }; 103 104 class WMRStageOrigin { 105 public: 106 virtual ~WMRStageOrigin() = default; 107 108 virtual std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() = 0; 109 virtual ABI::Windows::Perception::Spatial::SpatialMovementRange 110 MovementRange() = 0; 111 112 // This will return an empty array if no bounds are set. 113 virtual std::vector<ABI::Windows::Foundation::Numerics::Vector3> 114 GetMovementBounds(const WMRCoordinateSystem* coordinates) = 0; 115 }; 116 117 class WMRStageOriginImpl : public WMRStageOrigin { 118 public: 119 explicit WMRStageOriginImpl( 120 Microsoft::WRL::ComPtr< 121 ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference> 122 stage_origin); 123 ~WMRStageOriginImpl() override; 124 125 std::unique_ptr<WMRCoordinateSystem> CoordinateSystem() override; 126 ABI::Windows::Perception::Spatial::SpatialMovementRange MovementRange() 127 override; 128 std::vector<ABI::Windows::Foundation::Numerics::Vector3> GetMovementBounds( 129 const WMRCoordinateSystem* coordinates) override; 130 131 private: 132 Microsoft::WRL::ComPtr< 133 ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReference> 134 stage_origin_; 135 136 DISALLOW_COPY_AND_ASSIGN(WMRStageOriginImpl); 137 }; 138 139 class WMRStageStatics { 140 public: 141 virtual ~WMRStageStatics() = default; 142 143 virtual std::unique_ptr<WMRStageOrigin> CurrentStage() = 0; 144 145 virtual std::unique_ptr<base::CallbackList<void()>::Subscription> 146 AddStageChangedCallback(const base::RepeatingCallback<void()>& cb) = 0; 147 }; 148 149 class WMRStageStaticsImpl : public WMRStageStatics { 150 public: 151 explicit WMRStageStaticsImpl( 152 Microsoft::WRL::ComPtr<ABI::Windows::Perception::Spatial:: 153 ISpatialStageFrameOfReferenceStatics> 154 stage_statics); 155 ~WMRStageStaticsImpl() override; 156 157 std::unique_ptr<WMRStageOrigin> CurrentStage() override; 158 159 std::unique_ptr<base::CallbackList<void()>::Subscription> 160 AddStageChangedCallback(const base::RepeatingCallback<void()>& cb) override; 161 162 private: 163 HRESULT OnCurrentChanged(IInspectable* sender, IInspectable* args); 164 Microsoft::WRL::ComPtr< 165 ABI::Windows::Perception::Spatial::ISpatialStageFrameOfReferenceStatics> 166 stage_statics_; 167 168 EventRegistrationToken stage_changed_token_; 169 base::CallbackList<void()> callback_list_; 170 171 DISALLOW_COPY_AND_ASSIGN(WMRStageStaticsImpl); 172 }; 173 } // namespace device 174 175 #endif // DEVICE_VR_WINDOWS_MIXED_REALITY_WRAPPERS_WMR_ORIGINS_H_ 176