SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLHorizonNode Class Reference

#include <SLHorizonNode.h>

Inheritance diagram for SLHorizonNode:
[legend]

Public Member Functions

 SLHorizonNode (SLstring name, SLDeviceRotation *devRot, SLTexFont *font, SLstring shaderDir, int scrW, int scrH)
 Construct a new SLHorizonNode::SLHorizonNode object. More...
 
 ~SLHorizonNode ()
 
void doUpdate () override
 
- Public Member Functions inherited from SLNode
 SLNode (const SLstring &name="Node")
 Construct a new SLNode::SLNode object. More...
 
 SLNode (SLMesh *mesh, const SLstring &name="Node")
 
 SLNode (SLMesh *mesh, const SLVec3f &translation, const SLstring &name)
 
 ~SLNode () override
 
virtual void cull3DRec (SLSceneView *sv)
 
virtual void cullChildren3D (SLSceneView *sv)
 Initializer function to call SLNode::cull3DRec recursively. More...
 
virtual void cull2DRec (SLSceneView *sv)
 
virtual bool hitRec (SLRay *ray)
 
virtual void statsRec (SLNodeStats &stats)
 
virtual SLNodecopyRec ()
 
virtual SLAABBoxupdateAABBRec (SLbool updateAlsoAABBinOS)
 
virtual void dumpRec ()
 
void setDrawBitsRec (SLuint bit, SLbool state)
 
void setPrimitiveTypeRec (SLGLPrimitiveType primitiveType)
 
virtual void addMesh (SLMesh *mesh)
 
virtual void drawMesh (SLSceneView *sv)
 Draws the single mesh. More...
 
bool removeMesh ()
 Returns true if a mesh was assigned and set it to nullptr. More...
 
bool removeMesh (SLMesh *mesh)
 Returns true if the passed mesh was assigned and sets it to nullptr. More...
 
SLint numChildren ()
 
void addChild (SLNode *child)
 
bool insertChild (SLNode *insertC, SLNode *afterC)
 
void deleteChildren ()
 
bool deleteChild ()
 
bool deleteChild (SLNode *child)
 
bool deleteChild (const SLstring &name)
 
bool removeChild (SLNode *child)
 remove child from vector of children. Removes false if not found, else true. More...
 
template<typename T >
T * find (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
T * findChild (const SLstring &name="", SLbool findRecursive=true)
 
template<typename T >
deque< T * > findChildren (const SLstring &name="", SLbool findRecursive=true, SLbool canContain=false)
 
deque< SLNode * > findChildren (const SLMesh *mesh, SLbool findRecursive=true)
 
deque< SLNode * > findChildren (SLuint drawbit, SLbool findRecursive=true)
 
SLVec3f translationOS () const
 
SLVec3f forwardOS () const
 
SLVec3f rightOS () const
 
SLVec3f upOS () const
 
SLVec3f axisXOS () const
 
SLVec3f axisYOS () const
 
SLVec3f axisZOS () const
 
SLVec3f translationWS () const
 
SLVec3f forwardWS () const
 
SLVec3f rightWS () const
 
SLVec3f upWS () const
 
SLVec3f axisXWS () const
 
SLVec3f axisYWS () const
 
SLVec3f axisZWS () const
 
void translation (const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
 
void translation (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_parent)
 
void rotation (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
 
void rotation (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_parent)
 
void scaling (SLfloat s)
 
void scaling (SLfloat x, SLfloat y, SLfloat z)
 
void scaling (const SLVec3f &scaling)
 
void lookAt (SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
 
void lookAt (const SLVec3f &target, const SLVec3f &up=SLVec3f::AXISY, SLTransformSpace relativeTo=TS_world)
 
void translate (const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
 
void translate (SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotate (const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, const SLVec3f &axis, SLTransformSpace relativeTo=TS_object)
 
void rotate (SLfloat angleDeg, SLfloat x, SLfloat y, SLfloat z, SLTransformSpace relativeTo=TS_object)
 
void rotateAround (const SLVec3f &point, SLVec3f &axis, SLfloat angleDeg, SLTransformSpace relativeTo=TS_world)
 
void scale (SLfloat s)
 
void scale (SLfloat x, SLfloat y, SLfloat z)
 
void scale (const SLVec3f &scale)
 
void scaleToCenter (SLfloat maxDim)
 
void setInitialState ()
 
void resetToInitialState ()
 
void parent (SLNode *p)
 
void entityID (SLint entityID)
 
void om (const SLMat4f &mat)
 
void animation (SLAnimation *a)
 
void castsShadows (SLbool castsShadows)
 
virtual void needUpdate ()
 
void needWMUpdate ()
 
void needAABBUpdate ()
 
void isSelected (bool isSelected)
 
void minLodCoverage (SLfloat minLodCoverage)
 
void levelForSM (SLubyte lfsm)
 
void onUpdateCB (function< void()> callbackFunc)
 
SLNodeparent ()
 
SLint depth () const
 
SLint entityID () const
 
const SLMat4fom ()
 
const SLMat4finitialOM ()
 
const SLMat4fupdateAndGetWM () const
 
const SLMat4fupdateAndGetWMI () const
 
SLDrawBitsdrawBits ()
 
SLbool drawBit (SLuint bit)
 
SLAABBoxaabb ()
 
SLAnimationanimation ()
 
SLbool castsShadows ()
 
SLMeshmesh ()
 
SLVNodechildren ()
 
const SLAnimSkeletonskeleton ()
 Returns the first skeleton found in the meshes. More...
 
void updateRec ()
 
bool updateMeshSkins (bool forceCPUSkinning, const std::function< void(SLMesh *)> &cbInformNodes)
 Update all skinned meshes recursively. More...
 
void updateMeshAccelStructs ()
 
void updateMeshMat (std::function< void(SLMaterial *m)> setMat, bool recursive)
 Updates the mesh material recursively with a material lambda. More...
 
void setMeshMat (SLMaterial *mat, bool recursive)
 Set the mesh material recursively. More...
 
bool isSelected ()
 
SLfloat minLodCoverage ()
 
SLubyte levelForSM ()
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 
- Public Member Functions inherited from SLEventHandler
 SLEventHandler ()
 
virtual ~SLEventHandler ()
 
virtual SLbool onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod)
 
virtual SLbool onMouseWheel (const SLint delta, const SLKey mod)
 
virtual SLbool onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2)
 
virtual SLbool onTouch3Down (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Move (const SLint x1, const SLint y1)
 
virtual SLbool onTouch3Up (const SLint x1, const SLint y1)
 
virtual SLbool onKeyPress (const SLKey key, const SLKey mod)
 
virtual SLbool onKeyRelease (const SLKey key, const SLKey mod)
 
virtual SLbool onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD)
 
void mouseRotationFactor (SLfloat rf)
 
SLfloat mouseRotationFactor ()
 

Private Attributes

SLDeviceRotation_devRot = nullptr
 
SLTexFont_font = nullptr
 
SLstring _shaderDir
 
SLGLProgram_prog = nullptr
 
SLMaterial_mat = nullptr
 
SLPolyline_line = nullptr
 
SLNode_horizonNode = nullptr
 
SLNode_textNode = nullptr
 
SLMat3f _sRc
 

Additional Inherited Members

- Static Public Attributes inherited from SLNode
static SLuint numWMUpdates = 0
 NO. of calls to updateWMRec per frame. More...
 
static unsigned int instanceIndex = 0
 ??? More...
 
- Protected Attributes inherited from SLNode
SLNode_parent
 pointer to the parent node More...
 
SLVNode _children
 vector of children nodes More...
 
SLMesh_mesh
 pointer to a single mesh More...
 
SLint _depth
 depth of the node in a scene tree More...
 
SLint _entityID
 ID in the SLVEntity graph for Data Oriented Design. More...
 
SLMat4f _om
 object matrix for local transforms More...
 
SLMat4f _initialOM
 the initial om state More...
 
SLMat4f _wm
 world matrix for world transform More...
 
SLMat4f _wmI
 inverse world matrix More...
 
SLbool _isWMUpToDate
 is the WM of this node still valid More...
 
SLbool _isWMIUpToDate
 is the inverse WM of this node still valid More...
 
SLbool _isAABBUpToDate
 is the saved aabb still valid More...
 
bool _castsShadows
 flag if meshes of node should cast shadows More...
 
bool _isSelected
 flag if node and one or more of its meshes are selected More...
 
SLDrawBits _drawBits
 node level drawing flags More...
 
SLAABBox _aabb
 axis aligned bounding box More...
 
SLAnimation_animation
 animation of the node More...
 
SLfloat _minLodCoverage
 Min. LOD coverage for visibility (0.0 < _minLodCoverage < 1.0) More...
 
SLubyte _levelForSM
 Level of LOD to use for shadow mapping (0 = the visible one will be drawn) More...
 
function< void()> _onUpdateCB
 Optional lambda callback once per update. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 
- Protected Attributes inherited from SLEventHandler
SLfloat _mouseRotationFactor
 Mouse rotation sensibility. More...
 
SLfloat _keyboardDeltaPos
 Delta dist. for keyboard translation. More...
 

Detailed Description

Definition at line 22 of file SLHorizonNode.h.

Constructor & Destructor Documentation

◆ SLHorizonNode()

SLHorizonNode::SLHorizonNode ( SLstring  name,
SLDeviceRotation devRot,
SLTexFont font,
SLstring  shaderDir,
int  scrW,
int  scrH 
)

Construct a new SLHorizonNode::SLHorizonNode object.

Remarks
It is important that during instantiation NO OpenGL functions (gl*) get called because this constructor will be most probably called in a parallel thread from within an SLScene::registerAssetsToLoad or SLScene::assemble function. All objects that get rendered have to do their OpenGL initialization when they are used the first time during rendering in the main thread.
Parameters
nameName of the node
devRotDevice rotation object
fontFont for the text label
shaderDirPath to the shader directory
scrWWidth of the screen in pixels
scrHHeight of the sceen in pixels

Definition at line 30 of file SLHorizonNode.cpp.

36  : SLNode(name),
37  _devRot(devRot),
38  _font(font),
39  _shaderDir(shaderDir)
40 {
41  // make sure device rotation is enabled
42  if (!_devRot->isUsed())
43  _devRot->isUsed(true);
44 
45  // rotation of camera w.r.t sensor
46  _sRc.rotation(-90, 0, 0, 1);
47 
48  // init visualization node and meshes
49  //(this node is owner of instantiated programs, meshes and materials)
50  _prog = new SLGLProgramGeneric(nullptr,
51  shaderDir + "ColorUniformPoint.vert",
52  shaderDir + "Color.frag");
54  "u_pointSize",
55  1.0f));
56  _mat = new SLMaterial(nullptr, _prog, SLCol4f::WHITE, "White");
57  // define mesh points
58  int refLen = std::min(scrW, scrH);
59  SLfloat cs; // center size
60  if (_font)
61  {
62  SLfloat scale = 1.f;
63  SLstring txt = "-359.9";
64  SLVec2f size = _font->calcTextSize(txt);
65  cs = size.x;
66  }
67  else
68  cs = (float)refLen * 0.01f; // center size
69 
70  float l = (float)refLen * 0.35f;
71 
72  SLVVec3f points = {{-l, 0, 0},
73  {-cs, 0, 0},
74  {0, -cs, 0},
75  {cs, 0, 0},
76  {l, 0, 0},
77  {cs, 0, 0},
78  {0, cs, 0},
79  {-cs, 0, 0}};
80 
81  _line = new SLPolyline(nullptr,
82  points,
83  true,
84  "Horizon line",
85  _mat);
86  _horizonNode = new SLNode(_line, "Horizon node");
87  this->addChild(_horizonNode);
88 }
float SLfloat
Definition: SL.h:173
string SLstring
Definition: SL.h:158
@ UT_const
constant value
Definition: SLEnums.h:233
SLGLUniform< SLfloat > SLGLUniform1f
Definition: SLGLUniform.h:149
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
void isUsed(SLbool isUsed)
Setter that turns on the device rotation sensor.
Generic Shader Program class inherited from SLGLProgram.
void addUniform1f(SLGLUniform1f *u)
add float uniform
SLGLProgram * _prog
Definition: SLHorizonNode.h:40
SLTexFont * _font
Definition: SLHorizonNode.h:37
SLNode * _horizonNode
Definition: SLHorizonNode.h:43
SLstring _shaderDir
Definition: SLHorizonNode.h:38
SLPolyline * _line
Definition: SLHorizonNode.h:42
SLDeviceRotation * _devRot
Definition: SLHorizonNode.h:36
SLMaterial * _mat
Definition: SLHorizonNode.h:41
void rotation(const T angleDEG, const SLVec3< T > &axis)
Sets the rotation components
Definition: SLMat3.h:392
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void scale(SLfloat s)
Definition: SLNode.h:640
SLNode(const SLstring &name="Node")
Construct a new SLNode::SLNode object.
Definition: SLNode.cpp:40
const SLstring & name() const
Definition: SLObject.h:38
SLPolyline creates a polyline object.
Definition: SLPolyline.h:23
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
Definition: SLTexFont.cpp:243
T x
Definition: SLVec2.h:30
static SLVec4 WHITE
Definition: SLVec4.h:215

◆ ~SLHorizonNode()

SLHorizonNode::~SLHorizonNode ( )

Definition at line 90 of file SLHorizonNode.cpp.

91 {
92  delete _prog;
93  delete _mat;
94  delete _line;
95 }

Member Function Documentation

◆ doUpdate()

void SLHorizonNode::doUpdate ( )
overridevirtual

Reimplemented from SLNode.

Definition at line 97 of file SLHorizonNode.cpp.

98 {
99  // get latest orientation and update horizon
100  SLVec3f horizon;
102 
103  // rotate node to align it to horizon
104  float horizonAngle = std::atan2(horizon.y, horizon.x) * RAD2DEG;
105  _horizonNode->rotation(horizonAngle,
106  SLVec3f(0, 0, 1),
108 
109  // update text
110  if (_font)
111  {
112  if (_textNode)
113  this->deleteChild(_textNode);
114 
115  stringstream ss;
116  // we invert the sign to express the rotation of the device w.r.t the horizon
117  ss << std::fixed << std::setprecision(1) << -horizonAngle;
118  SLstring txt = ss.str();
119 
120  SLVec2f size = _font->calcTextSize(txt);
121  _textNode = new SLText(txt, _font, SLCol4f::WHITE);
122  _textNode->translate(-size.x * 0.5f, -size.y * 0.5f, 0);
123  this->addChild(_textNode);
124  }
125 }
@ TS_object
Definition: SLEnums.h:210
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLMat3f rotationAveraged()
SLNode * _textNode
Definition: SLHorizonNode.h:44
void rotation(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:846
bool deleteChild()
Definition: SLNode.cpp:267
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30
T y
Definition: SLVec2.h:30
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
bool estimateHorizon(const SLMat3f &enuRs, const SLMat3f &sRc, SLVec3f &horizon)
Definition: SLAlgo.cpp:17
static const float RAD2DEG
Definition: Utils.h:238

Member Data Documentation

◆ _devRot

SLDeviceRotation* SLHorizonNode::_devRot = nullptr
private

Definition at line 36 of file SLHorizonNode.h.

◆ _font

SLTexFont* SLHorizonNode::_font = nullptr
private

Definition at line 37 of file SLHorizonNode.h.

◆ _horizonNode

SLNode* SLHorizonNode::_horizonNode = nullptr
private

Definition at line 43 of file SLHorizonNode.h.

◆ _line

SLPolyline* SLHorizonNode::_line = nullptr
private

Definition at line 42 of file SLHorizonNode.h.

◆ _mat

SLMaterial* SLHorizonNode::_mat = nullptr
private

Definition at line 41 of file SLHorizonNode.h.

◆ _prog

SLGLProgram* SLHorizonNode::_prog = nullptr
private

Definition at line 40 of file SLHorizonNode.h.

◆ _shaderDir

SLstring SLHorizonNode::_shaderDir
private

Definition at line 38 of file SLHorizonNode.h.

◆ _sRc

SLMat3f SLHorizonNode::_sRc
private

Definition at line 46 of file SLHorizonNode.h.

◆ _textNode

SLNode* SLHorizonNode::_textNode = nullptr
private

Definition at line 44 of file SLHorizonNode.h.


The documentation for this class was generated from the following files: