Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfArcBallInteractor.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_TFARCBALLINTERACTOR_H_
21#define _SOURCE_RENDERING_TFARCBALLINTERACTOR_H_
22
23#include <stdint.h>
24
25#include <Magnum/Magnum.h>
26#include <Magnum/Math/Vector3.h>
27#include <Magnum/Math/Vector3.h>
28#include <Magnum/Math/Matrix4.h>
29#include <Magnum/Math/Quaternion.h>
30
31#include <iostream>
32
33inline std::ostream& operator<<(std::ostream& os, const Magnum::Matrix4& m) {
34 os << "mat4 : {{" << m[0][0] << ", " << m[1][0] << ", " << m[2][0] << ", " << m[3][0] << "}" << std::endl;
35 os << " {" << m[0][1] << ", " << m[1][1] << ", " << m[2][1] << ", " << m[3][1] << "}" << std::endl;
36 os << " {" << m[0][2] << ", " << m[1][2] << ", " << m[2][2] << ", " << m[3][2] << "}" << std::endl;
37 os << " {" << m[0][3] << ", " << m[1][3] << ", " << m[2][3] << ", " << m[3][3] << "}" << std::endl;
38 return os;
39}
40
41
42namespace TissueForge::rendering {
43
44
66 {
67 public:
69 ArcBallInteractor(const Magnum::Matrix4 &mtx);
70 ArcBallInteractor(const Magnum::Vector2 &center, float radius);
71
72 void setDampening(float d);
73
74 void idle();
75
76
80 Magnum::Matrix4 rotation() const;
81
82
87 void mouseDown(int x, int y);
88
89
90 void mouseUp();
91
92
96 void mouseMotion(int x, int y, int shift, int ctrl, int alt);
97
98
102 void mouseMotion(int x, int y);
103
107 void setWindowSize(int width, int height);
108
109
110 void setConstraints(bool constrain_x, bool constrain_y);
111
112 void resetMouse();
113
114 void reset();
115
116 private:
117
118 Magnum::Vector3 constrainVector(const Magnum::Vector3 &vector, const Magnum::Vector3 &axis);
119 Magnum::Vector3 mouseToSphere(const Magnum::Vector2 &p);
120
121 void setParams(const Magnum::Vector2 &center, float radius);
122
123 //public:
124 int is_mouse_down; /* true for down, false for up */
125 int is_spinning;
126 Magnum::Quaternion q_now, q_down, q_drag, q_increment;
127 Magnum::Vector2 down_pt;
128 Magnum::Matrix4 rot, rot_increment;
129
130 bool constraint_x, constraint_y;
131 Magnum::Vector2 center;
132 float radius, damp_factor;
133 int zero_increment;
134
135 friend std::ostream& operator<<(std::ostream& os, const ArcBallInteractor& ball);
136 };
137
138}
139
140#endif // _SOURCE_RENDERING_TFARCBALLINTERACTOR_H_
Definition tfArcBallInteractor.h:66
void mouseMotion(int x, int y, int shift, int ctrl, int alt)
void setWindowSize(int width, int height)
Tissue Forge rendering and visualization.
Definition tfAngle.h:38