Ocean
VRTextVisualizer.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_TEXT_VISUALIZER_H
9 #define META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_TEXT_VISUALIZER_H
10 
13 
14 #include "ocean/base/Timestamp.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Platform
20 {
21 
22 namespace Meta
23 {
24 
25 namespace Quest
26 {
27 
28 namespace Application
29 {
30 
31 /**
32  * This class implements a helper function allowing to visualize text in an Ocean-based VR application (e.g., VRNativeApplication).
33  * The visualize allows to place text at arbitrary locations in the 3D environment, to update the text, or to remove the text again.<br>
34  * The `text` coordinate system of the visualization is defined as follows:
35  * <pre>
36  * Coordinate system of text, the origin is in the center of the text, the text is visualized in the local z=0 plane:
37  *
38  * (text field top-left)
39  * ---------------------------------------------
40  * | |
41  * | ^ |
42  * | | y-axis |
43  * | | |
44  * | *------> x-axis |
45  * | / |
46  * | / z-axis |
47  * | v |
48  * | |
49  * ---------------------------------------------
50  * (text field bottom-right)
51  *
52  * |<-------------- object width --------------->|
53  * </pre>
54  * The visualizer uses `CV::Fonts` to rendering the text.
55  * Custom fonts can be registered via `CV::Fonts::FontManager::get().registerFont()`.
56  * @see VRNativeApplication.
57  * @ingroup platformmetaquestapplication
58  */
59 class OCEAN_PLATFORM_META_QUEST_APPLICATION_EXPORT VRTextVisualizer : public VRVisualizer
60 {
61  public:
62 
63  /**
64  * Default constructor, creates a new invalid visualizer.
65  */
66  inline VRTextVisualizer();
67 
68  /**
69  * Creates a new text visualizer and initializes the object with a given rendering engine and associated framebuffer.
70  * 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.
71  * @param engine The rendering engine to be used, must be valid
72  * @param framebuffer The framebuffer to be used, must be valid
73  */
74  inline VRTextVisualizer(const Rendering::EngineRef& engine, const Rendering::FramebufferRef framebuffer);
75 
76  /**
77  * Visualizes a text at a specific location in the virtual environment (defined in relation to the world).
78  * A previous visualization can be updated by specifying the old id and a new text.
79  * Beware: The visualizer must be created with a valid engine and framebuffer before usage.
80  * @param id The unique id of the visualization, the same id can be used to update/change the visualization
81  * @param world_T_text The transformation at which the text will be displayed, transforming text to world, can be invalid to remove the existing visualization
82  * @param text The text to visualize, can contain end-of-line characters for multiple text lines, can be empty to remove the existing visualization
83  * @param objectSize The size of the visualized image in virtual space (in object space), an invalid object to remove the visualization
84  * @param workaroundTimestamp Current workaround: Timestamp of the rendering engine
85  * @param fontName The name of the font to be used to render the text
86  * @see visualizeTextnView().
87  */
88  inline void visualizeTextInWorld(const unsigned int id, const HomogenousMatrix4& world_T_text, const std::string& text, const ObjectSize& objectSize, const Timestamp& workaroundTimestamp = Timestamp(false), const std::string& fontName = "Roboto");
89 
90  /**
91  * Visualizes a text at a specific location in the virtual environment (defined in relation to the view).
92  * A previous visualization can be updated by specifying the old id and a new text.
93  * Beware: The visualizer must be created with a valid engine and framebuffer before usage.
94  * @param id The unique id of the visualization, the same id can be used to update/change the visualization
95  * @param view_T_text The transformation at which the text will be displayed, transforming text to view, can be invalid to remove the existing visualization
96  * @param text The text to visualize, can contain end-of-line characters for multiple text lines, can be empty to remove the existing visualization
97  * @param objectSize The size of the visualized image in virtual space (in object space), an invalid object to remove the visualization
98  * @param workaroundTimestamp Current workaround: Timestamp of the rendering engine
99  * @param fontName The name of the font to be used to render the text
100  * @see visualizeTextInWorld().
101  */
102  inline void visualizeTextInView(const unsigned int id, const HomogenousMatrix4& view_T_text, const std::string& text, const ObjectSize& objectSize, const Timestamp& workaroundTimestamp = Timestamp(false), const std::string& fontName = "Roboto");
103 
104  /**
105  * Visualizes a text at a specific location in the virtual environment (defined in relation to the world or to the view).
106  * A previous visualization can be updated by specifying the old id and a new text.
107  * Beware: The visualizer must be created with a valid engine and framebuffer before usage.
108  * @param id The unique id of the visualization, the same id can be used to update/change the visualization
109  * @param reference_T_text The transformation at which the text will be displayed, transforming text to reference (either world or view), can be invalid to remove the existing visualization
110  * @param text The text to visualize, can contain end-of-line characters for multiple text lines, can be empty to remove the existing visualization
111  * @param objectSize The size of the visualized image in virtual space (in object space), an invalid object to remove the visualization
112  * @param workaroundTimestamp Current workaround: Timestamp of the rendering engine
113  * @param referenceIsWorld True, if reference is world; False, if reference is view
114  * @param fontName The name of the font to be used to render the text
115  */
116  void visualizeText(const unsigned int id, const HomogenousMatrix4& reference_T_text, const std::string& text, const ObjectSize& objectSize, const Timestamp& workaroundTimestamp = Timestamp(false), const bool referenceIsWorld = true, const std::string& fontName = "Roboto");
117 };
118 
120 {
121  // nothing to do here
122 }
123 
125  VRVisualizer(engine, framebuffer)
126 {
127  // nothing to do here
128 }
129 
130 inline void VRTextVisualizer::visualizeTextInWorld(const unsigned int id, const HomogenousMatrix4& world_T_text, const std::string& text, const ObjectSize& objectSize, const Timestamp& workaroundTimestamp, const std::string& fontName)
131 {
132  return visualizeText(id, world_T_text, text, objectSize, workaroundTimestamp, true, fontName);
133 }
134 
135 inline void VRTextVisualizer::visualizeTextInView(const unsigned int id, const HomogenousMatrix4& world_T_text, const std::string& text, const ObjectSize& objectSize, const Timestamp& workaroundTimestamp, const std::string& fontName)
136 {
137  return visualizeText(id, world_T_text, text, objectSize, workaroundTimestamp, false, fontName);
138 }
139 
140 }
141 
142 }
143 
144 }
145 
146 }
147 
148 }
149 
150 #endif // META_OCEAN_PLATFORM_META_QUEST_APPLICATION_VR_TEXT_VISUALIZER_H
This class implements a helper function allowing to visualize text in an Ocean-based VR application (...
Definition: VRTextVisualizer.h:60
VRTextVisualizer()
Default constructor, creates a new invalid visualizer.
Definition: VRTextVisualizer.h:119
void visualizeTextInView(const unsigned int id, const HomogenousMatrix4 &view_T_text, const std::string &text, const ObjectSize &objectSize, const Timestamp &workaroundTimestamp=Timestamp(false), const std::string &fontName="Roboto")
Visualizes a text at a specific location in the virtual environment (defined in relation to the view)...
Definition: VRTextVisualizer.h:135
void visualizeTextInWorld(const unsigned int id, const HomogenousMatrix4 &world_T_text, const std::string &text, const ObjectSize &objectSize, const Timestamp &workaroundTimestamp=Timestamp(false), const std::string &fontName="Roboto")
Visualizes a text at a specific location in the virtual environment (defined in relation to the world...
Definition: VRTextVisualizer.h:130
void visualizeText(const unsigned int id, const HomogenousMatrix4 &reference_T_text, const std::string &text, const ObjectSize &objectSize, const Timestamp &workaroundTimestamp=Timestamp(false), const bool referenceIsWorld=true, const std::string &fontName="Roboto")
Visualizes a text at a specific location in the virtual environment (defined in relation to the world...
Definition of a size object allowing to specify either width and height, or only width,...
Definition: VRVisualizer.h:50
This class implements the base class for all VR visualizers allowing to visualize e....
Definition: VRVisualizer.h:43
This class implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15