Subversion Repositories gelsvn

Rev

Rev 392 | Rev 447 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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