1
/************************************************************************************
3
AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
Copyright © 2006-2012 Michael Kurinnoy, Viewizard
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.
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.
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/>.
21
Web Site: http://www.viewizard.com/
22
Project: http://sourceforge.net/projects/openastromenace/
23
E-mail: viewizard@viewizard.com
25
*************************************************************************************/
36
inline void itoa10(int val, char* res)
38
// http://www.cplusplus.com/ref/cstdio/sprintf.html
39
// если нужны не 10-ки
40
sprintf(res,"%i",val);
45
double vw_dcos(int Angle);
47
double vw_dsin(int Angle);
49
float vw_sqrtf(float x);
53
// быстрое сравнение строк (по аналогии с strcmp)
54
int vw_strcmp(const char *a, const char *b);
57
// преобразуем утф8 в утф32, как результат возвращаем указатель на след утф8 символ
58
const char* utf8_to_utf32(const char* utf8, unsigned* utf32);
68
float vw_fRandNum(float 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);
81
// Нахождение максимального из 3
82
float Max3(float a1,float a2,float a3);
83
// Нахождение минимального из 3
84
float Min3(float a1,float a2,float a3);
88
// вектор в 3д пространстве
94
VECTOR3D(float nX, float nY, float nZ) { x = nX; y = nY; z = nZ; };
97
bool operator == (const VECTOR3D &A)
102
bool operator != (const VECTOR3D &A)
103
{ return (A.x != x ||
107
friend float operator * (const VECTOR3D &A, const VECTOR3D &B)
108
{ return A.x * B.x + A.y * B.y + A.z * B.z; };
110
VECTOR3D operator ^ (const float C)
111
{ return VECTOR3D(x*C,y*C, z*C); };
113
VECTOR3D operator / (const float C)
114
{ return VECTOR3D(x/C,y/C, z/C); };
116
void operator *= (float C)
117
{ x *= C; y *= C; z *= C; };
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; };
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; };
134
void Multiply(VECTOR3D A);
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);
151
// матрица 4на4 (float Matrix[16])
153
// начальная установка
154
void Matrix44Identity(float Matrix44[16]);
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]);
167
// матрица 3на3 (float Matrix[9])
169
// начальная установка
170
void Matrix33Identity(float Matrix33[9]);
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]);