mesh_conv::MC_trackball Class Reference

A container class to deal with a trackball. More...

#include <MC_trackball.hpp>

Collaboration diagram for mesh_conv::MC_trackball:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MC_trackball ()
 ~MC_trackball ()
 classical destructor
const MC_quaternionquaternion () const
 get the current quaternion
MC_quaternionquaternion ()
 get the current quaternion
const MC_quaterniond_quaternion () const
 get the quaternion to apply
MC_quaterniond_quaternion ()
 get the quaternion to apply
double project_to_disc (const double &x, const double &y) const
 return the distance to disc for the 3D coordinate
MC_trackballset_2d_coords (const double &x0, const double &y0, const double &x1, const double &y1)
 given a set of 2d coords difference, return the corresponding quaternion
MC_trackballapply_rotation ()
 multiply d_q to current_q
MC_trackballno_motion ()
 Set d_q to 0.

Public Attributes

double disc_radius
 internal parameter of the disc radius

Private Attributes

MC_quaternion current_q
 the current quaternion
MC_quaternion d_q
 the quaternion to apply

Detailed Description

A container class to deal with a trackball.

Definition at line 35 of file MC_trackball.hpp.


Constructor & Destructor Documentation

mesh_conv::MC_trackball::MC_trackball (  ) 

initial constructor

Definition at line 11 of file MC_trackball.cpp.

References disc_radius.

00012     {disc_radius=0.8;}

mesh_conv::MC_trackball::~MC_trackball (  ) 

classical destructor

Definition at line 14 of file MC_trackball.cpp.

00014 {}


Member Function Documentation

MC_trackball & mesh_conv::MC_trackball::apply_rotation (  ) 

multiply d_q to current_q

Definition at line 63 of file MC_trackball.cpp.

References mesh_conv::MC_quaternion::conjugated(), current_q, and d_q.

Referenced by motion_callback().

00064     {current_q=d_q.conjugated()*current_q;return *this;}

Here is the call graph for this function:

Here is the caller graph for this function:

MC_quaternion & mesh_conv::MC_trackball::d_quaternion (  ) 

get the quaternion to apply

Definition at line 73 of file MC_trackball.cpp.

References d_q.

00073 {return d_q;}

const MC_quaternion & mesh_conv::MC_trackball::d_quaternion (  )  const

get the quaternion to apply

Definition at line 72 of file MC_trackball.cpp.

References d_q.

00072 {return d_q;}

MC_trackball & mesh_conv::MC_trackball::no_motion (  ) 

Set d_q to 0.

Definition at line 65 of file MC_trackball.cpp.

References d_q.

00066     {d_q=MC_quaternion(1,0,0,0);return *this;}

double mesh_conv::MC_trackball::project_to_disc ( const double &  x,
const double &  y 
) const

return the distance to disc for the 3D coordinate

Definition at line 16 of file MC_trackball.cpp.

References disc_radius.

Referenced by set_2d_coords().

00017     {
00018         double n=sqrt(x*x+y*y);
00019         if(n<disc_radius*0.707107)
00020             return sqrt(disc_radius*disc_radius-n*n);
00021         else
00022             return disc_radius*disc_radius/(2.0*n);
00023     }

Here is the caller graph for this function:

MC_quaternion & mesh_conv::MC_trackball::quaternion (  ) 

get the current quaternion

Definition at line 70 of file MC_trackball.cpp.

References current_q.

00070 {return current_q;}

const MC_quaternion & mesh_conv::MC_trackball::quaternion (  )  const
MC_trackball & mesh_conv::MC_trackball::set_2d_coords ( const double &  x0,
const double &  y0,
const double &  x1,
const double &  y1 
)

given a set of 2d coords difference, return the corresponding quaternion

Definition at line 25 of file MC_trackball.cpp.

References mesh_conv::MC_v3d::cross(), d_q, disc_radius, mesh_conv::MC_v3d::norm(), and project_to_disc().

Referenced by motion_callback().

00026     {
00027         //axis of the rotation
00028         MC_v3d axis;
00029         // angle of the rotation
00030         double phi;
00031 
00032         //security to not move if start=end
00033         double epsilon=0.0001;
00034         if( std::sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1))<epsilon)
00035         {
00036             std::cout<<"MC_trackball::set_2d_coords problem"<<std::endl;
00037             d_q=MC_quaternion(1,0,0,0);
00038         }
00039         else
00040         {
00041             // temp position
00042             MC_v3d p1,p2;
00043 
00044 
00045             //printf("(%f,%f),(%f,%f)\n",x0,y0,x1,y1);
00046             p1=MC_v3d(x0,y0,project_to_disc(x0,y0));
00047             p2=MC_v3d(x1,y1,project_to_disc(x1,y1));
00048             //std::cout<<p1<<","<<p2<<"  "<<p1-p2<<std::endl;
00049 
00050             axis = (p1.cross(p2)).normalized();
00051 
00052             MC_v3d u=p1-p2;
00053             double t=u.norm()/(2*disc_radius);
00054             t=fmin(fmax(t,-1.0),1.0); //clamp
00055             phi = 2.0*asin(t);
00056 
00057             //compute quaternion to apply
00058             d_q=MC_quaternion(axis,phi);
00059         }
00060         return *this;
00061     }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

the current quaternion

Definition at line 94 of file MC_trackball.hpp.

Referenced by apply_rotation(), and quaternion().

the quaternion to apply

Definition at line 96 of file MC_trackball.hpp.

Referenced by apply_rotation(), d_quaternion(), no_motion(), and set_2d_coords().

internal parameter of the disc radius

Definition at line 87 of file MC_trackball.hpp.

Referenced by MC_trackball(), project_to_disc(), and set_2d_coords().


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

Generated on Sun Apr 18 20:24:48 2010 by  doxygen 1.6.1