Visual Computing Library  devel
Loading...
Searching...
No Matches
drawable_axis.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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
28#include <vclib/algorithms/mesh/create.h>
29#include <vclib/meshes/tri_mesh.h>
30#include <vclib/render/drawable/drawable_object.h>
31#include <vclib/space/core/matrix.h>
32
33#include <vclib/bgfx/context.h>
34
35#include <bgfx/bgfx.h>
36
37namespace vcl {
38
40{
41 inline static const std::pair<vcl::TriMesh, vcl::TriMesh> AXIS_MESHES =
43
44 inline static const vcl::Color AXIS_COLORS[3] = {
45 vcl::Color::Red,
46 vcl::Color::Green,
47 vcl::Color::Blue};
48
49 bool mVisible = false;
50
51 vcl::Matrix44f mMatrices[3] = {
52 vcl::Matrix44f::Zero(),
53 vcl::Matrix44f::Zero(),
54 vcl::Matrix44f::Zero()};
55
56 MeshRenderBuffers<vcl::TriMesh> mArrowBuffers[2]; // 0: cylinder, 1: cone
57
58public:
59 DrawableAxis(double size = 1);
60
61 DrawableAxis(const DrawableAxis& other) : mVisible(other.mVisible)
62 {
63 for (uint i = 0; i < 3; i++) {
64 mMatrices[i] = other.mMatrices[i];
65 }
66
67 createAxis();
68 }
69
71
72 ~DrawableAxis() = default;
73
75 {
76 swap(other);
77 return *this;
78 }
79
80 void swap(DrawableAxis& other)
81 {
82 using std::swap;
83 swap(mVisible, other.mVisible);
84 for (uint i = 0; i < 3; i++) {
85 swap(mMatrices[i], other.mMatrices[i]);
86 }
87 for (uint i = 0; i < 2; i++) {
88 mArrowBuffers[i].swap(other.mArrowBuffers[i]);
89 }
90 }
91
92 friend void swap(DrawableAxis& a, DrawableAxis& b) { a.swap(b); }
93
94 void setSize(double size);
95
96 // DrawableObject interface
97
98 void draw(const DrawObjectSettings& settings) const override;
99
100 Box3d boundingBox() const override { return Box3d(); }
101
102 std::shared_ptr<DrawableObject> clone() const& override
103 {
104 return std::make_shared<DrawableAxis>(*this);
105 }
106
107 std::shared_ptr<DrawableObject> clone() && override
108 {
109 return std::make_shared<DrawableAxis>(std::move(*this));
110 }
111
112 bool isVisible() const override { return mVisible; }
113
114 void setVisibility(bool vis) override { mVisible = vis; }
115
116private:
117 void updateMatrices(double size);
118
119 void createAxis();
120};
121
122} // namespace vcl
123
124#endif // VCL_BGFX_DRAWABLE_DRAWABLE_AXIS_H
The Color class represents a 32 bit color.
Definition color.h:48
Definition drawable_axis.h:40
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:100
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_axis.h:114
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:43
bool isVisible() const override
This member function is used to check if the object is visible.
Definition drawable_axis.h:112
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:102
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:107
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
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41