//---------------------------------------------------------- //Pinch controll //---------------------------------------------------------- void TapCamera::BeginPinch( const Vec2& v1, const Vec2& v2 ) { if( dragging_ ) EndDrag(); if( pinching_ ) EndPinch(); BeginDrag( Vec2() ); vec_pinch_start_center_ = (v1 + v2) / 2.f; Vec2 vec = v1 - v2; float x_diff; float y_diff; vec.Value( x_diff, y_diff ); pinch_start_distance_SQ_ = x_diff * x_diff + y_diff * y_diff; camera_rotation_start_ = atan2f( y_diff, x_diff ); camera_rotation_now_ = 0; pinching_ = true; momentum_ = false; //Init momentum factors vec_offset_delta_ = Vec3(); }
void TapCamera::Pinch( const Vec2& v1, const Vec2& v2 ) { if( !pinching_ ) return; //Update momentum factor vec_offset_last_ = vec_offset_now_; float x_diff, y_diff; Vec2 vec = v1 - v2; vec.Value( x_diff, y_diff ); float fDistanceSQ = x_diff * x_diff + y_diff * y_diff; float f = pinch_start_distance_SQ_ / fDistanceSQ; if( f < 1.f ) f = -1.f / f + 1.0f; else f = f - 1.f; if( isnan( f ) ) f = 0.f; vec = (v1 + v2) / 2.f - vec_pinch_start_center_; vec_offset_now_ = Vec3( vec, flip_z_ * f ); //Update momentum factor vec_offset_delta_ = vec_offset_delta_ * MOMENTUM_FACTOR + (vec_offset_now_ - vec_offset_last_); // //Update ration quaternion float fRotation = atan2f( y_diff, x_diff ); camera_rotation_now_ = fRotation - camera_rotation_start_; //Trackball rotation quat_ball_rot_ = Quaternion( 0.f, 0.f, sinf( -camera_rotation_now_ * 0.5f ), cosf( -camera_rotation_now_ * 0.5f ) ); }