Visual Computing Library
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 bgfx::ProgramHandle mProgram =
61 .programManager()
62 .getProgram<VertFragProgram::DRAWABLE_AXIS>();
63
64 mutable DrawableAxisUniforms mUniforms;
65
66public:
67 DrawableAxis(double size = 1);
68
70 mVisible(other.mVisible), mUniforms(other.mUniforms)
71 {
72 for (uint i = 0; i < 3; i++) {
73 mMatrices[i] = other.mMatrices[i];
74 }
75
76 createAxis();
77 }
78
80
81 ~DrawableAxis() = default;
82
84 {
85 swap(other);
86 return *this;
87 }
88
89 void swap(DrawableAxis& other)
90 {
91 using std::swap;
92 swap(mVisible, other.mVisible);
93 swap(mUniforms, other.mUniforms);
94 for (uint i = 0; i < 3; i++) {
95 swap(mMatrices[i], other.mMatrices[i]);
96 }
97 for (uint i = 0; i < 2; i++) {
98 mArrowBuffers[i].swap(other.mArrowBuffers[i]);
99 }
100 }
101
102 friend void swap(DrawableAxis& a, DrawableAxis& b) { a.swap(b); }
103
104 void setSize(double size);
105
106 // DrawableObject interface
107
108 void draw(uint viewId) const override;
109
110 Box3d boundingBox() const override { return Box3d(); }
111
112 std::shared_ptr<DrawableObject> clone() const& override
113 {
114 return std::make_shared<DrawableAxis>(*this);
115 }
116
117 std::shared_ptr<DrawableObject> clone() && override
118 {
119 return std::make_shared<DrawableAxis>(std::move(*this));
120 }
121
122 bool isVisible() const override { return mVisible; }
123
124 void setVisibility(bool vis) override { mVisible = vis; }
125
126private:
127 void updateMatrices(double size);
128
129 void createAxis();
130};
131
132} // namespace vcl
133
134#endif // VCL_BGFX_DRAWABLE_DRAWABLE_AXIS_H
The Color class represents a 32 bit color.
Definition color.h:48
static Context & instance(void *windowHandle=nullptr, void *displayHandle=nullptr)
Return the context instance.
Definition context.cpp:365
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:110
void setVisibility(bool vis) override
This member function is used to set the visibility of the object.
Definition drawable_axis.h:124
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:122
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:112
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:117
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:36
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43