ScummVM API documentation
qd_camera.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_QDCORE_QD_CAMERA_H
23#define QDENGINE_QDCORE_QD_CAMERA_H
24
25#include "qdengine/qdcore/qd_d3dutils.h"
26#include "qdengine/qdcore/qd_camera_mode.h"
27
28namespace Common {
29class WriteStream;
30}
31
32namespace QDEngine {
33
34class sGridCell {
35public:
48 };
49
50 sGridCell() {
51 _attributes = CELL_IMPASSABLE;
52 }
53 sGridCell(uint16 atr, int16 h) {
54 _attributes = atr;
55 }
56 ~sGridCell() { }
57
58 bool is_walkable() const {
59 return !check_attribute(CELL_IMPASSABLE);
60 }
61 void make_impassable() {
62 set_attribute(CELL_IMPASSABLE);
63 }
64 void make_walkable() {
65 drop_attribute(CELL_IMPASSABLE);
66 }
67
68 void select() {
69 set_attribute(CELL_SELECTED);
70 }
71 void deselect() {
72 drop_attribute(CELL_SELECTED);
73 }
74 void toggle_select() {
75 toggle_attribute(CELL_SELECTED);
76 }
77 bool is_selected() const {
78 return check_attribute(CELL_SELECTED);
79 }
80
81 int16 height() const {
82 return 0;
83 }
84 void set_height(int16 h) { }
85
86 void set_attribute(uint32 attr) {
87 _attributes |= attr;
88 }
89 void toggle_attribute(uint32 attr) {
90 _attributes ^= attr;
91 }
92 void drop_attribute(uint32 attr) {
93 _attributes &= ~attr;
94 }
95 bool check_attribute(uint32 attr) const {
96 if (_attributes & attr) return true;
97 else return false;
98 }
99
100 uint32 attributes() const {
101 return _attributes;
102 }
103 void set_attributes(uint32 attr) {
104 _attributes = attr;
105 }
106
107 bool clear() {
108 _attributes = 0;
109 return true;
110 }
111
112private:
113 byte _attributes;
114};
115
116enum qdCameraRedrawMode {
117 QDCAM_GRID_ABOVE,
118 QDCAM_GRID_ZBUFFER,
119 QDCAM_GRID_NONE
120};
121
122class qdCamera {
123public:
124 qdCamera();
125 ~qdCamera();
126
127 // Устанавливет параметры клетки с координатами cell_pos
128 // по параметрам клетки cell
129 bool set_grid_cell(const Vect2s &cell_pos, const sGridCell &cell);
130 bool set_grid_cell_attributes(const Vect2s &cell_pos, int attr);
131
133 bool set_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr);
135 bool drop_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr);
137 bool check_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr) const;
139 int cells_num_with_exact_attributes(const Vect2s &center_pos, const Vect2s &size, int attr) const;
140
142 bool set_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr);
144 bool drop_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr);
146 bool check_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr) const;
147
148 bool is_walkable(const Vect2s &center_pos, const Vect2s &size, bool ignore_personages = false) const;
149
151 bool set_grid_attributes(int attr);
153 bool drop_grid_attributes(int attr);
154
155 sGridCell *get_cell(const Vect2s &cell_pos);
156 const sGridCell *get_cell(const Vect2s &cell_pos) const;
157
158 // Восстанавливает параметры клетки (сейчас - делает ее непроходимой
159 // с нулевой высотой)
160 bool restore_grid_cell(const Vect2s cell_pos);
161
162 void cycle_coords(int &x, int &y) const;
163
164 void set_redraw_mode(int md) const {
165 _redraw_mode = md;
166 }
167 int get_redraw_mode() const {
168 return _redraw_mode;
169 }
170
171 void set_grid_size(int xs, int ys);
172
173 void scale_grid(int sx, int sy, int csx, int csy);
174 void resize_grid(int sx, int sy);
175
176 int get_grid_sx() const {
177 return _GSX;
178 }
179 int get_grid_sy() const {
180 return _GSY;
181 }
182
183 const sGridCell *get_grid() const {
184 return _grid;
185 }
186
187 int get_cell_sx() const {
188 return _cellSX;
189 }
190 int get_cell_sy() const {
191 return _cellSY;
192 }
193
194 void set_cell_size(int csx, int csy) {
195 _cellSX = csx;
196 _cellSY = csy;
197 }
198
199 void clear_grid();
200
201 // rotateAndScaling
202 void rotate_and_scale(float XA, float YA, float ZA, float kX, float kY, float kZ);
203
204 float get_focus() const {
205 return _focus;
206 }
207 void set_focus(float focus) {
208 _focus = focus;
209 }
210
211 void set_R(const float r);
212 float get_R() const {
213 return _m_fR;
214 }
215
216 float get_x_angle() const {
217 return _xAngle;
218 }
219 float get_y_angle() const {
220 return _yAngle;
221 }
222 float get_z_angle() const {
223 return _zAngle;
224 }
225
226 inline void set_scr_size(int xs, int ys) {
227 _scrSize.x = xs;
228 _scrSize.y = ys;
229 }
230
231 const Vect2i &get_scr_size() const {
232 return _scrSize;
233 }
234
235 // getScrSizeX
236 int get_scr_sx() const {
237 return _scrSize.x;
238 }
239 // getScrSizeY
240 int get_scr_sy() const {
241 return _scrSize.y;
242 }
243
244 void set_scr_center(int xc, int yc) {
245 _scrCenter.x = xc;
246 _scrCenter.y = yc;
247 }
248
249 const Vect2i &get_scr_center() const {
250 return _scrCenter;
251 }
252
253 int get_scr_center_x() const {
254 return _scrCenter.x;
255 }
256 int get_scr_center_y() const {
257 return _scrCenter.y;
258 }
259
260 const Vect2i screen_center_limit_x() const;
261 const Vect2i screen_center_limit_y() const;
262
263 const Vect2i &get_scr_offset() const {
264 return _scrOffset;
265 }
266 void set_scr_offset(const Vect2i &offs) {
267 _scrOffset = offs;
268 }
269
270 const Vect2i &get_scr_center_initial() const {
271 return _scrCenterInitial;
272 }
273 void set_scr_center_initial(const Vect2i &v) {
274 _scrCenterInitial = v;
275 }
276
277 void move_scr_center(int dxc, int dyc);
278
279 float scrolling_phase_x() const;
280 float scrolling_phase_y() const;
281
282 const Vect3f scr2plane(const Vect2s &scrPoint) const;
283 const Vect3f rscr2plane(const Vect2s &rscrPoint) const;
284
285 const Vect3f scr2plane_camera_coord(const Vect2s &scrPoint) const;
286 const Vect3f rscr2plane_camera_coord(const Vect2s &scrPoint) const;
287 const Vect2s plane2scr(const Vect3f &plnPoint) const;
288 const Vect2s plane2rscr(const Vect3f &plnPoint) const;
289
290 const Vect3f rscr2camera_coord(const Vect2s &rScrPoint, float z) const;
291 const Vect2s camera_coord2rscr(const Vect3f &coord) const;
292
293 const Vect2s rscr2scr(const Vect2s &v) const;
294 const Vect2s scr2rscr(const Vect2s &v) const;
295
296 const Vect2s camera_coord2scr(const Vect3f &coord) const;
297
298 const Vect3f scr2global(const Vect2s &vScrPoint, float zInCameraCoord) const;
299 const Vect3f rscr2global(const Vect2s rScrPoint, const float zInCameraCoord) const;
300 const Vect3f global2camera_coord(const Vect3f &glCoord) const;
301 const Vect3f camera_coord2global(const Vect3f &v) const;
302
303 const Vect2s global2scr(const Vect3f &glCoord) const;
304 const Vect2s global2rscr(const Vect3f &glCoord) const;
305
306 //обрезание отрезка по плоскости отсечения камеры
307 //возвращает false, если отрезок вообеще невидим
308 bool line_cutting(Vect3f &b, Vect3f &e) const;
310
313 bool clip_grid_line(Vect2s &v0, Vect2s &v1) const;
314
315 // getKScale
316 float get_scale(const Vect3f &glCoord) const;
317
318 const Vect3f &get_grid_center() const {
319 return _gridCenter;
320 }
321 void set_grid_center(const Vect3f &v) {
322 _gridCenter = v;
323 }
324
325 const sGridCell *get_cell(float X, float Y) const;
326 const Vect2s get_cell_index(float X, float Y, bool grid_crop = true) const;
327 const Vect2s get_cell_index(const Vect3f &v, bool grid_crop = true) const;
328 const Vect3f get_cell_coords(int x_idx, int y_idx) const;
329 const Vect3f get_cell_coords(const Vect2s &idxs) const;
330
331 void reset_all_select();
332 //принимает глобальные координаты
333 bool select_cell(int x, int y);
334
335 //принимает глобальные координаты
336 bool deselect_cell(int x, int y);
337
338 void load_script(const xml::tag *p);
339 bool save_script(Common::WriteStream &fh, int indent = 0) const;
340
342 bool load_data(Common::SeekableReadStream &fh, int save_version);
345
347 bool init();
348
349 bool draw_grid() const;
350 bool draw_cell(int x, int y, int z, int penWidth, uint32 color) const;
351
353
356 bool set_mode(const qdCameraMode &mode, qdGameObjectAnimated *object = NULL);
358 bool can_change_mode() const;
359
362 _default_object = p;
363 }
364
366 bool quant(float dt);
367
369
372 bool is_visible(const Vect2i &center_offs = Vect2i(0, 0)) const;
373
374 void set_cycle(bool cx, bool cy) {
375 _cycle_x = cx;
376 _cycle_y = cy;
377 }
378
379 void dump_grid(const char *file_name) const;
380
382 float scale_pow() const {
383 return _scale_pow;
384 }
385 void set_scale_pow(float sp) {
386 _scale_pow = sp;
387 }
388 float scale_z_offset() const {
389 return _scale_z_offset;
390 };
391 void set_scale_z_offset(float szo) {
392 _scale_z_offset = szo;
393 };
394
395 bool need_perspective_correction() const {
396 return (fabs(_scale_pow - 1) > 0.001 || fabs(_scale_z_offset) > 0.001);
397 }
398
400 const qdCameraMode &default_mode() const {
401 return _default_mode;
402 }
404 void set_default_mode(const qdCameraMode &mode) {
405 _default_mode = mode;
406 }
407
408 static qdCamera *current_camera() {
409 return _current_camera;
410 }
411 static void set_current_camera(qdCamera *p) {
412 _current_camera = p;
413 }
414
415 MATRIX3D const &get_view_matrix() const {
416 return _m_cam;
417 }
418
419private:
420
421 MATRIX3D _m_cam;
422 float _m_fR;
423 float _xAngle, _yAngle, _zAngle;
424
425 int _GSX, _GSY;
426 sGridCell *_grid;
427
428 bool _cycle_x;
429 bool _cycle_y;
430
431 int _cellSX, _cellSY;
432 float _focus;
433 // расстояние от центра рабочей области до
434 // верхнего левого угла окна
435 Vect2i _scrCenter;
436
437 // начальное расстояние от центра рабочей области до
438 // верхнего левого угла окна
439 Vect2i _scrCenterInitial;
440
441 // размер рабочей области
442 Vect2i _scrSize;
443 // смещение рабочей области
444 Vect2i _scrOffset;
445
446 // Координаты центра сетки
447 Vect3f _gridCenter;
448
449 mutable int _redraw_mode;
450
452 qdCameraMode _current_mode;
453
455 float _current_mode_work_time;
456 bool _current_mode_switch;
457
459 qdGameObjectAnimated *_current_object;
460
462 qdGameObjectAnimated *_default_object;
464 qdCameraMode _default_mode;
465
467 float _scale_pow;
468 float _scale_z_offset;
469
470 static qdCamera *_current_camera;
471
472 static const float _NEAR_PLANE; //ближная плоскость отсечения
473 static const float _FAR_PLANE; //дальняя
474
475 enum {
476 clLEFT = 1,
477 clRIGHT = 2,
478 clBOTTOM = 4,
479 clTOP = 8
480 };
481
482 inline int clip_out_code(const Vect2s &v) const {
483 int code = 0;
484 if (v.y >= _GSY)
485 code |= clTOP;
486 else if (v.y < 0)
487 code |= clBOTTOM;
488 if (v.x >= _GSX)
489 code |= clRIGHT;
490 else if (v.x < 0)
491 code |= clLEFT;
492
493 return code;
494 }
495
496 void clip_center_coords(int &x, int &y) const;
497};
498
499inline Vect3f To3D(const Vect2f &v) {
500 return Vect3f(v.x, v.y, 0);
501}
502
503} // namespace QDEngine
504
505#endif // QDENGINE_QDCORE_QD_CAMERA_H
Definition: stream.h:745
Definition: stream.h:77
Definition: xmath.h:268
Definition: xmath.h:419
Definition: xmath.h:533
Definition: qd_camera.h:122
bool set_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr)
Устанавливает атрибуты для клеток из прямоугольника на сетке с ценром center_pos и размерами size.
bool can_change_mode() const
Возвращает true, если в данный момент можно менять режим камеры.
bool drop_grid_attributes(int attr)
Очищает атрибуты attr для всех клеток сетки.
bool set_grid_attributes(int attr)
Устанавливает атрибуты attr для всех клеток сетки.
bool set_mode(const qdCameraMode &mode, qdGameObjectAnimated *object=NULL)
Установка текущего режима камеры.
bool check_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr) const
Возвращает true, если в прямоугольнике на сетке ЕСТЬ ХОТЯ БЫ ОДНА ячейка с атрибутами attr.
void set_default_object(qdGameObjectAnimated *p)
Установка объекта, за которым камера следит по умолчанию.
Definition: qd_camera.h:361
bool load_data(Common::SeekableReadStream &fh, int save_version)
Загрузка данных из сэйва.
int cells_num_with_exact_attributes(const Vect2s &center_pos, const Vect2s &size, int attr) const
Возвращает количество ячеек в заданной области, имеющих именно аттрибуты attr.
bool init()
Инициализация данных, вызывается при старте и перезапуске игры.
const qdCameraMode & default_mode() const
Возвращает режим работы камеры по умолчанию.
Definition: qd_camera.h:400
bool quant(float dt)
Обсчет логики (движения камеры и т.д), параметр - время в секундах.
void set_default_mode(const qdCameraMode &mode)
Установка режима работы камеры по умолчанию.
Definition: qd_camera.h:404
bool drop_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr)
Очищает атрибуты для линии клеток.
bool set_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr)
Устанавливает атрибуты для линии клеток.
bool clip_grid_line(Vect2s &v0, Vect2s &v1) const
Обрезка линиии, так чтобы она за сетку не выходила.
bool check_grid_line_attributes(const Vect2s &start_pos, const Vect2s &end_pos, const Vect2s &size, int attr) const
Возвращает true, если в линии на сетке есть хотя бы одна ячейка с атрибутами attr.
bool drop_grid_attributes(const Vect2s &center_pos, const Vect2s &size, int attr)
Очищает атрибуты для клеток из прямоугольника на сетке с ценром center_pos и размерами size.
float scale_pow() const
Параметры функции масштабирования
Definition: qd_camera.h:382
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
bool is_visible(const Vect2i &center_offs=Vect2i(0, 0)) const
Возвращает false, если вся рабочая область камеры находится за пределами экрана.
Режим работы камеры.
Definition: qd_camera_mode.h:40
Dynamic object.
Definition: qd_game_object_animated.h:37
Definition: qd_camera.h:34
cell_attribute_t
Атрибуты
Definition: qd_camera.h:37
@ CELL_OCCUPIED
ячейка занята объектом
Definition: qd_camera.h:43
@ CELL_SELECTED
ячейка выделена
Definition: qd_camera.h:39
@ CELL_IMPASSABLE
ячейка непроходима
Definition: qd_camera.h:41
@ CELL_PERSONAGE_PATH
по ячейке проходит путь персонажа
Definition: qd_camera.h:47
@ CELL_PERSONAGE_OCCUPIED
ячейка занята персонажем
Definition: qd_camera.h:45
Definition: algorithm.h:29
Базовый класс для игровых ресурсов.
Definition: console.h:28