Blue Brain BioExplorer
AbstractManipulator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 3 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
23 
24 #include "AbstractManipulator.h"
25 
30 
31 namespace core
32 {
33 namespace
34 {
35 constexpr float DEFAULT_MOTION_SPEED = 0.03f;
36 constexpr float DEFAULT_ROTATION_SPEED = 0.006f;
37 } // namespace
38 
40  : _camera(camera)
41  , _keyboardHandler(keyboardHandler)
42  , _motionSpeed{DEFAULT_ROTATION_SPEED}
43  , _rotationSpeed{DEFAULT_ROTATION_SPEED}
44 {
45 }
46 
47 void AbstractManipulator::adjust(const Boxd& boundingBox)
48 {
49  const auto size = boundingBox.isEmpty() ? 1 : glm::compMax(boundingBox.getSize());
50  auto position = boundingBox.getCenter();
51  auto target = position;
52  position.z += size;
53 
54  _camera.setInitialState(position, glm::identity<Quaterniond>(), target);
55 
56  _motionSpeed = DEFAULT_MOTION_SPEED * size;
57 
58  if (boundingBox.isEmpty())
59  CORE_INFO("World bounding box: empty")
60  else
61  CORE_INFO("World bounding box: " << boundingBox);
62  CORE_INFO("World center : " << boundingBox.getCenter());
63 }
64 
66 {
67  return _rotationSpeed;
68 }
69 
71 {
72  return getMotionSpeed() * 5.f;
73 }
74 
76 {
77  return _motionSpeed;
78 }
79 
81 {
82  _motionSpeed *= speed;
83 }
84 
86 {
87  auto orientation = _camera.getOrientation();
88  const auto translation = glm::rotate(orientation, vector);
89 
90  _camera.setPosition(_camera.getPosition() + translation);
91 }
92 
93 void AbstractManipulator::rotate(const Vector3d& pivot, const double du, const double dv, AxisMode axisMode)
94 {
95  const Vector3d axisX = glm::rotate(_camera.getOrientation(), Vector3d(1.0, 0.0, 0.0));
96 
97  const Vector3d axisY = axisMode == AxisMode::localY ? glm::rotate(_camera.getOrientation(), Vector3d(0.0, 1.0, 0.0))
98  : Vector3d(0.0, 1.0, 0.0);
99 
100  const Quaterniond deltaU = glm::angleAxis(-du, axisY);
101  const Quaterniond deltaV = glm::angleAxis(-dv, axisX);
102 
103  const Quaterniond final = deltaU * deltaV * _camera.getOrientation();
104  const Vector3d dir = glm::rotate(final, Vector3d(0.0, 0.0, -1.0));
105 
106  const double rotationRadius = glm::length(_camera.getPosition() - pivot);
107  _camera.setPosition(pivot + rotationRadius * -dir);
108  _camera.setOrientation(final);
109  _camera.setTarget(pivot);
110 }
111 } // namespace core
void updateMotionSpeed(float speed)
AbstractManipulator(Camera &camera, KeyboardHandler &keyboardHandler)
void rotate(const Vector3d &pivot, double du, double dv, AxisMode axisMode)
virtual void adjust(const Boxd &boundingBox)
void translate(const Vector3d &v)
vec getCenter() const
Definition: MathTypes.h:90
vec getSize() const
Definition: MathTypes.h:91
bool isEmpty() const
Definition: MathTypes.h:88
The Camera class is an abstract interface for a camera in a 3D graphics application....
Definition: Camera.h:41
PLATFORM_API void setInitialState(const Vector3d &position, const Quaterniond &orientation, const Vector3d &target=Vector3d(0.0, 0.0, 0.0))
Sets the initial state of the camera.
Definition: Camera.cpp:51
PLATFORM_API void setTarget(const Vector3d &target)
Sets the camera target.
Definition: Camera.h:101
PLATFORM_API void setPosition(const Vector3d &position)
Sets the camera position.
Definition: Camera.h:94
PLATFORM_API const Vector3d & getPosition() const
Gets the camera position.
Definition: Camera.h:108
PLATFORM_API const Quaterniond & getOrientation() const
Gets the camera orientation quaternion.
Definition: Camera.h:133
PLATFORM_API void setOrientation(Quaterniond orientation)
Sets the camera orientation quaternion.
Definition: Camera.h:122
The KeyboardHandler class manages keyboard shortcuts and special keys.
glm::vec< 3, double > Vector3d
Definition: MathTypes.h:143
glm::tquat< double, glm::highp > Quaterniond
Double quaternion.
Definition: MathTypes.h:153
@ vector
Definition: CommonTypes.h:68
#define CORE_INFO(__msg)
Definition: Logs.h:33