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 * Sets whether the controller coordinate systems are shown.
86 * @param show True to show the coordinate systems; False to hide them
87 */
88 inline void showCoordinateSystems(const bool show);
89
90 /**
91 * Returns whether the controller coordinate systems are shown.
92 * @return True, if the coordinate systems are shown
93 */
94 inline bool coordinateSystemsShown() const;
95
96 protected:
97
98 /**
99 * Visualizes the coordinate system of a single controller.
100 * @param controllerIndex The index of the controller (0 = left, 1 = right)
101 * @param world_T_controller The transformation of the controller in world coordinates, must be valid
102 */
103 void visualizeControllerCoordinateSystem(const size_t controllerIndex, const HomogenousMatrix4& world_T_controller);
104
105 protected:
106
107 /// The translation offset between controller model and controller aim transformation, must be valid
108 Vector3 controllerAim_t_controllerModel_ = Vector3(Numeric::minValue(), Numeric::minValue(), Numeric::minValue());
109
110 /// The rendering Transform nodes for rendering the controller coordinate systems (one per controller).
111 Rendering::TransformRef transformCoordinateSystems_[numberControllers_];
112
113 /// The rendering VertexSet objects for rendering the controller coordinate systems (one per controller).
114 Rendering::VertexSetRef vertexSetCoordinateSystems_[numberControllers_];
115
116 /// The scene for the coordinate system visualizations.
118
119 /// True, if the controller coordinate systems are shown.
120 bool showCoordinateSystems_ = false;
121};
122
123inline VRControllerVisualizer::VRControllerVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer, const std::string& leftRenderModelFilename, const std::string& rightRenderModelFilename, const Vector3& controllerAim_t_controllerModel) :
124 Quest::Application::VRControllerVisualizer(engine, framebuffer, leftRenderModelFilename, rightRenderModelFilename),
125 controllerAim_t_controllerModel_(controllerAim_t_controllerModel)
126{
127 // nothing to do here
128}
129
134
139
140#ifdef OCEAN_PLATFORM_META_QUEST_OPENXR_USE_EXTERNAL_TRANSLATION_OFFSET
141
142/**
143 * Returns the translation offset for an external controller.
144 * @param deviceType The device type associated with the external controller, must be valid
145 * @return The translation offset, Vector3(0, 0, 0) if unknown
146 */
148
149#endif // OCEAN_PLATFORM_META_QUEST_OPENXR_USE_EXTERNAL_TRANSLATION_OFFSET
150
151}
152
153}
154
155}
156
157}
158
159}
160
161}
162
163#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:120
Rendering::SceneRef sceneCoordinateSystems_
The scene for the coordinate system visualizations.
Definition openxr/application/VRControllerVisualizer.h:117
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:130
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 coordinateSystemsShown() const
Returns whether the controller coordinate systems are shown.
Definition openxr/application/VRControllerVisualizer.h:135
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
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