Trackball Class Reference

#include <trackball.h>

Public Types

enum  Mode { Around , Local }
 

Public Member Functions

 Trackball ()
 
void start (Mode m=Around)
 
void setCamera (Camera *pCam)
 
void track (const Eigen::Vector2i &newPoint2D)
 

Protected Member Functions

bool mapToSphere (const Eigen::Vector2i &p2, Eigen::Vector3f &v3)
 

Protected Attributes

CamerampCamera
 
Eigen::Vector3f mLastPoint3D
 
Mode mMode
 
bool mLastPointOk
 

Member Enumeration Documentation

◆ Mode

Enumerator
Around 
Local 
19 { Around, Local };
@ Around
Definition: trackball.h:19
@ Local
Definition: trackball.h:19

Constructor & Destructor Documentation

◆ Trackball()

Trackball::Trackball ( )
inline
21 : mpCamera(0) {}
Camera * mpCamera
Definition: trackball.h:35

Member Function Documentation

◆ mapToSphere()

bool Trackball::mapToSphere ( const Eigen::Vector2i &  p2,
Eigen::Vector3f &  v3 
)
protected
36  {
37  if ((p2.x() >= 0) && (p2.x() <= int(mpCamera->vpWidth())) && (p2.y() >= 0) && (p2.y() <= int(mpCamera->vpHeight()))) {
38  double x = (double)(p2.x() - 0.5 * mpCamera->vpWidth()) / (double)mpCamera->vpWidth();
39  double y = (double)(0.5 * mpCamera->vpHeight() - p2.y()) / (double)mpCamera->vpHeight();
40  double sinx = sin(M_PI * x * 0.5);
41  double siny = sin(M_PI * y * 0.5);
42  double sinx2siny2 = sinx * sinx + siny * siny;
43 
44  v3.x() = sinx;
45  v3.y() = siny;
46  v3.z() = sinx2siny2 < 1.0 ? sqrt(1.0 - sinx2siny2) : 0.0;
47 
48  return true;
49  } else
50  return false;
51 }
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
uint vpHeight(void) const
Definition: camera.h:49
uint vpWidth(void) const
Definition: camera.h:48
Scalar * y
Definition: level1_cplx_impl.h:128
#define M_PI
Definition: main.h:121
list x
Definition: plotDoE.py:28

References M_PI, sin(), sqrt(), plotDoE::x, and y.

◆ setCamera()

void Trackball::setCamera ( Camera pCam)
inline
28 { mpCamera = pCam; }

References mpCamera.

◆ start()

void Trackball::start ( Mode  m = Around)
inline
23  {
24  mMode = m;
25  mLastPointOk = false;
26  }
Mode mMode
Definition: trackball.h:37
bool mLastPointOk
Definition: trackball.h:38
int * m
Definition: level2_cplx_impl.h:294

References m, mLastPointOk, and mMode.

◆ track()

void Trackball::track ( const Eigen::Vector2i &  newPoint2D)
15  {
16  if (mpCamera == 0) return;
17  Vector3f newPoint3D;
18  bool newPointOk = mapToSphere(point2D, newPoint3D);
19 
20  if (mLastPointOk && newPointOk) {
21  Vector3f axis = mLastPoint3D.cross(newPoint3D).normalized();
22  float cos_angle = mLastPoint3D.dot(newPoint3D);
23  if (std::abs(cos_angle) < 1.0) {
24  float angle = 2. * acos(cos_angle);
25  if (mMode == Around)
27  else
29  }
30  }
31 
32  mLastPoint3D = newPoint3D;
33  mLastPointOk = newPointOk;
34 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar acos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:138
void localRotate(const Eigen::Quaternionf &q)
Definition: camera.cpp:135
void rotateAroundTarget(const Eigen::Quaternionf &q)
Definition: camera.cpp:118
bool mapToSphere(const Eigen::Vector2i &p2, Eigen::Vector3f &v3)
Definition: trackball.cpp:36
Eigen::Vector3f mLastPoint3D
Definition: trackball.h:36
Quaternion< float > Quaternionf
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:384
AngleAxis< float > AngleAxisf
Definition: AngleAxis.h:165
double angle(const double &t)
Angular position as a function of time t.
Definition: jeffery_orbit.cc:98

References abs(), acos(), and Jeffery_Solution::angle().

Member Data Documentation

◆ mLastPoint3D

Eigen::Vector3f Trackball::mLastPoint3D
protected

◆ mLastPointOk

bool Trackball::mLastPointOk
protected

Referenced by start().

◆ mMode

Mode Trackball::mMode
protected

Referenced by start().

◆ mpCamera

Camera* Trackball::mpCamera
protected

Referenced by setCamera().


The documentation for this class was generated from the following files: