SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLHorizonNode.h
Go to the documentation of this file.
1 /**
2  * \file SLHorizonNode.h
3  * \brief Scene node that draws the device's horizon line and tilt angle
4  * \date November 2020
5  * \authors Michael Göttlicher, Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9  */
10 
11 #ifndef SL_HORIZON_NODE_H
12 #define SL_HORIZON_NODE_H
13 
14 #include <SLNode.h>
15 #include <SLTexFont.h>
16 #include <SLDeviceRotation.h>
17 #include <SLPolyline.h>
18 #include <SLGLProgramGeneric.h>
19 #include <SLMaterial.h>
20 
21 //-----------------------------------------------------------------------------
22 //! Scene node that visualises the horizon estimated from the device rotation
23 /*! The node owns two children: a polyline drawn as the horizon itself and an
24 SLText showing the roll angle in degrees. Every frame doUpdate() reads the
25 averaged rotation from the SLDeviceRotation passed to the constructor, derives
26 the horizon direction with SLAlgo::estimateHorizon and rotates the line to
27 match. The displayed angle is negated, so it expresses the rotation of the
28 device with respect to the horizon rather than the other way round.
29 
30 Intended for AR scenes on mobile devices, where it gives the user a reference
31 for how far the device is tilted. */
32 class SLHorizonNode : public SLNode
33 {
34 public:
35  //! Builds the horizon line and its text label
36  /*! \param name Name of the node
37  \param devRot Rotation sensor to read the orientation from, not owned
38  \param font Font for the angle label; if nullptr no label is shown
39  \param shaderDir Directory the line shader is loaded from
40  \param scrW Screen width in pixels, used to size the line
41  \param scrH Screen height in pixels, used to size the line */
43  SLDeviceRotation* devRot,
44  SLTexFont* font,
45  SLstring shaderDir,
46  int scrW,
47  int scrH);
48 
49  //! Deletes the program, material and meshes created in the constructor
51 
52  //! Re-aligns the horizon line and refreshes the angle label
53  /*! Called once per frame by the scene update. The text node is destroyed
54  and rebuilt on every call because the label text changes. */
55  void doUpdate() override;
56 
57 private:
58  SLDeviceRotation* _devRot = nullptr; //!< Rotation sensor, not owned
59  SLTexFont* _font = nullptr; //!< Font of the angle label, not owned
60  SLstring _shaderDir; //!< Directory of the line shader
61 
62  SLGLProgram* _prog = nullptr; //!< Program drawing the horizon line
63  SLMaterial* _mat = nullptr; //!< Material of the horizon line
64  SLPolyline* _line = nullptr; //!< Mesh of the horizon line
65  SLNode* _horizonNode = nullptr; //!< Child node carrying the line
66  SLNode* _textNode = nullptr; //!< Child node carrying the angle text
67 
68  SLMat3f _sRc; //!< Sensor to camera rotation used by the horizon estimation
69 };
70 //-----------------------------------------------------------------------------
71 #endif
string SLstring
Redefinition of standard types for platform independence.
Definition: SL.h:185
Mobile device rotation class declaration.
Encapsulation of a mobile device rotation set by the device's IMU sensor.
Encapsulation of an OpenGL shader program object.
Definition: SLGLProgram.h:56
Scene node that visualises the horizon estimated from the device rotation.
Definition: SLHorizonNode.h:33
SLGLProgram * _prog
Program drawing the horizon line.
Definition: SLHorizonNode.h:62
SLTexFont * _font
Font of the angle label, not owned.
Definition: SLHorizonNode.h:59
void doUpdate() override
Re-aligns the horizon line and refreshes the angle label.
~SLHorizonNode()
Deletes the program, material and meshes created in the constructor.
SLNode * _horizonNode
Child node carrying the line.
Definition: SLHorizonNode.h:65
SLHorizonNode(SLstring name, SLDeviceRotation *devRot, SLTexFont *font, SLstring shaderDir, int scrW, int scrH)
Builds the horizon line and its text label.
SLstring _shaderDir
Directory of the line shader.
Definition: SLHorizonNode.h:60
SLMat3f _sRc
Sensor to camera rotation used by the horizon estimation.
Definition: SLHorizonNode.h:68
SLPolyline * _line
Mesh of the horizon line.
Definition: SLHorizonNode.h:64
SLDeviceRotation * _devRot
Rotation sensor, not owned.
Definition: SLHorizonNode.h:58
SLMaterial * _mat
Material of the horizon line.
Definition: SLHorizonNode.h:63
SLNode * _textNode
Child node carrying the angle text.
Definition: SLHorizonNode.h:66
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:148
const SLstring & name() const
Definition: SLObject.h:38
SLPolyline creates a polyline object.
Definition: SLPolyline.h:23
Texture Font class inherits SLGLTexture for alpha blended font rendering.
Definition: SLTexFont.h:40