Ocean
Loading...
Searching...
No Matches
VRVisualizer.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_APPLICATION_VR_VISUALIZER_H
9#define META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_VISUALIZER_H
10
12
14
15#include "ocean/math/Numeric.h"
16#include "ocean/math/Vector2.h"
17
20
21namespace Ocean
22{
23
24namespace Platform
25{
26
27namespace Meta
28{
29
30namespace Quest
31{
32
33namespace Application
34{
35
36/**
37 * This class implements the base class for all VR visualizers allowing to visualize e.g., images or text in an Ocean-based VR application (e.g., VRNativeApplication).
38 * The visualize allows to place the visuals at arbitrary locations in the 3D environment, to update the visuals, or to remove them again.
39 * @see VRNativeApplication.
40 * @ingroup platformmetaquestapplication
41 */
43{
44 public:
45
46 /**
47 * Definition of a size object allowing to specify either width and height, or only width, or only height.
48 */
50 {
51 public:
52
53 /**
54 * Creates a new size object with invalid value.
55 */
56 inline ObjectSize();
57
58 /**
59 * Creates a new size object
60 * The size object can be specified with either width and height, or only width, or only height.<br>
61 * In case width and height is specified, the resulting visualization will have the desired width and height in object space (regardless of the actual aspect ratio of the object to visualize).<br>
62 * In case either width or height is specified, the resulting visualization will have either the desired width or height in object space (and will preserve the aspect ratio of the object to visualize).
63 * @param width The width of the object, with range [0, infinity)
64 * @param height The height of the object, with range [0, infinity)
65 */
66 inline ObjectSize(const Scalar width, const Scalar height = 0);
67
68 /**
69 * Returns the width value.
70 * @return The object width
71 */
72 inline Scalar width() const;
73
74 /**
75 * Returns the width value.
76 * @return The object width
77 */
78 inline Scalar height() const;
79
80 /**
81 * Returns the desired extent in object space for a given reference width and height (mainly for the reference aspect ratio).
82 * The resulting extent will preserve the aspect ratio of the reference values as long as either width or height is specified in this size object.
83 * @param referenceWidth The width of the reference object for which the desired extent will be determined, with range (0, infinity)
84 * @param referenceHeight The height of the reference object for which the desired extent will be determined, with range (0, infinity)
85 */
86 inline Vector2 size(const Scalar referenceWidth, const Scalar referenceHeight) const;
87
88 /**
89 * Returns whether this object has at least one value size value.
90 * @return True, if so
91 */
92 inline bool isValid() const;
93
94 protected:
95
96 /// The width, if any.
98
99 /// the object height, if any.
101 };
102
103 public:
104
105 /**
106 * Returns whether the visualizer has been initialized correctly and thus can be used.
107 * @return True, if so
108 */
109 inline bool isValid() const;
110
111 /**
112 * Returns whether the visualizer has been initialized correctly and thus can be used.
113 * @return True, if so
114 */
115 explicit inline operator bool() const;
116
117 protected:
118
119 /**
120 * Default constructor, creates a new invalid visualizer.
121 */
122 inline VRVisualizer() = default;
123
124 /**
125 * Default destructor.
126 */
127 virtual ~VRVisualizer() = default;
128
129 /**
130 * Creates a new text visualizer and initializes the object with a given rendering engine and associated framebuffer.
131 * Rendering engine and framebuffer are necessary so that the rendering objects (like Scene, Transform, Texture2D) can be created and attached to the existing rendering objects.
132 * @param engine The rendering engine to be used, must be valid
133 * @param framebuffer The framebuffer to be used, must be valid
134 */
135 inline VRVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer);
136
137 /**
138 * Disable the copy constructor
139 * @param vrVisualizer The other instance that would have been copied to this instance
140 */
141 VRVisualizer(const VRVisualizer& vrVisualizer) = delete;
142
143 /**
144 * Move constructor
145 * @param vrVisualizer The other instance that will be moved to this instance
146 */
147 inline VRVisualizer(VRVisualizer&& vrVisualizer);
148
149 /**
150 * Disable the copy assignment operator
151 * @param vrVisualizer The other instance that would have been copied to this instance
152 */
153 VRVisualizer& operator=(const VRVisualizer& vrVisualizer) = delete;
154
155 /**
156 * The move assignment operator
157 * @param vrVisualizer The other instance that will be moved to this instance
158 */
159 inline VRVisualizer& operator=(VRVisualizer&& vrVisualizer);
160
161 protected:
162
163 /// The rendering engine to be used for visualization
165
166 /// The rendering framebuffer to be used for visualization.
168
169 /// The visualizer's lock.
170 mutable Lock lock_;
171};
172
174{
175 ocean_assert(!isValid());
176}
177
179 width_(width),
181{
182 ocean_assert(width_ >= 0);
183 ocean_assert(height_ >= 0);
184}
185
187{
188 return width_;
189}
190
192{
193 return height_;
194}
195
196inline Vector2 VRVisualizer::ObjectSize::size(const Scalar referenceWidth, const Scalar referenceHeight) const
197{
198 ocean_assert(isValid());
199 ocean_assert(referenceWidth > Numeric::eps() && referenceHeight > Numeric::eps());
200
202 {
203 return Vector2(width_, height_);
204 }
205
206 const Scalar referenceAspectRatio = Numeric::ratio(referenceWidth, referenceHeight);
207
209 {
210 ocean_assert(Numeric::isNotEqualEps(referenceAspectRatio));
211 return Vector2(width_, width_ / referenceAspectRatio);
212 }
213 else
214 {
215 return Vector2(height_ * referenceAspectRatio, height_);
216 }
217}
218
223
225 engine_(engine),
226 framebuffer_(framebuffer)
227{
228 ocean_assert(engine_ && framebuffer_);
229}
230
233{
234 *this = std::move(vrVisualizer);
235}
236
238{
239 if (this != &vrVisualizer)
240 {
241 engine_ = std::move(vrVisualizer.engine_);
242 framebuffer_ = std::move(vrVisualizer.framebuffer_);
243 }
244
245 return *this;
246};
247
248inline bool VRVisualizer::isValid() const
249{
250 return engine_ && framebuffer_;
251}
252
253inline VRVisualizer::operator bool() const
254{
255 return isValid();
256}
257
258}
259
260}
261
262}
263
264}
265
266}
267
268#endif // META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_VISUALIZER_H
This class implements a recursive lock object.
Definition Lock.h:31
static constexpr Scalar eps()
static constexpr Scalar ratio(const Scalar nominator, const Scalar denominator, const Scalar fallback=Scalar(1))
static constexpr bool isNotEqualEps(const Scalar value)
Vector2 size(const Scalar referenceWidth, const Scalar referenceHeight) const
Returns the desired extent in object space for a given reference width and height (mainly for the ref...
Definition VRVisualizer.h:196
bool isValid() const
Returns whether this object has at least one value size value.
Definition VRVisualizer.h:219
ObjectSize()
Creates a new size object with invalid value.
Definition VRVisualizer.h:173
Scalar height_
the object height, if any.
Definition VRVisualizer.h:100
Scalar width() const
Returns the width value.
Definition VRVisualizer.h:186
Scalar height() const
Returns the width value.
Definition VRVisualizer.h:191
Scalar width_
The width, if any.
Definition VRVisualizer.h:97
VRVisualizer(const VRVisualizer &vrVisualizer)=delete
Disable the copy constructor.
Rendering::EngineRef engine_
The rendering engine to be used for visualization.
Definition VRVisualizer.h:164
virtual ~VRVisualizer()=default
Default destructor.
VRVisualizer()=default
Default constructor, creates a new invalid visualizer.
Lock lock_
The visualizer's lock.
Definition VRVisualizer.h:170
VRVisualizer & operator=(const VRVisualizer &vrVisualizer)=delete
Disable the copy assignment operator.
bool isValid() const
Returns whether the visualizer has been initialized correctly and thus can be used.
Definition VRVisualizer.h:248
Rendering::WindowFramebufferRef framebuffer_
The rendering framebuffer to be used for visualization.
Definition VRVisualizer.h:167
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
float Scalar
Definition of a scalar type.
Definition Math.h:129
Ocean::ObjectRef< Engine > EngineRef
Definition of an engine reference object.
Definition Engine.h:30
SmartObjectRef< WindowFramebuffer > WindowFramebufferRef
Definition of a smart object reference holding a window framebuffer node.
Definition rendering/WindowFramebuffer.h:28
SmartObjectRef< Framebuffer > FramebufferRef
Definition of a smart object reference holding a framebuffer.
Definition rendering/Framebuffer.h:38
Namespace of the Platform Meta Quest Application library.
Definition meta/quest/application/Application.h:26
Namespace of the Platform Meta Quest library.
Definition meta/quest/application/Application.h:23
Namespace of the Platform Meta library.
Definition Meta.h:20
Namespace of the Platform library.
Definition platform/android/Android.h:21
The namespace covering the entire Ocean framework.
Definition Accessor.h:15