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 ParentViewer::onDraw(viewId);
60
61 setDirectionalLightVisibility(
62 ParentViewer::currentMotion() ==
63 ParentViewer::TrackBallType::DIR_LIGHT_ARC);
64
65 if (mAxis.isVisible()) {
66 mAxis.draw(viewId);
67 }
68
69 if (mDrawTrackBall.isVisible()) {
70 mDrawTrackBall.draw(viewId);
71 }
72
73 if (mDrawableDirectionalLight.isVisible()) {
74 mDrawableDirectionalLight.draw(viewId);
75 }
76 }
77
78 void onDrawContent(uint viewId) override
79 {
80 ParentViewer::onDrawContent(viewId);
81
82 updateDrawableTrackball();
83 updateDrawableDirectionalLight();
84 }
85
86 // events
87 void onKeyPress(Key::Enum key, const KeyModifiers& modifiers) override
88 {
89 ParentViewer::onKeyPress(key, modifiers);
90
91 switch (key) {
92 case Key::A: toggleAxisVisibility(); break;
93
94 case Key::T: toggleTrackBallVisibility(); break;
95
96 default: break;
97 }
98 }
99
100 void toggleAxisVisibility() { mAxis.setVisibility(!mAxis.isVisible()); }
101
102 void toggleTrackBallVisibility()
103 {
104 mDrawTrackBall.setVisibility(!mDrawTrackBall.isVisible());
105 }
106
107private:
108 void updateDrawableTrackball()
109 {
110 auto v = ParentViewer::gizmoMatrix();
111 mDrawTrackBall.setTransform(v);
112 mDrawTrackBall.updateDragging(ParentViewer::isDragging());
113 }
114
115 bool isDirectionalLightVisible() const
116 {
117 return mDrawableDirectionalLight.isVisible();
118 }
119
120 void setDirectionalLightVisibility(bool b)
121 {
122 mDrawableDirectionalLight.setVisibility(b);
123 }
124
125 void updateDrawableDirectionalLight()
126 {
127 auto v = ParentViewer::lightGizmoMatrix();
128 mDrawableDirectionalLight.updateRotation(v);
129 }
130};
131
132} // namespace vcl
133
134#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:119
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:117
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(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_directional_light.cpp:110
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:35
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_trackball.cpp:192
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_trackball.cpp:197
void updateDragging(bool isDragging)
Update the dragging status of the trackball.
Definition drawable_trackball.cpp:138
void draw(uint viewId) const override
This member function must draw the object. It will be called at every frame.
Definition drawable_trackball.cpp:154
Definition trackball_viewer_drawer_bgfx.h:38
Definition viewer_drawer_bgfx.h:36