ScummVM API documentation
qdMath.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_MINIGAMES_ADV_QDMATH_H
23#define QDENGINE_MINIGAMES_ADV_QDMATH_H
24
25#include "qdengine/xmath.h"
26
27namespace QDEngine {
28
29#define SQRT2 1.41421356f
30#define SQRT3 1.73205081f
31
32inline float dist(const mgVect2f& v1, const mgVect2f& v2) {
33 return sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y));
34}
35
36inline float abs(const mgVect2f& v) {
37 return sqrt(v.x * v.x + v.y * v.y);
38}
39
40inline void norm(mgVect2f& v) {
41 float mod = abs(v);
42 if (mod < FLT_EPS) {
43 v = mgVect2f(0, 1);
44 return;
45 }
46 v.x /= mod;
47 v.y /= mod;
48}
49
50template<class T, class T1, class T2>
51inline T clamp(const T& x, const T1& xmin, const T2& xmax) {
52 if (x < xmin) return xmin;
53 if (x > xmax) return xmax;
54 return x;
55}
56
57template<class T>
58inline T abs(const T& x) {
59 if (x < 0) return -x;
60 return x;
61}
62
63} // namespace QDEngine
64
65#endif // QDENGINE_MINIGAMES_ADV_QDMATH_H
Базовый класс для игровых ресурсов.
Definition: console.h:28