Visual Computing Library  devel
Loading...
Searching...
No Matches
trackball_viewer_drawer_bgfx.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_DRAWERS_TRACKBALL_VIEWER_DRAWER_BGFX_H
24#define VCL_BGFX_DRAWERS_TRACKBALL_VIEWER_DRAWER_BGFX_H
25
26#include "viewer_drawer_bgfx.h"
27
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/render/drawers/trackball_event_drawer.h>
32
33namespace vcl {
34
35template<typename DerivedRenderApp>
37 public ViewerDrawerBGFX<TrackBallEventDrawer<DerivedRenderApp>>
38{
39 using ParentViewer =
41
42 DrawableAxis mAxis;
43 DrawableTrackBall mDrawTrackBall;
44 DrawableDirectionalLight mDrawableDirectionalLight;
45
46public:
48
49 void onInit(uint viewId) override
50 {
51 ParentViewer::onInit(viewId);
52 mAxis.init();
53 mDrawTrackBall.init();
54 mDrawableDirectionalLight.init();
55 }
56
57 void onDraw(uint viewId) override
58 {
59 DrawObjectSettings settings;
60 settings.viewId = viewId;
61
62 ParentViewer::onDraw(viewId);
63
64 setDirectionalLightVisibility(
65 ParentViewer::currentMotion() ==
66 ParentViewer::TrackBallType::DIR_LIGHT_ARC);
67
68 if (mAxis.isVisible()) {
69 mAxis.draw(settings);
70 }
71
72 if (mDrawTrackBall.isVisible()) {
73 mDrawTrackBall.draw(settings);
74 }
75
76 if (mDrawableDirectionalLight.isVisible()) {
77 mDrawableDirectionalLight.draw(settings);
78 }
79 }
80
81 void onDrawContent(uint viewId) override
82 {
83 ParentViewer::onDrawContent(viewId);
84
85 updateDrawableTrackball();
86 updateDrawableDirectionalLight();
87 }
88
89 // events
90 void onKeyPress(Key::Enum key, const KeyModifiers& modifiers) override
91 {
92 ParentViewer::onKeyPress(key, modifiers);
93
94 switch (key) {
95 case Key::A: toggleAxisVisibility(); break;
96
97 case Key::T: toggleTrackBallVisibility(); break;
98
99 default: break;
100 }
101 }
102
103 void toggleAxisVisibility() { mAxis.setVisibility(!mAxis.isVisible()); }
104
105 void toggleTrackBallVisibility()
106 {
107 mDrawTrackBall.setVisibility(!mDrawTrackBall.isVisible());
108 }
109
110private:
111 void updateDrawableTrackball()
112 {
113 auto v = ParentViewer::gizmoMatrix();
114 mDrawTrackBall.setTransform(v);
115 mDrawTrackBall.updateDragging(ParentViewer::isDragging());
116 }
117
118 bool isDirectionalLightVisible() const
119 {
120 return mDrawableDirectionalLight.isVisible();
121 }
122
123 void setDirectionalLightVisibility(bool b)
124 {
125 mDrawableDirectionalLight.setVisibility(b);
126 }
127
128 void updateDrawableDirectionalLight()
129 {
130 auto v = ParentViewer::lightGizmoMatrix();
131 mDrawableDirectionalLight.updateRotation(v);
132 }
133};
134
135} // namespace vcl
136
137#endif // VCL_BGFX_DRAWERS_TRACKBALL_VIEWER_DRAWER_BGFX_H
A class representing a box in N-dimensional space.
Definition box.h:46
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:118
void draw(const DrawObjectSettings &settings) 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:116
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:88
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_directional_light.h:86
void draw(const DrawObjectSettings &settings) 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:73
Definition drawable_trackball.h:35
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_trackball.cpp:191
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_trackball.cpp:196
void updateDragging(bool isDragging)
Update the dragging status of the trackball.
Definition drawable_trackball.cpp:137
void draw(const DrawObjectSettings &settings) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_trackball.cpp:153
Definition trackball_viewer_drawer_bgfx.h:38
Definition viewer_drawer_bgfx.h:36