23#ifndef VCL_BGFX_DRAWERS_VIEWER_DRAWER_H
24#define VCL_BGFX_DRAWERS_VIEWER_DRAWER_H
26#include <vclib/render/drawers/abstract_viewer_drawer.h>
28#include <vclib/bgfx/drawable/drawable_axis.h>
29#include <vclib/bgfx/drawable/drawable_directional_light.h>
30#include <vclib/bgfx/drawable/drawable_trackball.h>
31#include <vclib/bgfx/drawable/uniforms/camera_uniforms.h>
32#include <vclib/bgfx/drawable/uniforms/directional_light_uniforms.h>
33#include <vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h>
37template<
typename DerivedRenderApp>
41 using DTB = ParentViewer::DTB;
51 bool mStatsEnabled =
false;
57 mCameraUniforms.updateCamera(DTB::camera());
58 mDirectionalLightUniforms.
updateLight(DTB::light());
62 const std::shared_ptr<DrawableObjectVector>& v,
66 ParentViewer::setDrawableObjectVector(v);
69 void onInit(uint viewId)
override
71 ParentViewer::onInit(viewId);
73 mDirectionalLight.
init();
74 mDrawTrackBall.
init();
77 void onDraw(uint viewId)
override
79 onDrawContent(viewId);
86 mDirectionalLight.
draw(viewId);
90 mDrawTrackBall.
draw(viewId);
94 void onDrawContent(uint viewId)
override
96 setDirectionalLightVisibility(
97 DTB::currentMotion() == DTB::TrackBallType::DIR_LIGHT_ARC);
98 updateDirectionalLight();
99 updateDrawableTrackball();
101 bgfx::setViewTransform(
102 viewId, DTB::viewMatrix().data(), DTB::projectionMatrix().data());
104 mCameraUniforms.updateCamera(DTB::camera());
105 mCameraUniforms.bind();
107 mDirectionalLightUniforms.bind();
109 ParentViewer::drawableObjectVector().draw(viewId);
114 if (key == Key::F1) {
116 mStatsEnabled =
false;
120 mStatsEnabled =
true;
124 ParentViewer::onKeyPress(key,
modifiers);
127 void onMouseDoubleClick(
139 void toggleAxisVisibility()
override
144 void toggleTrackBallVisibility()
override
150 bool isDirectionalLightVisible()
const
155 void setDirectionalLightVisibility(
bool b)
160 void updateDirectionalLight()
162 auto v = DTB::lightGizmoMatrix();
163 mDirectionalLight.updateRotation(v);
164 mDirectionalLightUniforms.
updateLight(DTB::light());
167 void updateDrawableTrackball()
169 auto v = DTB::gizmoMatrix();
170 mDrawTrackBall.setTransform(v);
The AbstractViewerDrawer class is a base class for all viewer drawers implementations.
Definition abstract_viewer_drawer.h:49
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:365
Definition drawable_axis.h:41
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_axis.h:124
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_axis.cpp:41
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_axis.h:122
Definition drawable_directional_light.h:40
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_directional_light.h:95
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_directional_light.h:93
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_directional_light.cpp:111
virtual void init()
This member function is called after the initialization of the Context. It must initialize and bind d...
Definition drawable_object.h:71
Definition drawable_trackball.h:39
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_trackball.h:153
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_trackball.h:155
void updateDragging(bool isDragging)
Update the dragging status of the trackball.
Definition drawable_trackball.h:107
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_trackball.h:120
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition viewer_drawer.h:39