22 #ifndef KJB_CPP_GUI_TRACKBALL_H
23 #define KJB_CPP_GUI_TRACKBALL_H
25 #ifdef KJB_HAVE_OPENGL
37 #include <boost/bind.hpp>
65 enum Mouse_mode {no_mode, rotate_mode, zoom_mode, slide_mode} ;
72 Trackball(
double diameter = 0.7,
double x = 0.5,
double y = 0.5) :
74 sphere_radius_(diameter / 2.0),
81 cur_t_(kjb::Vector(0, 0, -10)),
88 base_cam_(1.0, 1000.0),
91 fixed_fovy_(DEFAULT_FOVY *
M_PI/180),
92 object_origin_(0.0, 0.0, 0.0),
93 ACCELERATION_FACTOR(1.0/200.0)
96 base_cam_.set_world_origin(
kjb::Vector(cur_t_.begin(), cur_t_.end()));
99 set_focal_from_fovy_();
103 void bind(kjb::opengl::Glut_window& wnd)
106 using namespace boost;
108 wnd.set_mouse_callback(boost::bind(&Trackball::glut_mouse_down,
this, _1, _2, _3, _4));
109 wnd.set_motion_callback(boost::bind(&Trackball::glut_mouse_move,
this, _1, _2));
116 void attach(Viewer& wnd);
118 void update_viewport();
120 void update_viewport(
int x,
int y,
int width,
int height);
125 bool glut_mouse_down(
int button,
int state,
int x,
int y)
127 return opengl_mouse_down(button, state, x, height_ - y - 1);
133 bool opengl_mouse_down(
int button,
int state,
int x,
int y);
143 void rotate_mouse_down(
double x,
double y);
146 bool glut_mouse_move(
int x,
int y)
148 return opengl_mouse_move(x, height_ - y - 1);
152 bool opengl_mouse_move(
int x,
int y);
157 void zoom_mouse_move(
int x,
int y);
162 void slide_mouse_move(
int x,
int y);
167 void translate_mouse_down(
int x,
int y);
176 void rotate_mouse_move(
double x,
double y);
179 void rotate_mouse_up();
182 const Quaternion get_orientation()
185 return cam_.get_orientation();
190 set_extrinsic_dispatch_(extrinsic);
195 set_extrinsic_dispatch_(extrinsic);
201 template <
class Matrix_type>
202 void set_extrinsic_dispatch_(
const Matrix_type& extrinsic);
204 void set_clipping_planes(
double near,
double far);
209 void set_camera(
const Perspective_camera& cam);
213 void set_camera(
const Perspective_camera& cam,
double height);
215 void set_camera_same_fovy(
const Perspective_camera& cam);
223 void set_object_origin(
const Vector3& o);
225 const Vector3& get_object_origin()
const;
232 inline void prepare_for_rendering()
234 return prepare_for_rendering_dispatch_(
false, 0, 0, 0, 0);
243 inline void prepare_for_picking(
double x,
double y,
double width,
double height)
245 return prepare_for_rendering_dispatch_(
246 true, x, y, width, height);
249 void prepare_for_rendering_dispatch_(
bool selecting,
double select_x,
double select_y,
double select_dx,
double select_dy );
251 void render_object_origin();
278 int viewport_height()
284 int viewport_x_offset()
290 int viewport_y_offset()
296 double get_focal_length_()
const
298 return cam_.get_focal_length();
302 double get_xy_scale_()
const
306 return -(cur_t_[2]) / get_focal_length_();
310 double get_z(
double x,
double y);
313 void update_camera_()
const;
316 double get_fovy_from_focal_(
double focal_length,
double image_height);
318 void set_focal_from_fovy_();
323 Vector sphere_center_;
324 double sphere_radius_;
347 mutable bool cam_dirty_;
352 const double ACCELERATION_FACTOR;
353 static const float DEFAULT_FOVY;
Definition: gr_opengl.h:41
Vector_d< 3 > Vector3
Definition: g_quaternion.h:37
height
Definition: APPgetLargeConnectedEdges.m:33
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Definition: perspective_camera.h:93
x
Definition: APPgetLargeConnectedEdges.m:100
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
#define M_PI
Definition: fft.cpp:206
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...