Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfArrowRenderer.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _SOURCE_RENDERING_TFARROWRENDERER_H_
21#define _SOURCE_RENDERING_TFARROWRENDERER_H_
22
23#include "tfSubRenderer.h"
24
25#include <shaders/tfPhong.h>
26#include "tfStyle.h"
27
28#include <Magnum/GL/Mesh.h>
29#include <Magnum/Math/Color.h>
30#include <Magnum/Mesh.h>
31
32#include <utility>
33#include <vector>
34
35
36namespace TissueForge::rendering {
37
38
46 struct CAPI_EXPORT ArrowData {
47 // Position of the arrow
48 fVector3 position;
49
50 // Vector components of the arrow
51 fVector3 components;
52
53 // Tissue Forge style
54 Style style;
55
56 // Scaling applied to arrow
57 float scale = 1.0;
58
59 private:
60
61 int id;
62 friend struct ArrowRenderer;
63 };
64
66 Magnum::Matrix4 transformationMatrix;
67 Magnum::Matrix3 normalMatrix;
68 Magnum::Color4 color;
69 };
70
86
87 // Current number of arrows in inventory
88 int nr_arrows;
89
90 // Arrow inventory
91 std::vector<ArrowData *> arrows;
92
94 ArrowRenderer(const ArrowRenderer &other);
96
97 HRESULT start(const std::vector<fVector4> &clipPlanes) override;
98 HRESULT draw(ArcBallCamera *camera, const iVector2 &viewportSize, const fMatrix4 &modelViewMat) override;
99 const unsigned addClipPlaneEquation(const Magnum::Vector4& pe) override;
100 const unsigned removeClipPlaneEquation(const unsigned int &id) override;
101 void setClipPlaneEquation(unsigned id, const Magnum::Vector4& pe) override;
102 void setAmbientColor(const Magnum::Color3& color) override;
103 void setDiffuseColor(const Magnum::Color3& color) override;
104 void setSpecularColor(const Magnum::Color3& color) override;
105 void setShininess(float shininess) override;
106 void setLightDirection(const fVector3& lightDir) override;
107 void setLightColor(const Magnum::Color3 &color) override;
108
121 int addArrow(ArrowData *arrow);
122
138 std::pair<int, ArrowData*> addArrow(
139 const fVector3 &position,
140 const fVector3 &components,
141 const Style &style,
142 const float &scale=1.0
143 );
144
153 HRESULT removeArrow(const int &arrowId);
154
160 ArrowData *getArrow(const int &arrowId);
161
168
169 private:
170
171 int _arrowDetail = 10;
172
173 std::vector<Magnum::Vector4> _clipPlanes;
174
175 Magnum::GL::Buffer _bufferHead{Corrade::Containers::NoCreate};
176 Magnum::GL::Buffer _bufferCylinder{Corrade::Containers::NoCreate};
177 Magnum::GL::Mesh _meshHead{Corrade::Containers::NoCreate};
178 Magnum::GL::Mesh _meshCylinder{Corrade::Containers::NoCreate};
179 shaders::Phong _shader{Corrade::Containers::NoCreate};
180
186 int nextDataId();
187
188 };
189
199
200};
201
202#endif // _SOURCE_RENDERING_TFARROWRENDERER_H_
Definition tfArcBallCamera.h:66
Definition tfMatrix3.h:35
Tissue Forge rendering and visualization.
Definition tfAngle.h:38
fMatrix3 vectorFrameRotation(const fVector3 &vec)
Generates a 3x3 rotation matrix into the frame of a vector.
Vector visualization specification.
Definition tfArrowRenderer.h:46
Definition tfArrowRenderer.h:65
Vector renderer.
Definition tfArrowRenderer.h:85
const unsigned addClipPlaneEquation(const Magnum::Vector4 &pe) override
Adds a clip plane equation.
void setDiffuseColor(const Magnum::Color3 &color) override
Set the diffuse color.
HRESULT draw(ArcBallCamera *camera, const iVector2 &viewportSize, const fMatrix4 &modelViewMat) override
Updates visualization.
HRESULT start(const std::vector< fVector4 > &clipPlanes) override
Starts the renderer.
static ArrowRenderer * get()
Gets the global instance of the renderer.
std::pair< int, ArrowData * > addArrow(const fVector3 &position, const fVector3 &components, const Style &style, const float &scale=1.0)
Adds a vector visualization specification.
void setLightColor(const Magnum::Color3 &color) override
Sets the light color.
ArrowData * getArrow(const int &arrowId)
Gets a vector visualization specification.
void setLightDirection(const fVector3 &lightDir) override
Sets the light direction.
int addArrow(ArrowData *arrow)
Adds a vector visualization specification.
HRESULT removeArrow(const int &arrowId)
Removes a vector visualization specification.
void setSpecularColor(const Magnum::Color3 &color) override
Set the specular color.
void setClipPlaneEquation(unsigned id, const Magnum::Vector4 &pe) override
Sets a clip plane equation.
const unsigned removeClipPlaneEquation(const unsigned int &id) override
Removes a clip plane equation.
void setAmbientColor(const Magnum::Color3 &color) override
Sets the ambient color.
void setShininess(float shininess) override
Sets the shininess.
The Tissue Forge style type.
Definition tfStyle.h:46
Definition tfSubRenderer.h:34
int32_t HRESULT
Definition tf_port.h:255