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
65 mVisible(other.mVisible), mUniforms(other.mUniforms)
66 {
67 for (uint i = 0; i < 3; i++) {
68 mMatrices[i] = other.mMatrices[i];
69 }
70
71 createAxis();
72 }
73
75
76 ~DrawableAxis() = default;
77
79 {
80 swap(other);
81 return *this;
82 }
83
84 void swap(DrawableAxis& other)
85 {
86 using std::swap;
87 swap(mVisible, other.mVisible);
88 swap(mUniforms, other.mUniforms);
89 for (uint i = 0; i < 3; i++) {
90 swap(mMatrices[i], other.mMatrices[i]);
91 }
92 for (uint i = 0; i < 2; i++) {
93 mArrowBuffers[i].swap(other.mArrowBuffers[i]);
94 }
95 }
96
97 friend void swap(DrawableAxis& a, DrawableAxis& b) { a.swap(b); }
98
99 void setSize(double size);
100
101 // DrawableObject interface
102
103 void draw(uint viewId) const override;
104
105 Box3d boundingBox() const override { return Box3d(); }
106
107 std::shared_ptr<DrawableObject> clone() const& override
108 {
109 return std::make_shared<DrawableAxis>(*this);
110 }
111
112 std::shared_ptr<DrawableObject> clone() && override
113 {
114 return std::make_shared<DrawableAxis>(std::move(*this));
115 }
116
117 bool isVisible() const override { return mVisible; }
118
119 void setVisibility(bool vis) override { mVisible = vis; }
120
121private:
122 void updateMatrices(double size);
123
124 void createAxis();
125};
126
127} // namespace vcl
128
129#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:105
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
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:107
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:112
The DrawableObject class is the base class for all the objects that can be drawn in a 3D viewer.
Definition drawable_object.h:55
Definition matrix.h:34