Subversion Repositories gelsvn

Rev

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

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