~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/Core/Math/Math.h

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-04-09 02:04:25 UTC
  • Revision ID: package-import@ubuntu.com-20130409020425-a7fl9xk4diamw6di
Tags: upstream-1.3.1+repack
Import upstream version 1.3.1+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
 
 
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
 
4
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
5
 
 
6
 
 
7
        AstroMenace 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
        AstroMenace 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 AstroMenace. If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
 
 
21
        Web Site: http://www.viewizard.com/
 
22
        Project: http://sourceforge.net/projects/openastromenace/
 
23
        E-mail: viewizard@viewizard.com
 
24
 
 
25
*************************************************************************************/
 
26
 
 
27
 
 
28
#ifndef CoreMath_H
 
29
#define CoreMath_H
 
30
 
 
31
 
 
32
#include "../Base.h"
 
33
 
 
34
 
 
35
 
 
36
inline void itoa10(int val, char* res)
 
37
{
 
38
    // http://www.cplusplus.com/ref/cstdio/sprintf.html
 
39
    // если нужны не 10-ки
 
40
    sprintf(res,"%i",val);
 
41
}
 
42
 
 
43
 
 
44
// Get cosine
 
45
double  vw_dcos(int Angle);
 
46
// Get sine
 
47
double  vw_dsin(int Angle);
 
48
// быстрый sqrtf
 
49
float   vw_sqrtf(float x);
 
50
 
 
51
 
 
52
 
 
53
// быстрое сравнение строк (по аналогии с strcmp)
 
54
int             vw_strcmp(const char *a, const char *b);
 
55
 
 
56
 
 
57
// преобразуем утф8 в утф32, как результат возвращаем указатель на след утф8 символ
 
58
const char* utf8_to_utf32(const char* utf8, unsigned* utf32);
 
59
 
 
60
 
 
61
 
 
62
 
 
63
// Rand
 
64
 
 
65
// 0.0f - 1.0f
 
66
float   vw_fRand();
 
67
// 0.0f - Max
 
68
float   vw_fRandNum(float Max);
 
69
// 0 - Max
 
70
int             vw_iRandNum(int Max);
 
71
// возвращает значение -1.0f - 1.0f, результат стремится к нулю (!)
 
72
#define vw_Randf0      (vw_fRand()-vw_fRand())
 
73
// возвращает значение 0.0f - 1.0f
 
74
#define vw_Randf1               vw_fRand()
 
75
// макрос, проверяет значение с учетом допустимых пределов
 
76
#define Clamp(x, min, max)  x = (x<min  ? min : x<max ? x : max);
 
77
 
 
78
 
 
79
 
 
80
 
 
81
// Нахождение максимального из 3
 
82
float Max3(float a1,float a2,float a3);
 
83
// Нахождение минимального из 3
 
84
float Min3(float a1,float a2,float a3);
 
85
 
 
86
 
 
87
 
 
88
// вектор в 3д пространстве
 
89
struct VECTOR3D
 
90
{
 
91
        float x,y,z;
 
92
 
 
93
        VECTOR3D(){};
 
94
        VECTOR3D(float nX, float nY, float nZ) { x = nX; y = nY; z = nZ; };
 
95
        ~VECTOR3D(){};
 
96
        // Equal
 
97
        bool operator == (const VECTOR3D &A)
 
98
        { return (A.x == x &&
 
99
                        A.y == y &&
 
100
                        A.z == z); };
 
101
        // Not equal
 
102
        bool operator != (const VECTOR3D &A)
 
103
        { return (A.x != x ||
 
104
                        A.y != y ||
 
105
                        A.z != z); };
 
106
        // Multiply
 
107
        friend float operator * (const VECTOR3D &A, const VECTOR3D &B)
 
108
        { return A.x * B.x + A.y * B.y + A.z * B.z; };
 
109
 
 
110
        VECTOR3D operator ^ (const float C)
 
111
        { return VECTOR3D(x*C,y*C, z*C); };
 
112
 
 
113
        VECTOR3D operator / (const float C)
 
114
        { return VECTOR3D(x/C,y/C, z/C); };
 
115
 
 
116
        void operator *= (float C)
 
117
        { x *= C; y *= C; z *= C; };
 
118
 
 
119
        // Add
 
120
        VECTOR3D operator + (const VECTOR3D &A)
 
121
        { return VECTOR3D(x + A.x, y + A.y, z + A.z); };
 
122
        void operator += (const VECTOR3D &A)
 
123
        { x += A.x; y += A.y; z += A.z; };
 
124
        // Subtract
 
125
        VECTOR3D operator - (const VECTOR3D &A)
 
126
        { return VECTOR3D(x - A.x, y - A.y, z - A.z); };
 
127
        void operator -= (const VECTOR3D &A)
 
128
        { x -= A.x; y -= A.y; z -= A.z; };
 
129
 
 
130
 
 
131
        float Length();
 
132
        void Normalize();
 
133
        void NormalizeHi();
 
134
        void Multiply(VECTOR3D A);
 
135
};
 
136
 
 
137
 
 
138
 
 
139
 
 
140
// вращение точки на углы
 
141
void RotatePoint(VECTOR3D *Point, VECTOR3D Angle);
 
142
void RotatePointInv(VECTOR3D *Point, VECTOR3D Angle);
 
143
// получение данных плоскости по 3 -м точкам
 
144
void GetPlaneABCD(float *A, float *B, float *C, float *D, VECTOR3D Point1, VECTOR3D Point2, VECTOR3D Point3);
 
145
 
 
146
 
 
147
 
 
148
 
 
149
 
 
150
 
 
151
// матрица 4на4 (float Matrix[16])
 
152
 
 
153
// начальная установка
 
154
void Matrix44Identity(float Matrix44[16]);
 
155
// перемножение
 
156
void Matrix44Mult(float DstMatrix44[16], float SrcMatrix44[16]);
 
157
// перенос в точку Location
 
158
void Matrix44Translate(float Matrix44[16], VECTOR3D Location);
 
159
// создаем матрицу поворота на углы Angle
 
160
void Matrix44CreateRotate(float Matrix44[16], VECTOR3D Angle);
 
161
// Получение обратной матрицы поворота
 
162
void Matrix44InverseRotate(float Matrix44[16]);
 
163
// Получаем точку по матрице трансформаций
 
164
void Matrix44CalcPoint(VECTOR3D *Point, float Matrix44[16]);
 
165
 
 
166
 
 
167
// матрица 3на3 (float Matrix[9])
 
168
 
 
169
// начальная установка
 
170
void Matrix33Identity(float Matrix33[9]);
 
171
// перемножение
 
172
void Matrix33Mult(float DstMatrix33[9], float SrcMatrix33[9]);
 
173
// создаем матрицу поворота на углы Angle
 
174
void Matrix33CreateRotate(float Matrix33[9], VECTOR3D Angle);
 
175
// Получение обратной матрицы поворота
 
176
void Matrix33InverseRotate(float Matrix33[9]);
 
177
// Получаем точку по матрице трансформаций
 
178
void Matrix33CalcPoint(VECTOR3D *Point, float Matrix33[9]);
 
179
 
 
180
 
 
181
 
 
182
 
 
183
#endif // CoreMath_H
 
184