Visual Computing Library  devel
Loading...
Searching...
No Matches
drawable_axis.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_DRAWABLE_DRAWABLE_AXIS_H
24#define VCL_BGFX_DRAWABLE_DRAWABLE_AXIS_H
25
26#include "mesh/mesh_render_buffers.h"
27#include "uniforms/drawable_axis_uniforms.h"
28
29#include <vclib/algorithms/mesh/create.h>
30#include <vclib/meshes/tri_mesh.h>
31#include <vclib/render/drawable/drawable_object.h>
32#include <vclib/space/core/matrix.h>
33
34#include <vclib/bgfx/context.h>
35
36#include <bgfx/bgfx.h>
37
38namespace vcl {
39
41{
42 inline static const std::pair<vcl::TriMesh, vcl::TriMesh> AXIS_MESHES =
44
45 inline static const vcl::Color AXIS_COLORS[3] = {
46 vcl::Color::Red,
47 vcl::Color::Green,
48 vcl::Color::Blue};
49
50 bool mVisible = false;
51
52 vcl::Matrix44f mMatrices[3] = {
53 vcl::Matrix44f::Zero(),
54 vcl::Matrix44f::Zero(),
55 vcl::Matrix44f::Zero()};
56
57 MeshRenderBuffers<vcl::TriMesh> mArrowBuffers[2]; // 0: cylinder, 1: cone
58
59 mutable DrawableAxisUniforms mUniforms;
60
61public:
62 DrawableAxis(double size = 1);
63
64 DrawableAxis(const DrawableAxis& other) : mVisible(other.mVisible)
65 {
66 for (uint i = 0; i < 3; i++) {
67 mMatrices[i] = other.mMatrices[i];
68 }
69
70 createAxis();
71 }
72
74
75 ~DrawableAxis() = default;
76
78 {
79 swap(other);
80 return *this;
81 }
82
83 void swap(DrawableAxis& other)
84 {
85 using std::swap;
86 swap(mVisible, other.mVisible);
87 swap(mUniforms, other.mUniforms);
88 for (uint i = 0; i < 3; i++) {
89 swap(mMatrices[i], other.mMatrices[i]);
90 }
91 for (uint i = 0; i < 2; i++) {
92 mArrowBuffers[i].swap(other.mArrowBuffers[i]);
93 }
94 }
95
96 friend void swap(DrawableAxis& a, DrawableAxis& b) { a.swap(b); }
97
98 void setSize(double size);
99
100 // DrawableObject interface
101
102 void draw(const DrawObjectSettings& settings) const override;
103
104 Box3d boundingBox() const override { return Box3d(); }
105
106 std::shared_ptr<DrawableObject> clone() const& override
107 {
108 return std::make_shared<DrawableAxis>(*this);
109 }
110
111 std::shared_ptr<DrawableObject> clone() && override
112 {
113 return std::make_shared<DrawableAxis>(std::move(*this));
114 }
115
116 bool isVisible() const override { return mVisible; }
117
118 void setVisibility(bool vis) override { mVisible = vis; }
119
120private:
121 void updateMatrices(double size);
122
123 void createAxis();
124};
125
126} // namespace vcl
127
128#endif // VCL_BGFX_DRAWABLE_DRAWABLE_AXIS_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Color class represents a 32 bit color.
Definition color.h:48
Definition drawable_axis_uniforms.h:32
Definition drawable_axis.h:41
Box3d boundingBox() const override
This member function is used to find a good camera position to render object. It should return the th...
Definition drawable_axis.h:104
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
std::shared_ptr< DrawableObject > clone() const &override
This member function is used to create a new copy of the DrawableObject. Each derived class must impl...
Definition drawable_axis.h:106
std::shared_ptr< DrawableObject > clone() &&override
This member function is used to create a new DrawableObject that is a moved from the current one....
Definition drawable_axis.h:111
The DrawableObject class is the base class for all the objects that can be drawn in a 3D viewer.
Definition drawable_object.h:57
Definition matrix.h:34