Ocean
Loading...
Searching...
No Matches
openxr/application/VRControllerVisualizer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_CONTROLLER_VISUALIZER_H
9#define META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_CONTROLLER_VISUALIZER_H
10
12
14
16
20
21namespace Ocean
22{
23
24namespace Platform
25{
26
27namespace Meta
28{
29
30namespace Quest
31{
32
33namespace OpenXR
34{
35
36namespace Application
37{
38
39/**
40 * This class implements helper functions allowing to visualize the controllers of Quest headsets in an Ocean-based VR application (e.g., VRNativeApplication) using OpenXR as input.
41 * @see VRNativeApplication.
42 * @ingroup platformmetaquestopenxrapplication
43 */
44class OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_EXPORT VRControllerVisualizer final : public Quest::Application::VRControllerVisualizer
45{
46 protected:
47
48 /// The number of controllers.
49 static constexpr size_t numberControllers_ = 2;
50
51 public:
52
53 /**
54 * Default constructor.
55 */
57
58 /**
59 * Creates a new controller visualizer and initializes the object with a given rendering engine and associated framebuffer and load the models from the specified files
60 * @param engine The rendering engine to be used, must be valid
61 * @param framebuffer The framebuffer to be used, must be valid
62 * @param leftRenderModelFilename The path to file that contains the render model of the left controller, must be valid
63 * @param rightRenderModelFilename The path to file that contains the render model of the right controller, must be valid
64 * @param controllerAim_t_controllerModel The translation offset between controller model and controller aim transformation, must be valid
65 * @see Quest::Application::VRControllerVisualizer::VRControllerVisualizer().
66 */
67 inline VRControllerVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer, const std::string& leftRenderModelFilename, const std::string& rightRenderModelFilename, const Vector3& controllerAim_t_controllerModel = Vector3(0, 0, 0));
68
69 /**
70 * Creates a new controller visualizer and initializes the object with a given rendering engine and associated framebuffer and load the models from the specified files
71 * @see Quest::Application::VRControllerVisualizer::VRControllerVisualizer().
72 */
73 VRControllerVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer, const Device::DeviceType deviceType, const std::string& renderModelDirectoryName);
74
75 /**
76 * Visualizes both controllers of an Oculus headset at a specific location in the virtual environment (defined in relation to the world).
77 * A previous visualization can be updated by specifying the same controller again in conjunction with a new transformation.
78 * Beware: The visualizer must be created with a valid engine and framebuffer before usage.
79 * @param trackedController The instance of a tracked controller that is used to query the pose of the controllers, must be valid
80 * @param controllerRayLength Optional explicit parameter used for the length of the controller ray, will be hidden for value 0, -1 to use the length as defined in controllerRayLength()
81 */
82 void visualizeControllersInWorld(const TrackedController& trackedController, const Scalar controllerRayLength = -1);
83
84 /**
85 * Computes the transformation of the controller render model relative to base space.
86 * Applies the same offsets that visualizeControllersInWorld uses to place the rendered controller model,
87 * so callers can align other content (e.g. virtual markers or coordinate systems) with the rendered controller.
88 * @param trackedController The instance of a tracked controller used to query the controller pose, must be valid
89 * @param controllerType The type of the controller (CT_LEFT or CT_RIGHT)
90 * @param baseSpace_T_controllerModel The resulting transformation of the controller model in base space (only valid if true is returned)
91 * @return True if the pose could be obtained and the transformation was computed; false otherwise
92 */
93 bool baseSpaceFromControllerModel(const TrackedController& trackedController, const TrackedController::ControllerType controllerType, HomogenousMatrix4& baseSpace_T_controllerModel) const;
94
95 /**
96 * Sets whether the controller coordinate systems are shown.
97 * @param show True to show the coordinate systems; False to hide them
98 */
99 inline void showCoordinateSystems(const bool show);
100
101 /**
102 * Returns whether the controller coordinate systems are shown.
103 * @return True, if the coordinate systems are shown
104 */
105 inline bool coordinateSystemsShown() const;
106
107 protected:
108
109 /**
110 * Visualizes the coordinate system of a single controller.
111 * @param controllerIndex The index of the controller (0 = left, 1 = right)
112 * @param world_T_controller The transformation of the controller in world coordinates, must be valid
113 */
114 void visualizeControllerCoordinateSystem(const size_t controllerIndex, const HomogenousMatrix4& world_T_controller);
115
116 protected:
117
118 /// The translation offset between controller model and controller aim transformation, must be valid
119 Vector3 controllerAim_t_controllerModel_ = Vector3(Numeric::minValue(), Numeric::minValue(), Numeric::minValue());
120
121 /// The rendering Transform nodes for rendering the controller coordinate systems (one per controller).
122 Rendering::TransformRef transformCoordinateSystems_[numberControllers_];
123
124 /// The rendering VertexSet objects for rendering the controller coordinate systems (one per controller).
125 Rendering::VertexSetRef vertexSetCoordinateSystems_[numberControllers_];
126
127 /// The scene for the coordinate system visualizations.
129
130 /// True, if the controller coordinate systems are shown.
131 bool showCoordinateSystems_ = false;
132};
133
134inline VRControllerVisualizer::VRControllerVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer, const std::string& leftRenderModelFilename, const std::string& rightRenderModelFilename, const Vector3& controllerAim_t_controllerModel) :
135 Quest::Application::VRControllerVisualizer(engine, framebuffer, leftRenderModelFilename, rightRenderModelFilename),
136 controllerAim_t_controllerModel_(controllerAim_t_controllerModel)
137{
138 // nothing to do here
139}
140
145
150
151#ifdef OCEAN_PLATFORM_META_QUEST_OPENXR_USE_EXTERNAL_TRANSLATION_OFFSET
152
153/**
154 * Returns the translation offset for an external controller.
155 * @param deviceType The device type associated with the external controller, must be valid
156 * @return The translation offset, Vector3(0, 0, 0) if unknown
157 */
159
160#endif // OCEAN_PLATFORM_META_QUEST_OPENXR_USE_EXTERNAL_TRANSLATION_OFFSET
161
162}
163
164}
165
166}
167
168}
169
170}
171
172}
173
174#endif // META_OCEAN_PLATFORM_META_QUEST_OPENXR_APPLICATION_VR_CONTROLLER_VISUALIZER_H
This class implements helper functions allowing to visualize the controllers of Quest headsets in an ...
Definition application/VRControllerVisualizer.h:41
void show()
Shows the controllers.
Definition application/VRControllerVisualizer.h:335
DeviceType
Definition of individual device types.
Definition platform/meta/quest/Device.h:37
This class implements helper functions allowing to visualize the controllers of Quest headsets in an ...
Definition openxr/application/VRControllerVisualizer.h:45
bool showCoordinateSystems_
True, if the controller coordinate systems are shown.
Definition openxr/application/VRControllerVisualizer.h:131
Rendering::SceneRef sceneCoordinateSystems_
The scene for the coordinate system visualizations.
Definition openxr/application/VRControllerVisualizer.h:128
VRControllerVisualizer(const Rendering::EngineRef &engine, const Rendering::FramebufferRef framebuffer, const Device::DeviceType deviceType, const std::string &renderModelDirectoryName)
Creates a new controller visualizer and initializes the object with a given rendering engine and asso...
void showCoordinateSystems(const bool show)
Sets whether the controller coordinate systems are shown.
Definition openxr/application/VRControllerVisualizer.h:141
void visualizeControllersInWorld(const TrackedController &trackedController, const Scalar controllerRayLength=-1)
Visualizes both controllers of an Oculus headset at a specific location in the virtual environment (d...
bool baseSpaceFromControllerModel(const TrackedController &trackedController, const TrackedController::ControllerType controllerType, HomogenousMatrix4 &baseSpace_T_controllerModel) const
Computes the transformation of the controller render model relative to base space.
bool coordinateSystemsShown() const
Returns whether the controller coordinate systems are shown.
Definition openxr/application/VRControllerVisualizer.h:146
void visualizeControllerCoordinateSystem(const size_t controllerIndex, const HomogenousMatrix4 &world_T_controller)
Visualizes the coordinate system of a single controller.
This class implements a wrapper for tracker controllers.
Definition TrackedController.h:40
ControllerType
Definition of individual controller types.
Definition TrackedController.h:91
float Scalar
Definition of a scalar type.
Definition Math.h:129
Vector3 VRControllerVisualizer_externalTranslationOffset(const uint32_t deviceType)
Returns the translation offset for an external controller.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15