Subversion Repositories gelsvn

Rev

Rev 392 | Rev 447 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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