Subversion Repositories gelsvn

Rev

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

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