Subversion Repositories gelsvn

Rev

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

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