| 1 |
/* |
| 2 |
* Copyright (C) 2005-2021 Team Kodi (https://kodi.tv) |
| 3 |
* Copyright (C) 2005 Joakim Eriksson <[email protected]> |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <math.h> |
| 12 |
#include <stdint.h> |
| 13 |
|
| 14 |
/***************************** D E F I N E S *******************************/ |
| 15 |
|
| 16 |
typedef signed char s8; |
| 17 |
typedef unsigned char u8; |
| 18 |
typedef signed short s16; |
| 19 |
typedef unsigned short u16; |
| 20 |
typedef signed long s32; |
| 21 |
typedef unsigned long u32; |
| 22 |
typedef int64_t s64; |
| 23 |
typedef uint64_t u64; |
| 24 |
typedef float f32; |
| 25 |
typedef double f64; |
| 26 |
#define null 0 |
| 27 |
|
| 28 |
const f32 PI = 3.14159265358979323846f; |
| 29 |
const f32 FLOATEPSILON = 0.00001f; |
| 30 |
|
| 31 |
/****************************** M A C R O S ********************************/ |
| 32 |
|
| 33 |
#define SAFE_DELETE(_p) { if(_p) { delete _p; _p=NULL; } } |
| 34 |
#define SAFE_DELETE_ARRAY(_p) { if(_p) { delete [] _p; _p=NULL; } } |
| 35 |
#define SAFE_RELEASE(_p) { if(_p) { _p->Release(); _p=NULL; } } |
| 36 |
|
| 37 |
// Direct 3d verify |
| 38 |
#define DVERIFY( _func ) \ |
| 39 |
{ \ |
| 40 |
HRESULT _retCode = _func; \ |
| 41 |
if( _retCode != D3D_OK) \ |
| 42 |
{ \ |
| 43 |
char buf[2000]; \ |
| 44 |
sprintf(buf, "\""#_func"\" returned 0x%lx in\n" __FILE__ "(%ld)\n", _retCode, __LINE__); \ |
| 45 |
OutputDebugString(buf); \ |
| 46 |
return false; \ |
| 47 |
} \ |
| 48 |
} |
| 49 |
|
| 50 |
#define DEGTORAD(d) ((d)*(PI / 180.0f)) |
| 51 |
#define RADTODEG(r) ((r)*(180.0f / PI)) |
| 52 |
#define assert(_x) |
| 53 |
|
| 54 |
/***************************** C L A S S E S *******************************/ |
| 55 |
|
| 56 |
//////////////////////////////////////////////////////////////////////////// |
| 57 |
// |
| 58 |
class CRGBA |
| 59 |
{ |
| 60 |
public: |
| 61 |
union |
| 62 |
{ |
| 63 |
f32 col[4]; |
| 64 |
struct |
| 65 |
{ |
| 66 |
f32 r,g,b,a; |
| 67 |
}; |
| 68 |
}; |
| 69 |
|
| 70 |
CRGBA() |
| 71 |
{ |
| 72 |
col[0] = col[1] = col[2] = 1.0f; |
| 73 |
col[3] = 1.0f; |
| 74 |
} |
| 75 |
CRGBA(f32 R, f32 G, f32 B, f32 A) |
| 76 |
{ |
| 77 |
col[0]=R; col[1]=G; col[2]=B; col[3]=A; |
| 78 |
} |
| 79 |
|
| 80 |
void Set(f32 R, f32 G, f32 B, f32 A) |
| 81 |
{ |
| 82 |
col[0]=R; |
| 83 |
col[1]=G; |
| 84 |
col[2]=B; |
| 85 |
col[3]=A; |
| 86 |
} |
| 87 |
|
| 88 |
CRGBA& operator = (const CRGBA& c) |
| 89 |
{ |
| 90 |
r = c.r; |
| 91 |
g = c.g; |
| 92 |
b = c.b; |
| 93 |
a = c.a; |
| 94 |
return *this; |
| 95 |
} |
| 96 |
}; |
| 97 |
|
| 98 |
//////////////////////////////////////////////////////////////////////////// |
| 99 |
// |
| 100 |
class CVector |
| 101 |
{ |
| 102 |
public: |
| 103 |
CVector() { } |
| 104 |
CVector(f32 _x, f32 _y, f32 _z) |
| 105 |
{ |
| 106 |
x = _x; |
| 107 |
y = _y; |
| 108 |
z = _z; |
| 109 |
} |
| 110 |
|
| 111 |
void Zero() |
| 112 |
{ |
| 113 |
x = y = z = 0.0f; |
| 114 |
} |
| 115 |
|
| 116 |
void Set(f32 _x, f32 _y, f32 _z) |
| 117 |
{ |
| 118 |
x = _x; |
| 119 |
y = _y; |
| 120 |
z = _z; |
| 121 |
} |
| 122 |
|
| 123 |
f32 x; |
| 124 |
f32 y; |
| 125 |
f32 z; |
| 126 |
}; |
| 127 |
|
| 128 |
/***************************** G L O B A L S *******************************/ |
| 129 |
/***************************** I N L I N E S *******************************/ |
| 130 |
|
| 131 |
inline f32 Clamp(f32 x, f32 min, f32 max) { return (x <= min ? min : (x >= max ? max : x)); } |
| 132 |
inline f32 RandFloat(void) { return (1.0f / RAND_MAX) * ((f32)rand()); } |
| 133 |
inline int ISEQUAL(f32 a,f32 b,f32 absprec) { return (fabs((a)-(b))<=absprec); } |
| 134 |
inline int Rand(int max) { return rand() % max; } |
| 135 |
|
| 136 |
//////////////////////////////////////////////////////////////////////////// |
| 137 |
// |
| 138 |
inline f32 DotProduct(const CVector& v1, const CVector& v2) |
| 139 |
{ |
| 140 |
return v1.x*v2.x + v1.y * v2.y + v1.z*v2.z; |
| 141 |
} |