1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2006 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main programmer: Marco Biasini |
---|
13 | This files needs to be removed after code-revision... |
---|
14 | */ |
---|
15 | #ifndef TYPES_H |
---|
16 | #define TYPES_H |
---|
17 | |
---|
18 | #ifndef NULL |
---|
19 | #define NULL 0 |
---|
20 | #endif |
---|
21 | #include <math.h> |
---|
22 | #include "texture.h" |
---|
23 | |
---|
24 | #define SAVE_DELETE_ARRAY( _a ) if ( _a ) { delete[] _a; _a = NULL; } |
---|
25 | #define SAVE_DELETE( _a ) if ( _a ) { delete _a; _a = NULL; } |
---|
26 | |
---|
27 | struct Triple { |
---|
28 | Triple( float _x, float _y, float _z ) |
---|
29 | { |
---|
30 | x = _x; y = _y; z = _z; |
---|
31 | } |
---|
32 | Triple() { x = y = z = 0.0f; } |
---|
33 | inline float length() const |
---|
34 | { return sqrt( x*x+y*y+z*z ); } |
---|
35 | float x, y, z; |
---|
36 | }; |
---|
37 | |
---|
38 | struct TexCoord { |
---|
39 | TexCoord( float _u, float _v ) |
---|
40 | { |
---|
41 | u = _u; v = _v; |
---|
42 | } |
---|
43 | TexCoord() { u = v = 0.0f; } |
---|
44 | float u, v; |
---|
45 | }; |
---|
46 | |
---|
47 | /** |
---|
48 | * Defines an axis aligned box. |
---|
49 | */ |
---|
50 | struct ABox { |
---|
51 | |
---|
52 | ABox( Triple _min, Triple _max) |
---|
53 | { |
---|
54 | corner = _min; |
---|
55 | x = _max.x-_min.x; |
---|
56 | y = _max.y-_min.y; |
---|
57 | z = _max.z-_min.z; |
---|
58 | } |
---|
59 | |
---|
60 | ABox() |
---|
61 | { |
---|
62 | corner = Triple( 0.0f, 0.0f, 0.0f ); |
---|
63 | x = y = z = 0.0f; |
---|
64 | } |
---|
65 | inline void set( const Triple& _min, const Triple& _max ) |
---|
66 | { |
---|
67 | setMin( _min ); setMax( _max ); |
---|
68 | } |
---|
69 | inline void setMax( const Triple& _max ) |
---|
70 | { |
---|
71 | x = _max.x-corner.x; |
---|
72 | y = _max.y-corner.y; |
---|
73 | z = _max.z-corner.z; |
---|
74 | } |
---|
75 | inline void setMin( const Triple& _min ) |
---|
76 | { |
---|
77 | corner = _min; |
---|
78 | } |
---|
79 | inline Triple vertexP( const Triple& _normal ) const |
---|
80 | { |
---|
81 | Triple res = corner; |
---|
82 | if ( _normal.x > 0 ) |
---|
83 | res.x+= x; |
---|
84 | if ( _normal.y > 0 ) |
---|
85 | res.y+= y; |
---|
86 | if ( _normal.z > 0 ) |
---|
87 | res.z+= z; |
---|
88 | |
---|
89 | return res; |
---|
90 | } |
---|
91 | inline Triple vertexN( const Triple& _normal ) const |
---|
92 | { |
---|
93 | Triple res = corner; |
---|
94 | if ( _normal.x < 0 ) |
---|
95 | res.x+= x; |
---|
96 | if ( _normal.y < 0 ) |
---|
97 | res.y+= y; |
---|
98 | if ( _normal.z < 0 ) |
---|
99 | res.z+= z; |
---|
100 | |
---|
101 | return res; |
---|
102 | |
---|
103 | } |
---|
104 | inline Triple min() const { return Triple(corner); } |
---|
105 | inline Triple max() const { return Triple( corner.x+x, corner.y+y, corner.z+z ); } |
---|
106 | Triple corner; |
---|
107 | float x, y, z; |
---|
108 | |
---|
109 | }; |
---|
110 | |
---|
111 | struct Plane { |
---|
112 | Plane() { n = Triple( 0.0f, 1.0f, 0.0f ); d = 0.0f; } |
---|
113 | inline void setCoefficients( float _nx, float _ny, float _nz, float _d ) |
---|
114 | { |
---|
115 | n = Triple( _nx, _ny, _nz ); |
---|
116 | float l = n.length(); |
---|
117 | n.x /= l; n.y/=l; n.z/=l; |
---|
118 | d = _d/l; |
---|
119 | } |
---|
120 | inline float distance( const Triple& _point ) const |
---|
121 | { |
---|
122 | return _point.x*n.x+_point.y*n.y+_point.z*n.z+d; |
---|
123 | } |
---|
124 | Triple n; |
---|
125 | float d; |
---|
126 | }; |
---|
127 | |
---|
128 | /** |
---|
129 | * TODO: Replace this method with the actual matrix multiplication code! |
---|
130 | */ |
---|
131 | inline void multMat(float *res,float *a, float *b) { |
---|
132 | |
---|
133 | |
---|
134 | for (int i=0;i<4;i++) { |
---|
135 | for (int j = 0;j < 4;j++) { |
---|
136 | res[i*4+j] = 0.0; |
---|
137 | for (int k = 0; k < 4; k++) { |
---|
138 | res[i*4+j] += a[i*4+k] * b[k*4+j]; |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | typedef unsigned char UByte; |
---|
144 | struct Heightfield { |
---|
145 | int width; |
---|
146 | int height; |
---|
147 | int pitch; |
---|
148 | UByte *data; |
---|
149 | Heightfield() { data = NULL; width=0;height=0;pitch=0;} |
---|
150 | }; |
---|
151 | |
---|
152 | struct LayerInfo { |
---|
153 | |
---|
154 | int envmode; |
---|
155 | float repeatX, |
---|
156 | repeatZ; |
---|
157 | Texture *alpha; |
---|
158 | Texture *detail; |
---|
159 | |
---|
160 | }; |
---|
161 | typedef enum { LV_FULL, LV_PARTIAL, LV_NO } LayerVisibility; |
---|
162 | |
---|
163 | struct BufferInfo { |
---|
164 | |
---|
165 | BufferInfo( unsigned int _vb, unsigned int _ib, |
---|
166 | unsigned int _numV, unsigned int _numI ) |
---|
167 | { |
---|
168 | vbIdentifier = _vb; ibIdentifier = _ib; |
---|
169 | numIndices = _numI; numVertices =_numV; |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | BufferInfo() |
---|
174 | { |
---|
175 | vbIdentifier = ibIdentifier = numIndices = numVertices = 0; |
---|
176 | } |
---|
177 | unsigned int vbIdentifier, |
---|
178 | ibIdentifier, |
---|
179 | numIndices, |
---|
180 | numVertices; |
---|
181 | }; |
---|
182 | #endif |
---|