Subversion Repositories gelsvn

Rev

Rev 630 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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