DART  6.10.1
Trackball.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_GUI_TRACKBALL_HPP_
34 #define DART_GUI_TRACKBALL_HPP_
35 
36 #include <Eigen/Core>
37 #include <Eigen/Geometry>
38 
39 namespace dart {
40 namespace gui {
41 
43 class Trackball
44 {
45 public:
46  // To get byte-aligned Eigen vectors
47  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
48 
50  Trackball();
51 
53  Trackball(const Eigen::Vector2d& _center, double _radius);
54 
56  void startBall(double _x, double _y);
57 
60  void updateBall(double _x, double _y);
61 
63  void applyGLRotation();
64 
66  void draw(int _winWidth, int _winHeight);
67 
69  void setTrackball(const Eigen::Vector2d& _center, const double _radius);
70 
72  void setCenter(const Eigen::Vector2d& _center);
73 
75  void setRadius(const double _radius);
76 
78  void setQuaternion(const Eigen::Quaterniond& _q);
79 
81  Eigen::Quaterniond getCurrQuat() const;
82 
84  Eigen::Matrix3d getRotationMatrix() const;
85 
87  Eigen::Vector2d getCenter() const;
88 
90  double getRadius() const;
91 
92 private:
94  Eigen::Vector3d mouseOnSphere(double _mouseX, double _mouseY) const;
95 
98  Eigen::Quaterniond quatFromVectors(
99  const Eigen::Vector3d& _from, const Eigen::Vector3d& _to) const;
100 
102  Eigen::Vector2d mCenter;
103 
105  double mRadius;
106 
108  Eigen::Vector3d mStartPos;
109 
111  Eigen::Quaterniond mCurrQuat;
112 };
113 
114 } // namespace gui
115 } // namespace dart
116 
117 #endif // DART_GUI_TRACKBALL_HPP_
Definition: Trackball.hpp:44
Eigen::Vector3d mStartPos
Definition: Trackball.hpp:108
void updateBall(double _x, double _y)
Update the current rotation to rotate from mStartPos to the projection of (x,y) on trackball,...
Definition: Trackball.cpp:62
Eigen::Matrix3d getRotationMatrix() const
Definition: Trackball.cpp:137
double getRadius() const
Definition: Trackball.cpp:147
Eigen::Quaterniond getCurrQuat() const
Definition: Trackball.cpp:132
Eigen::Vector2d mCenter
Definition: Trackball.hpp:102
Eigen::Quaterniond mCurrQuat
Definition: Trackball.hpp:111
void setQuaternion(const Eigen::Quaterniond &_q)
Definition: Trackball.cpp:127
void draw(int _winWidth, int _winHeight)
Draw the trackball on screen.
Definition: Trackball.cpp:76
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Trackball()
Default constructor.
Definition: Trackball.cpp:41
Eigen::Quaterniond quatFromVectors(const Eigen::Vector3d &_from, const Eigen::Vector3d &_to) const
Compute the quaternion that rotates from vector "from" to vector "to".
Definition: Trackball.cpp:177
double mRadius
Definition: Trackball.hpp:105
void setCenter(const Eigen::Vector2d &_center)
Definition: Trackball.cpp:117
Eigen::Vector3d mouseOnSphere(double _mouseX, double _mouseY) const
Project screen coordinate (x,y) to the trackball.
Definition: Trackball.cpp:152
void applyGLRotation()
Apply the current rotation to openGL env.
Definition: Trackball.cpp:70
void setRadius(const double _radius)
Definition: Trackball.cpp:122
void startBall(double _x, double _y)
Set the starting position to the project of (x,y) on the trackball.
Definition: Trackball.cpp:57
Eigen::Vector2d getCenter() const
Definition: Trackball.cpp:142
void setTrackball(const Eigen::Vector2d &_center, const double _radius)
Definition: Trackball.cpp:110
Definition: BulletCollisionDetector.cpp:65