MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
camera_trackball.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef OGL_CAM_TRACKBALL_HEADER
11#define OGL_CAM_TRACKBALL_HEADER
12
13#include "math/vector.h"
14#include "ogl/defines.h"
15#include "ogl/events.h"
16#include "ogl/camera.h"
17
19
25{
26public:
27 CamTrackball (void);
28
29 void set_camera (Camera* camera);
30 bool consume_event (MouseEvent const& event);
31 bool consume_event (KeyboardEvent const& event);
32
33 void set_camera_params (math::Vec3f const& center,
34 math::Vec3f const& lookat, math::Vec3f const& upvec);
35
36 math::Vec3f get_campos (void) const;
37 math::Vec3f get_viewdir (void) const;
38 math::Vec3f const& get_upvec (void) const;
39
40private:
41 math::Vec3f get_center (int x, int y);
42 void handle_tb_rotation (int x, int y);
43 math::Vec3f get_ball_normal (int x, int y);
44
45private:
46 /* Camera information. */
47 Camera* cam;
48
49 /* Current trackball configuration. */
50 float tb_radius;
51 math::Vec3f tb_center;
52 math::Vec3f tb_tocam;
53 math::Vec3f tb_upvec;
54
55 /* Variables to calculate rotation and zoom. */
56 int rot_mouse_x;
57 int rot_mouse_y;
58 math::Vec3f rot_tb_tocam;
59 math::Vec3f rot_tb_upvec;
60
61 float zoom_tb_radius;
62 int zoom_mouse_y;
63};
64
65/* ---------------------------------------------------------------- */
66
67inline void
68CamTrackball::set_camera (Camera* camera)
69{
70 this->cam = camera;
71}
72
73inline math::Vec3f
74CamTrackball::get_campos (void) const
75{
76 return this->tb_center + this->tb_tocam * this->tb_radius;
77}
78
79inline math::Vec3f
80CamTrackball::get_viewdir (void) const
81{
82 return -this->tb_tocam;
83}
84
85inline math::Vec3f const&
86CamTrackball::get_upvec (void) const
87{
88 return this->tb_upvec;
89}
90
92
93#endif /* OGL_CAM_TRACKBALL_HEADER */
Vector class for arbitrary dimensions and types.
Definition vector.h:87
A trackball camera control that consumes mouse events and delivers viewing parameters for the camera.
A camera class that manages viewing and projection matrices.
Definition camera.h:33
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13
Keyboard event.
Definition events.h:57
Mouse event.
Definition events.h:40