Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 4d01fa25ef1f5a845f8d23fa9e7194eec1f844ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
   render/camera.h
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#ifndef __INCLUDED_RENDER_CAMERA_H__
#define __INCLUDED_RENDER_CAMERA_H__

#include "core/range.h"
#include "math/vector3f.h"
#include "math/axis.h"

namespace core
{
	class Entity;
}

namespace render
{

const float WORLDSCALE = 4.0f;

const float FRUSTUMSIZE = 0.5f;
const float FRUSTUMFRONT = 1.0f;
const float FARPLANE = core::range::maxdistance * WORLDSCALE;

/**
 * @brief The Camera class draws a camera transformation determined by its current settings
 * */
class Camera
{
public:
	/**
	 * @brief enum indicating the camera mode
	 * */
	enum Mode {Track, Cockpit, Free, Overview};
	
	/**
	 * @brief default constructor
	 * */
	Camera(const Mode mode = Track);
	
	/**
	 * @brief destructor
	 * */
	~Camera();
	
	/* --- inspectors ------------------------------------------ */
	
	/**
	 * @brief current camera mode
	 * */
	inline const Mode mode() const
	{
		return _mode;
	}
	
	/**
	 * @brief distance between the camera eye and the target
	 * */
	inline const float distance() const
	{
		return _distance;
	}
	
	/**
	 * @brief distance multiplier
	 * The distance multiplier can be used to zoom the camera in or out
	 * */
	inline const float multiplier() const
	{
		return _multiplier;
	}
	
	/**
	 * @brief camera eye location, translation part of the camera transformation
	 * */
	inline const math::Vector3f & location() const
	{
		return _location;
	}
	
	/**
	 * @brief camera target location,point the camera is looking at
	 * */
	inline const math::Vector3f & target_location() const
	{
		return _target_location;
	}
	
	/**
	 * @brief camera eye axis, rotation part of the camera transformation
	 * */
	inline const math::Axis & axis() const
	{
		return _axis;
	}
	
	/**
	 * @brief the entity the camera is currently looking at
	 * */
	inline const core::Entity *target()
	{
		return _target_entity;
	}
	
	/**
	 * @brief free look direction angle, in degrees
	 * */
	inline const float freelook_direction() const
	{
		return _freelook_direction;
	}
	
	/**
	 * @brief free look pitch angle, in degrees
	 * */
	inline const float freelook_pitch() const
	{
		return _freelook_pitch;
	}
	
	/**
	 * @brief free look direction rotation speed, -1..1
	 * */
	inline const float movement_direction() const
	{
		return _movement_direction;
	}
	
	/**
	 * @brief free look pitch rotation speed, -1..1
	 * */
	inline const float movement_pitch() const
	{
		return _movement_pitch;
	}
	
	/* --- mutators -------------------------------------------- */
		
	/**
	 * @brief set the current camera mode
	 * */
	void set_mode(const Mode mode);
	
	/**
	 * @brief set next camera mode
	 * */
	void cycle_mode_next();
	
	/**
	 * @brief set previous camera mode
	 * */
	void cycle_mode_previous();

	/**
	 * @brief set camera target
	 * */
	void set_target(const core::Entity *entity = 0);
	
	/**
	 * @brief set distance multiplier
	 * */
	void set_multiplier(const float multiplier);
	
	/**
	 * @brief set the free look direction angle, in degrees
	 * */
	void set_freelook_direction(const float angle);
	
	/**
	 * @brief set the free look pitch angle, in degrees
	 * */
	void set_freelook_pitch(const float angle);
	
	/**
	 * @brief set the free look direction rotation  speed, -1..1
	 * */
	void set_movement_direction(const float speed);
	
	/**
	 * @brief set the free look pitch rotation speed, -1..1
	 * */
	void set_movement_pitch(const float speed);
		
	/* --- actors ---------------------------------------------- */
	
	void reset();
	
	/**
	 * @brief update the camera location and axis.
	 * */
	void frame(const float elapsed);
	
	/**
	 * @brief draw the actual camera transformation
	 * This method is used to draw the camera projection for the world render
	 * and applies WORLDSCALE.
	 * */
	void draw();
	
	/**
	 * @brief draw the actual camera transformation
	 * This method variant is used by the user interface 3D model widget
	 * and ignores WORLDSCALE.
	 * */
	void draw(const float center_x, const float center_y);
	
	/* --- static ---------------------------------------------- */
	
	/**
	 * @brief set the current transformation matrix to a orthographic projection
	 * This method is used while drawing the user interface.
	 * */
	static void ortho();

private:
	Mode			_mode;
	
	float			_distance;
	float 			_multiplier;
	math::Vector3f		_location;
	math::Axis		_axis;	
		
	const core::Entity *	_target_entity;
	math::Vector3f		_target_location;
	math::Axis		_target_axis;	

	float 			_freelook_direction;	
	float 			_freelook_pitch;
	
	float			_movement_direction;
	float			_movement_pitch;

	
}; 	// class camera

} 	// namespace render

#endif 	// __INCLUDED_RENDER_CAMERA_H__