DART  6.7.3
Trackball.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, 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 public:
45  // To get byte-aligned Eigen vectors
46  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 
49  Trackball();
50 
52  Trackball(const Eigen::Vector2d& _center, double _radius);
53 
55  void startBall(double _x, double _y);
56 
59  void updateBall(double _x, double _y);
60 
62  void applyGLRotation();
63 
65  void draw(int _winWidth, int _winHeight);
66 
68  void setTrackball(const Eigen::Vector2d& _center, const double _radius);
69 
71  void setCenter(const Eigen::Vector2d& _center);
72 
74  void setRadius(const double _radius);
75 
77  void setQuaternion(const Eigen::Quaterniond& _q);
78 
80  Eigen::Quaterniond getCurrQuat() const;
81 
83  Eigen::Matrix3d getRotationMatrix() const;
84 
86  Eigen::Vector2d getCenter() const;
87 
89  double getRadius() const;
90 
91 private:
93  Eigen::Vector3d mouseOnSphere(double _mouseX, double _mouseY) const;
94 
97  Eigen::Quaterniond quatFromVectors(const Eigen::Vector3d& _from,
98  const Eigen::Vector3d& _to) const;
99 
101  Eigen::Vector2d mCenter;
102 
104  double mRadius;
105 
107  Eigen::Vector3d mStartPos;
108 
110  Eigen::Quaterniond mCurrQuat;
111 };
112 
113 } // namespace gui
114 } // namespace dart
115 
116 #endif // DART_GUI_TRACKBALL_HPP_
Definition: Trackball.hpp:43
Eigen::Vector3d mStartPos
Definition: Trackball.hpp:107
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:59
Eigen::Matrix3d getRotationMatrix() const
Definition: Trackball.cpp:124
double getRadius() const
Definition: Trackball.cpp:132
Eigen::Quaterniond getCurrQuat() const
Definition: Trackball.cpp:120
Eigen::Vector2d mCenter
Definition: Trackball.hpp:101
Eigen::Quaterniond mCurrQuat
Definition: Trackball.hpp:110
void setQuaternion(const Eigen::Quaterniond &_q)
Definition: Trackball.cpp:116
void draw(int _winWidth, int _winHeight)
Draw the trackball on screen.
Definition: Trackball.cpp:71
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:156
double mRadius
Definition: Trackball.hpp:104
void setCenter(const Eigen::Vector2d &_center)
Definition: Trackball.cpp:108
Eigen::Vector3d mouseOnSphere(double _mouseX, double _mouseY) const
Project screen coordinate (x,y) to the trackball.
Definition: Trackball.cpp:136
void applyGLRotation()
Apply the current rotation to openGL env.
Definition: Trackball.cpp:66
void setRadius(const double _radius)
Definition: Trackball.cpp:112
void startBall(double _x, double _y)
Set the starting position to the project of (x,y) on the trackball.
Definition: Trackball.cpp:55
Eigen::Vector2d getCenter() const
Definition: Trackball.cpp:128
void setTrackball(const Eigen::Vector2d &_center, const double _radius)
Definition: Trackball.cpp:102
Definition: BulletCollisionDetector.cpp:63