Subversion Repositories gelsvn

Rev

Rev 394 | Rev 594 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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