Go to the documentation of this file.00001
00009 #include "Arcball.h"
00010 #include <stdio.h>
00011
00012 using namespace MeshLib;
00013
00014
00015
00016 CArcball::CArcball( int win_width, int win_height, int ox, int oy )
00017 {
00018 m_radius = (win_width < win_height )? win_width/2: win_height/2;
00019
00020 m_center = CPoint2( win_width/2, win_height/2 );
00021
00022 CPoint2 p(ox,oy);
00023
00024 _plane2sphere( p, m_position );
00025 }
00026
00027
00028
00029 void CArcball::_plane2sphere( const CPoint2 & p, CPoint & q )
00030 {
00031
00032 CPoint2 f = p;
00033 f /= m_radius;
00034
00035 double l = sqrt( f*f );
00036
00037 if( l > 1.0 ){
00038 q=CPoint( f[0]/l, f[1]/l,0);
00039 return;
00040 }
00041
00042 double fz = sqrt( 1 - l * l );
00043
00044 q = CPoint( f[0],f[1],fz );
00045 }
00046
00047
00048
00049 CQrot CArcball::update( int nx, int ny )
00050 {
00051 CPoint position;
00052 _plane2sphere( CPoint2(nx,ny), position );
00053 CPoint cp = m_position^position;
00054 CQrot r(m_position * position, cp[0],cp[1],cp[2]);
00055 m_position = position;
00056
00057 return r;
00058 }