660 |
khor |
1 |
/**
|
|
|
2 |
* @file GLViewController.h
|
|
|
3 |
* @brief Class for setting view transform.
|
|
|
4 |
*/
|
|
|
5 |
/* ----------------------------------------------------------------------- *
|
|
|
6 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
7 |
* Copyright (C) the authors and DTU Informatics
|
|
|
8 |
* For license and list of authors, see ../../doc/intro.pdf
|
|
|
9 |
* ----------------------------------------------------------------------- */
|
|
|
10 |
|
|
|
11 |
#ifndef __GLGRAPHICS_GLVIEWCONTROLLER_H__
|
|
|
12 |
#define __GLGRAPHICS_GLVIEWCONTROLLER_H__
|
|
|
13 |
|
|
|
14 |
#include <fstream>
|
|
|
15 |
#include "QuatTrackBall.h"
|
|
|
16 |
|
|
|
17 |
namespace GLGraphics
|
|
|
18 |
{
|
|
|
19 |
/** The GLViewController is a more high level component than a trackball.
|
|
|
20 |
The idea behind GLViewController is to handle setting up the projection
|
|
|
21 |
and changing the viewport when the window is reshaped. Basically the raw
|
|
|
22 |
mouse position and related info is sent to the view controller which takes
|
|
|
23 |
care of the rest.
|
|
|
24 |
*/
|
|
|
25 |
class GLViewController
|
|
|
26 |
{
|
|
|
27 |
float FOV_DEG;
|
|
|
28 |
int WINX, WINY;
|
|
|
29 |
float znear, zfar;
|
|
|
30 |
float aspect;
|
|
|
31 |
bool button_down;
|
|
|
32 |
TrackBallAction last_action;
|
|
|
33 |
bool spin;
|
|
|
34 |
|
|
|
35 |
QuatTrackBall ball;
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
public:
|
|
|
39 |
GLViewController();
|
|
|
40 |
/** Constructor which accepts the window dimensions as well as the world center and the
|
|
|
41 |
radius which should be construed as the distance to the observer */
|
|
|
42 |
GLViewController(int _WINX, int _WINY,
|
|
|
43 |
const CGLA::Vec3f& _centre, float _rad);
|
|
|
44 |
|
|
|
45 |
/// Grab ball takes an action and a mouse position.
|
|
|
46 |
void grab_ball(TrackBallAction action, const CGLA::Vec2i& pos);
|
|
|
47 |
|
|
|
48 |
/// Roll virtual trackball (pass just mouse position).
|
|
|
49 |
void roll_ball(const CGLA::Vec2i& pos);
|
|
|
50 |
|
|
|
51 |
/// Release the virtual trackball
|
|
|
52 |
void release_ball();
|
|
|
53 |
|
|
|
54 |
/// Try to spind the trackball - called from idle.
|
|
|
55 |
bool try_spin();
|
|
|
56 |
|
|
|
57 |
/// Setup GL modelview matrix.
|
|
|
58 |
void set_gl_modelview();
|
|
|
59 |
|
|
|
60 |
/// Reset projection. Called initially, when window size has changed or when user zooms.
|
|
|
61 |
void reset_projection();
|
|
|
62 |
|
|
|
63 |
/// Reshape window.
|
|
|
64 |
void reshape(int W, int H);
|
|
|
65 |
|
|
|
66 |
/// Set near and far planes.
|
|
|
67 |
void set_near_and_far();
|
|
|
68 |
|
|
|
69 |
/// Set centre of ball.
|
|
|
70 |
void set_centre(const CGLA::Vec3f& c)
|
|
|
71 |
{
|
|
|
72 |
ball.set_centre(c);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/// Set rotation of ball.
|
|
|
76 |
void set_rotation(const CGLA::Quatf& qrot)
|
|
|
77 |
{
|
|
|
78 |
ball.set_rotation(qrot);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/// Set eye distance.
|
|
|
82 |
void set_eye_dist(float rad)
|
|
|
83 |
{
|
|
|
84 |
ball.set_eye_dist(rad);
|
|
|
85 |
set_near_and_far();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/// Returns eye distance
|
|
|
89 |
float get_eye_dist() const
|
|
|
90 |
{
|
|
|
91 |
return ball.get_eye_dist();
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/// Get viewing parameters: eye, centre, up
|
|
|
95 |
void get_view_param(CGLA::Vec3f& e, CGLA::Vec3f& c, CGLA::Vec3f& u) const
|
|
|
96 |
{
|
|
|
97 |
ball.get_view_param(e,c,u);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/// Set viewing parameters: eye centre, up
|
|
|
101 |
void set_view_param(const CGLA::Vec3f& e, const CGLA::Vec3f& c, const CGLA::Vec3f& u);
|
|
|
102 |
|
|
|
103 |
/// Load trackball from stream
|
|
|
104 |
bool load(std::ifstream&);
|
|
|
105 |
|
|
|
106 |
/// Save trackball to stream.
|
|
|
107 |
bool save(std::ofstream&) const;
|
|
|
108 |
};
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
#endif
|