Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 336 vs 337 for /trunk/Source Code/Libs/src/ReCast/DebugUtils/Source/DebugDraw.cpp

Diff revisions: vs.
  @@ -24,563 +24,563 @@
24 24
25 25 duDebugDraw::~duDebugDraw()
26 26 {
27 - // Empty
27 + // Empty
28 28 }
29 -
29 +
30 30
31 31 inline int bit(int a, int b)
32 32 {
33 - return (a & (1 << b)) >> b;
33 + return (a & (1 << b)) >> b;
34 34 }
35 35
36 36 unsigned int duIntToCol(int i, int a)
37 37 {
38 - int r = bit(i, 1) + bit(i, 3) * 2 + 1;
39 - int g = bit(i, 2) + bit(i, 4) * 2 + 1;
40 - int b = bit(i, 0) + bit(i, 5) * 2 + 1;
41 - return duRGBA(r*63,g*63,b*63,a);
38 + int r = bit(i, 1) + bit(i, 3) * 2 + 1;
39 + int g = bit(i, 2) + bit(i, 4) * 2 + 1;
40 + int b = bit(i, 0) + bit(i, 5) * 2 + 1;
41 + return duRGBA(r*63,g*63,b*63,a);
42 42 }
43 43
44 44 void duIntToCol(int i, float* col)
45 45 {
46 - int r = bit(i, 0) + bit(i, 3) * 2 + 1;
47 - int g = bit(i, 1) + bit(i, 4) * 2 + 1;
48 - int b = bit(i, 2) + bit(i, 5) * 2 + 1;
49 - col[0] = 1 - r*63.0f/255.0f;
50 - col[1] = 1 - g*63.0f/255.0f;
51 - col[2] = 1 - b*63.0f/255.0f;
46 + int r = bit(i, 0) + bit(i, 3) * 2 + 1;
47 + int g = bit(i, 1) + bit(i, 4) * 2 + 1;
48 + int b = bit(i, 2) + bit(i, 5) * 2 + 1;
49 + col[0] = 1 - r*63.0f/255.0f;
50 + col[1] = 1 - g*63.0f/255.0f;
51 + col[2] = 1 - b*63.0f/255.0f;
52 52 }
53 53
54 54 void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide)
55 55 {
56 - if (!colors) return;
57 -
58 - colors[0] = duMultCol(colTop, 250);
59 - colors[1] = duMultCol(colSide, 140);
60 - colors[2] = duMultCol(colSide, 165);
61 - colors[3] = duMultCol(colSide, 217);
62 - colors[4] = duMultCol(colSide, 165);
63 - colors[5] = duMultCol(colSide, 217);
56 + if (!colors) return;
57 +
58 + colors[0] = duMultCol(colTop, 250);
59 + colors[1] = duMultCol(colSide, 140);
60 + colors[2] = duMultCol(colSide, 165);
61 + colors[3] = duMultCol(colSide, 217);
62 + colors[4] = duMultCol(colSide, 165);
63 + colors[5] = duMultCol(colSide, 217);
64 64 }
65 65
66 66 void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
67 - float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
67 + float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
68 68 {
69 - if (!dd) return;
70 -
71 - dd->begin(DU_DRAW_LINES, lineWidth);
72 - duAppendCylinderWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
73 - dd->end();
69 + if (!dd) return;
70 +
71 + dd->begin(DU_DRAW_LINES, lineWidth);
72 + duAppendCylinderWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
73 + dd->end();
74 74 }
75 75
76 76 void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
77 - float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
77 + float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
78 78 {
79 - if (!dd) return;
80 -
81 - dd->begin(DU_DRAW_LINES, lineWidth);
82 - duAppendBoxWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
83 - dd->end();
79 + if (!dd) return;
80 +
81 + dd->begin(DU_DRAW_LINES, lineWidth);
82 + duAppendBoxWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
83 + dd->end();
84 84 }
85 85
86 86 void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
87 - const float x1, const float y1, const float z1, const float h,
88 - const float as0, const float as1, unsigned int col, const float lineWidth)
87 + const float x1, const float y1, const float z1, const float h,
88 + const float as0, const float as1, unsigned int col, const float lineWidth)
89 89 {
90 - if (!dd) return;
91 -
92 - dd->begin(DU_DRAW_LINES, lineWidth);
93 - duAppendArc(dd, x0,y0,z0, x1,y1,z1, h, as0, as1, col);
94 - dd->end();
90 + if (!dd) return;
91 +
92 + dd->begin(DU_DRAW_LINES, lineWidth);
93 + duAppendArc(dd, x0,y0,z0, x1,y1,z1, h, as0, as1, col);
94 + dd->end();
95 95 }
96 96
97 97 void duDebugDrawArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
98 - const float x1, const float y1, const float z1,
99 - const float as0, const float as1, unsigned int col, const float lineWidth)
98 + const float x1, const float y1, const float z1,
99 + const float as0, const float as1, unsigned int col, const float lineWidth)
100 100 {
101 - if (!dd) return;
102 -
103 - dd->begin(DU_DRAW_LINES, lineWidth);
104 - duAppendArrow(dd, x0,y0,z0, x1,y1,z1, as0, as1, col);
105 - dd->end();
101 + if (!dd) return;
102 +
103 + dd->begin(DU_DRAW_LINES, lineWidth);
104 + duAppendArrow(dd, x0,y0,z0, x1,y1,z1, as0, as1, col);
105 + dd->end();
106 106 }
107 107
108 108 void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
109 - const float r, unsigned int col, const float lineWidth)
109 + const float r, unsigned int col, const float lineWidth)
110 110 {
111 - if (!dd) return;
112 -
113 - dd->begin(DU_DRAW_LINES, lineWidth);
114 - duAppendCircle(dd, x,y,z, r, col);
115 - dd->end();
111 + if (!dd) return;
112 +
113 + dd->begin(DU_DRAW_LINES, lineWidth);
114 + duAppendCircle(dd, x,y,z, r, col);
115 + dd->end();
116 116 }
117 117
118 118 void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
119 - const float size, unsigned int col, const float lineWidth)
119 + const float size, unsigned int col, const float lineWidth)
120 120 {
121 - if (!dd) return;
122 -
123 - dd->begin(DU_DRAW_LINES, lineWidth);
124 - duAppendCross(dd, x,y,z, size, col);
125 - dd->end();
121 + if (!dd) return;
122 +
123 + dd->begin(DU_DRAW_LINES, lineWidth);
124 + duAppendCross(dd, x,y,z, size, col);
125 + dd->end();
126 126 }
127 127
128 128 void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
129 - float maxx, float maxy, float maxz, const unsigned int* fcol)
129 + float maxx, float maxy, float maxz, const unsigned int* fcol)
130 130 {
131 - if (!dd) return;
132 -
133 - dd->begin(DU_DRAW_QUADS);
134 - duAppendBox(dd, minx,miny,minz, maxx,maxy,maxz, fcol);
135 - dd->end();
131 + if (!dd) return;
132 +
133 + dd->begin(DU_DRAW_QUADS);
134 + duAppendBox(dd, minx,miny,minz, maxx,maxy,maxz, fcol);
135 + dd->end();
136 136 }
137 137
138 138 void duDebugDrawCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
139 - float maxx, float maxy, float maxz, unsigned int col)
139 + float maxx, float maxy, float maxz, unsigned int col)
140 140 {
141 - if (!dd) return;
142 -
143 - dd->begin(DU_DRAW_TRIS);
144 - duAppendCylinder(dd, minx,miny,minz, maxx,maxy,maxz, col);
145 - dd->end();
141 + if (!dd) return;
142 +
143 + dd->begin(DU_DRAW_TRIS);
144 + duAppendCylinder(dd, minx,miny,minz, maxx,maxy,maxz, col);
145 + dd->end();
146 146 }
147 147
148 148 void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
149 - const int w, const int h, const float size,
150 - const unsigned int col, const float lineWidth)
149 + const int w, const int h, const float size,
150 + const unsigned int col, const float lineWidth)
151 151 {
152 - if (!dd) return;
152 + if (!dd) return;
153 153
154 - dd->begin(DU_DRAW_LINES, lineWidth);
155 - for (int i = 0; i <= h; ++i)
156 - {
157 - dd->vertex(ox,oy,oz+i*size, col);
158 - dd->vertex(ox+w*size,oy,oz+i*size, col);
159 - }
160 - for (int i = 0; i <= w; ++i)
161 - {
162 - dd->vertex(ox+i*size,oy,oz, col);
163 - dd->vertex(ox+i*size,oy,oz+h*size, col);
164 - }
165 - dd->end();
154 + dd->begin(DU_DRAW_LINES, lineWidth);
155 + for (int i = 0; i <= h; ++i)
156 + {
157 + dd->vertex(ox,oy,oz+i*size, col);
158 + dd->vertex(ox+w*size,oy,oz+i*size, col);
159 + }
160 + for (int i = 0; i <= w; ++i)
161 + {
162 + dd->vertex(ox+i*size,oy,oz, col);
163 + dd->vertex(ox+i*size,oy,oz+h*size, col);
164 + }
165 + dd->end();
166 166 }
167 -
167 +
168 168
169 169 void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
170 - float maxx, float maxy, float maxz, unsigned int col)
170 + float maxx, float maxy, float maxz, unsigned int col)
171 171 {
172 - if (!dd) return;
172 + if (!dd) return;
173 173
174 - static const int NUM_SEG = 16;
175 - static float dir[NUM_SEG*2];
176 - static bool init = false;
177 - if (!init)
178 - {
179 - init = true;
180 - for (int i = 0; i < NUM_SEG; ++i)
181 - {
182 - const float a = (float)i/(float)NUM_SEG*DU_PI*2;
183 - dir[i*2] = dtMathCosf(a);
184 - dir[i*2+1] = dtMathSinf(a);
185 - }
186 - }
187 -
188 - const float cx = (maxx + minx)/2;
189 - const float cz = (maxz + minz)/2;
190 - const float rx = (maxx - minx)/2;
191 - const float rz = (maxz - minz)/2;
192 -
193 - for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
194 - {
195 - dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col);
196 - dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
197 - dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
198 - dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
199 - }
200 - for (int i = 0; i < NUM_SEG; i += NUM_SEG/4)
201 - {
202 - dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
203 - dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
204 - }
174 + static const int NUM_SEG = 16;
175 + static float dir[NUM_SEG*2];
176 + static bool init = false;
177 + if (!init)
178 + {
179 + init = true;
180 + for (int i = 0; i < NUM_SEG; ++i)
181 + {
182 + const float a = (float)i/(float)NUM_SEG*DU_PI*2;
183 + dir[i*2] = dtMathCosf(a);
184 + dir[i*2+1] = dtMathSinf(a);
185 + }
186 + }
187 +
188 + const float cx = (maxx + minx)/2;
189 + const float cz = (maxz + minz)/2;
190 + const float rx = (maxx - minx)/2;
191 + const float rz = (maxz - minz)/2;
192 +
193 + for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
194 + {
195 + dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col);
196 + dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
197 + dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
198 + dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
199 + }
200 + for (int i = 0; i < NUM_SEG; i += NUM_SEG/4)
201 + {
202 + dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
203 + dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
204 + }
205 205 }
206 206
207 207 void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
208 - float maxx, float maxy, float maxz, unsigned int col)
208 + float maxx, float maxy, float maxz, unsigned int col)
209 209 {
210 - if (!dd) return;
211 - // Top
212 - dd->vertex(minx, miny, minz, col);
213 - dd->vertex(maxx, miny, minz, col);
214 - dd->vertex(maxx, miny, minz, col);
215 - dd->vertex(maxx, miny, maxz, col);
216 - dd->vertex(maxx, miny, maxz, col);
217 - dd->vertex(minx, miny, maxz, col);
218 - dd->vertex(minx, miny, maxz, col);
219 - dd->vertex(minx, miny, minz, col);
220 -
221 - // bottom
222 - dd->vertex(minx, maxy, minz, col);
223 - dd->vertex(maxx, maxy, minz, col);
224 - dd->vertex(maxx, maxy, minz, col);
225 - dd->vertex(maxx, maxy, maxz, col);
226 - dd->vertex(maxx, maxy, maxz, col);
227 - dd->vertex(minx, maxy, maxz, col);
228 - dd->vertex(minx, maxy, maxz, col);
229 - dd->vertex(minx, maxy, minz, col);
230 -
231 - // Sides
232 - dd->vertex(minx, miny, minz, col);
233 - dd->vertex(minx, maxy, minz, col);
234 - dd->vertex(maxx, miny, minz, col);
235 - dd->vertex(maxx, maxy, minz, col);
236 - dd->vertex(maxx, miny, maxz, col);
237 - dd->vertex(maxx, maxy, maxz, col);
238 - dd->vertex(minx, miny, maxz, col);
239 - dd->vertex(minx, maxy, maxz, col);
210 + if (!dd) return;
211 + // Top
212 + dd->vertex(minx, miny, minz, col);
213 + dd->vertex(maxx, miny, minz, col);
214 + dd->vertex(maxx, miny, minz, col);
215 + dd->vertex(maxx, miny, maxz, col);
216 + dd->vertex(maxx, miny, maxz, col);
217 + dd->vertex(minx, miny, maxz, col);
218 + dd->vertex(minx, miny, maxz, col);
219 + dd->vertex(minx, miny, minz, col);
220 +
221 + // bottom
222 + dd->vertex(minx, maxy, minz, col);
223 + dd->vertex(maxx, maxy, minz, col);
224 + dd->vertex(maxx, maxy, minz, col);
225 + dd->vertex(maxx, maxy, maxz, col);
226 + dd->vertex(maxx, maxy, maxz, col);
227 + dd->vertex(minx, maxy, maxz, col);
228 + dd->vertex(minx, maxy, maxz, col);
229 + dd->vertex(minx, maxy, minz, col);
230 +
231 + // Sides
232 + dd->vertex(minx, miny, minz, col);
233 + dd->vertex(minx, maxy, minz, col);
234 + dd->vertex(maxx, miny, minz, col);
235 + dd->vertex(maxx, maxy, minz, col);
236 + dd->vertex(maxx, miny, maxz, col);
237 + dd->vertex(maxx, maxy, maxz, col);
238 + dd->vertex(minx, miny, maxz, col);
239 + dd->vertex(minx, maxy, maxz, col);
240 240 }
241 241
242 242 void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
243 - float maxx, float maxy, float maxz, unsigned int col)
243 + float maxx, float maxy, float maxz, unsigned int col)
244 244 {
245 - if (!dd) return;
246 - // Top
247 - dd->vertex(minx, miny, minz, col);
248 - dd->vertex(maxx, miny, minz, col);
249 - dd->vertex(maxx, miny, minz, col);
250 - dd->vertex(maxx, miny, maxz, col);
251 - dd->vertex(maxx, miny, maxz, col);
252 - dd->vertex(minx, miny, maxz, col);
253 - dd->vertex(minx, miny, maxz, col);
254 - dd->vertex(minx, miny, minz, col);
255 -
256 - // bottom
257 - dd->vertex(minx, maxy, minz, col);
258 - dd->vertex(maxx, maxy, minz, col);
259 - dd->vertex(maxx, maxy, minz, col);
260 - dd->vertex(maxx, maxy, maxz, col);
261 - dd->vertex(maxx, maxy, maxz, col);
262 - dd->vertex(minx, maxy, maxz, col);
263 - dd->vertex(minx, maxy, maxz, col);
264 - dd->vertex(minx, maxy, minz, col);
245 + if (!dd) return;
246 + // Top
247 + dd->vertex(minx, miny, minz, col);
248 + dd->vertex(maxx, miny, minz, col);
249 + dd->vertex(maxx, miny, minz, col);
250 + dd->vertex(maxx, miny, maxz, col);
251 + dd->vertex(maxx, miny, maxz, col);
252 + dd->vertex(minx, miny, maxz, col);
253 + dd->vertex(minx, miny, maxz, col);
254 + dd->vertex(minx, miny, minz, col);
255 +
256 + // bottom
257 + dd->vertex(minx, maxy, minz, col);
258 + dd->vertex(maxx, maxy, minz, col);
259 + dd->vertex(maxx, maxy, minz, col);
260 + dd->vertex(maxx, maxy, maxz, col);
261 + dd->vertex(maxx, maxy, maxz, col);
262 + dd->vertex(minx, maxy, maxz, col);
263 + dd->vertex(minx, maxy, maxz, col);
264 + dd->vertex(minx, maxy, minz, col);
265 265 }
266 266
267 267 void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
268 - float maxx, float maxy, float maxz, const unsigned int* fcol)
268 + float maxx, float maxy, float maxz, const unsigned int* fcol)
269 269 {
270 - if (!dd) return;
271 - const float verts[8*3] =
272 - {
273 - minx, miny, minz,
274 - maxx, miny, minz,
275 - maxx, miny, maxz,
276 - minx, miny, maxz,
277 - minx, maxy, minz,
278 - maxx, maxy, minz,
279 - maxx, maxy, maxz,
280 - minx, maxy, maxz,
281 - };
282 - static const unsigned char inds[6*4] =
283 - {
284 - 7, 6, 5, 4,
285 - 0, 1, 2, 3,
286 - 1, 5, 6, 2,
287 - 3, 7, 4, 0,
288 - 2, 6, 7, 3,
289 - 0, 4, 5, 1,
290 - };
291 -
292 - const unsigned char* in = inds;
293 - for (int i = 0; i < 6; ++i)
294 - {
295 - dd->vertex(&verts[*in*3], fcol[i]); in++;
296 - dd->vertex(&verts[*in*3], fcol[i]); in++;
297 - dd->vertex(&verts[*in*3], fcol[i]); in++;
298 - dd->vertex(&verts[*in*3], fcol[i]); in++;
299 - }
270 + if (!dd) return;
271 + const float verts[8*3] =
272 + {
273 + minx, miny, minz,
274 + maxx, miny, minz,
275 + maxx, miny, maxz,
276 + minx, miny, maxz,
277 + minx, maxy, minz,
278 + maxx, maxy, minz,
279 + maxx, maxy, maxz,
280 + minx, maxy, maxz,
281 + };
282 + static const unsigned char inds[6*4] =
283 + {
284 + 7, 6, 5, 4,
285 + 0, 1, 2, 3,
286 + 1, 5, 6, 2,
287 + 3, 7, 4, 0,
288 + 2, 6, 7, 3,
289 + 0, 4, 5, 1,
290 + };
291 +
292 + const unsigned char* in = inds;
293 + for (int i = 0; i < 6; ++i)
294 + {
295 + dd->vertex(&verts[*in*3], fcol[i]); in++;
296 + dd->vertex(&verts[*in*3], fcol[i]); in++;
297 + dd->vertex(&verts[*in*3], fcol[i]); in++;
298 + dd->vertex(&verts[*in*3], fcol[i]); in++;
299 + }
300 300 }
301 301
302 302 void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
303 - float maxx, float maxy, float maxz, unsigned int col)
303 + float maxx, float maxy, float maxz, unsigned int col)
304 304 {
305 - if (!dd) return;
306 -
307 - static const int NUM_SEG = 16;
308 - static float dir[NUM_SEG*2];
309 - static bool init = false;
310 - if (!init)
311 - {
312 - init = true;
313 - for (int i = 0; i < NUM_SEG; ++i)
314 - {
315 - const float a = (float)i/(float)NUM_SEG*DU_PI*2;
316 - dir[i*2] = cosf(a);
317 - dir[i*2+1] = sinf(a);
318 - }
319 - }
320 -
321 - unsigned int col2 = duMultCol(col, 160);
322 -
323 - const float cx = (maxx + minx)/2;
324 - const float cz = (maxz + minz)/2;
325 - const float rx = (maxx - minx)/2;
326 - const float rz = (maxz - minz)/2;
327 -
328 - for (int i = 2; i < NUM_SEG; ++i)
329 - {
330 - const int a = 0, b = i-1, c = i;
331 - dd->vertex(cx+dir[a*2+0]*rx, miny, cz+dir[a*2+1]*rz, col2);
332 - dd->vertex(cx+dir[b*2+0]*rx, miny, cz+dir[b*2+1]*rz, col2);
333 - dd->vertex(cx+dir[c*2+0]*rx, miny, cz+dir[c*2+1]*rz, col2);
334 - }
335 - for (int i = 2; i < NUM_SEG; ++i)
336 - {
337 - const int a = 0, b = i, c = i-1;
338 - dd->vertex(cx+dir[a*2+0]*rx, maxy, cz+dir[a*2+1]*rz, col);
339 - dd->vertex(cx+dir[b*2+0]*rx, maxy, cz+dir[b*2+1]*rz, col);
340 - dd->vertex(cx+dir[c*2+0]*rx, maxy, cz+dir[c*2+1]*rz, col);
341 - }
342 - for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
343 - {
344 - dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
345 - dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col2);
346 - dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
347 -
348 - dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
349 - dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
350 - dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
351 - }
305 + if (!dd) return;
306 +
307 + static const int NUM_SEG = 16;
308 + static float dir[NUM_SEG*2];
309 + static bool init = false;
310 + if (!init)
311 + {
312 + init = true;
313 + for (int i = 0; i < NUM_SEG; ++i)
314 + {
315 + const float a = (float)i/(float)NUM_SEG*DU_PI*2;
316 + dir[i*2] = cosf(a);
317 + dir[i*2+1] = sinf(a);
318 + }
319 + }
320 +
321 + unsigned int col2 = duMultCol(col, 160);
322 +
323 + const float cx = (maxx + minx)/2;
324 + const float cz = (maxz + minz)/2;
325 + const float rx = (maxx - minx)/2;
326 + const float rz = (maxz - minz)/2;
327 +
328 + for (int i = 2; i < NUM_SEG; ++i)
329 + {
330 + const int a = 0, b = i-1, c = i;
331 + dd->vertex(cx+dir[a*2+0]*rx, miny, cz+dir[a*2+1]*rz, col2);
332 + dd->vertex(cx+dir[b*2+0]*rx, miny, cz+dir[b*2+1]*rz, col2);
333 + dd->vertex(cx+dir[c*2+0]*rx, miny, cz+dir[c*2+1]*rz, col2);
334 + }
335 + for (int i = 2; i < NUM_SEG; ++i)
336 + {
337 + const int a = 0, b = i, c = i-1;
338 + dd->vertex(cx+dir[a*2+0]*rx, maxy, cz+dir[a*2+1]*rz, col);
339 + dd->vertex(cx+dir[b*2+0]*rx, maxy, cz+dir[b*2+1]*rz, col);
340 + dd->vertex(cx+dir[c*2+0]*rx, maxy, cz+dir[c*2+1]*rz, col);
341 + }
342 + for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
343 + {
344 + dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
345 + dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col2);
346 + dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
347 +
348 + dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
349 + dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
350 + dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
351 + }
352 352 }
353 353
354 354
355 355 inline void evalArc(const float x0, const float y0, const float z0,
356 - const float dx, const float dy, const float dz,
357 - const float h, const float u, float* res)
356 + const float dx, const float dy, const float dz,
357 + const float h, const float u, float* res)
358 358 {
359 - res[0] = x0 + dx * u;
360 - res[1] = y0 + dy * u + h * (1-(u*2-1)*(u*2-1));
361 - res[2] = z0 + dz * u;
359 + res[0] = x0 + dx * u;
360 + res[1] = y0 + dy * u + h * (1-(u*2-1)*(u*2-1));
361 + res[2] = z0 + dz * u;
362 362 }
363 363
364 364
365 365 inline void vcross(float* dest, const float* v1, const float* v2)
366 366 {
367 - dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
368 - dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
369 - dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
367 + dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
368 + dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
369 + dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
370 370 }
371 371
372 372 inline void vnormalize(float* v)
373 373 {
374 - float d = 1.0f / sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
375 - v[0] *= d;
376 - v[1] *= d;
377 - v[2] *= d;
374 + float d = 1.0f / sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
375 + v[0] *= d;
376 + v[1] *= d;
377 + v[2] *= d;
378 378 }
379 379
380 380 inline void vsub(float* dest, const float* v1, const float* v2)
381 381 {
382 - dest[0] = v1[0]-v2[0];
383 - dest[1] = v1[1]-v2[1];
384 - dest[2] = v1[2]-v2[2];
382 + dest[0] = v1[0]-v2[0];
383 + dest[1] = v1[1]-v2[1];
384 + dest[2] = v1[2]-v2[2];
385 385 }
386 386
387 387 inline float vdistSqr(const float* v1, const float* v2)
388 388 {
389 - const float x = v1[0]-v2[0];
390 - const float y = v1[1]-v2[1];
391 - const float z = v1[2]-v2[2];
392 - return x*x + y*y + z*z;
389 + const float x = v1[0]-v2[0];
390 + const float y = v1[1]-v2[1];
391 + const float z = v1[2]-v2[2];
392 + return x*x + y*y + z*z;
393 393 }
394 394
395 395
396 396 void appendArrowHead(struct duDebugDraw* dd, const float* p, const float* q,
397 - const float s, unsigned int col)
397 + const float s, unsigned int col)
398 398 {
399 - const float eps = 0.001f;
400 - if (!dd) return;
401 - if (vdistSqr(p,q) < eps*eps) return;
402 - float ax[3], ay[3] = {0,1,0}, az[3];
403 - vsub(az, q, p);
404 - vnormalize(az);
405 - vcross(ax, ay, az);
406 - vcross(ay, az, ax);
407 - vnormalize(ay);
408 -
409 - dd->vertex(p, col);
410 - // dd->vertex(p[0]+az[0]*s+ay[0]*s/2, p[1]+az[1]*s+ay[1]*s/2, p[2]+az[2]*s+ay[2]*s/2, col);
411 - dd->vertex(p[0]+az[0]*s+ax[0]*s/3, p[1]+az[1]*s+ax[1]*s/3, p[2]+az[2]*s+ax[2]*s/3, col);
412 -
413 - dd->vertex(p, col);
414 - // dd->vertex(p[0]+az[0]*s-ay[0]*s/2, p[1]+az[1]*s-ay[1]*s/2, p[2]+az[2]*s-ay[2]*s/2, col);
415 - dd->vertex(p[0]+az[0]*s-ax[0]*s/3, p[1]+az[1]*s-ax[1]*s/3, p[2]+az[2]*s-ax[2]*s/3, col);
416 -
399 + const float eps = 0.001f;
400 + if (!dd) return;
401 + if (vdistSqr(p,q) < eps*eps) return;
402 + float ax[3], ay[3] = {0,1,0}, az[3];
403 + vsub(az, q, p);
404 + vnormalize(az);
405 + vcross(ax, ay, az);
406 + vcross(ay, az, ax);
407 + vnormalize(ay);
408 +
409 + dd->vertex(p, col);
410 + // dd->vertex(p[0]+az[0]*s+ay[0]*s/2, p[1]+az[1]*s+ay[1]*s/2, p[2]+az[2]*s+ay[2]*s/2, col);
411 + dd->vertex(p[0]+az[0]*s+ax[0]*s/3, p[1]+az[1]*s+ax[1]*s/3, p[2]+az[2]*s+ax[2]*s/3, col);
412 +
413 + dd->vertex(p, col);
414 + // dd->vertex(p[0]+az[0]*s-ay[0]*s/2, p[1]+az[1]*s-ay[1]*s/2, p[2]+az[2]*s-ay[2]*s/2, col);
415 + dd->vertex(p[0]+az[0]*s-ax[0]*s/3, p[1]+az[1]*s-ax[1]*s/3, p[2]+az[2]*s-ax[2]*s/3, col);
416 +
417 417 }
418 418
419 419 void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
420 - const float x1, const float y1, const float z1, const float h,
421 - const float as0, const float as1, unsigned int col)
420 + const float x1, const float y1, const float z1, const float h,
421 + const float as0, const float as1, unsigned int col)
422 422 {
423 - if (!dd) return;
424 - static const int NUM_ARC_PTS = 8;
425 - static const float PAD = 0.05f;
426 - static const float ARC_PTS_SCALE = (1.0f-PAD*2) / (float)NUM_ARC_PTS;
427 - const float dx = x1 - x0;
428 - const float dy = y1 - y0;
429 - const float dz = z1 - z0;
430 - const float len = sqrtf(dx*dx + dy*dy + dz*dz);
431 - float prev[3];
432 - evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, prev);
433 - for (int i = 1; i <= NUM_ARC_PTS; ++i)
434 - {
435 - const float u = PAD + i * ARC_PTS_SCALE;
436 - float pt[3];
437 - evalArc(x0,y0,z0, dx,dy,dz, len*h, u, pt);
438 - dd->vertex(prev[0],prev[1],prev[2], col);
439 - dd->vertex(pt[0],pt[1],pt[2], col);
440 - prev[0] = pt[0]; prev[1] = pt[1]; prev[2] = pt[2];
441 - }
442 -
443 - // End arrows
444 - if (as0 > 0.001f)
445 - {
446 - float p[3], q[3];
447 - evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, p);
448 - evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD+0.05f, q);
449 - appendArrowHead(dd, p, q, as0, col);
450 - }
451 -
452 - if (as1 > 0.001f)
453 - {
454 - float p[3], q[3];
455 - evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-PAD, p);
456 - evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-(PAD+0.05f), q);
457 - appendArrowHead(dd, p, q, as1, col);
458 - }
423 + if (!dd) return;
424 + static const int NUM_ARC_PTS = 8;
425 + static const float PAD = 0.05f;
426 + static const float ARC_PTS_SCALE = (1.0f-PAD*2) / (float)NUM_ARC_PTS;
427 + const float dx = x1 - x0;
428 + const float dy = y1 - y0;
429 + const float dz = z1 - z0;
430 + const float len = sqrtf(dx*dx + dy*dy + dz*dz);
431 + float prev[3];
432 + evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, prev);
433 + for (int i = 1; i <= NUM_ARC_PTS; ++i)
434 + {
435 + const float u = PAD + i * ARC_PTS_SCALE;
436 + float pt[3];
437 + evalArc(x0,y0,z0, dx,dy,dz, len*h, u, pt);
438 + dd->vertex(prev[0],prev[1],prev[2], col);
439 + dd->vertex(pt[0],pt[1],pt[2], col);
440 + prev[0] = pt[0]; prev[1] = pt[1]; prev[2] = pt[2];
441 + }
442 +
443 + // End arrows
444 + if (as0 > 0.001f)
445 + {
446 + float p[3], q[3];
447 + evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, p);
448 + evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD+0.05f, q);
449 + appendArrowHead(dd, p, q, as0, col);
450 + }
451 +
452 + if (as1 > 0.001f)
453 + {
454 + float p[3], q[3];
455 + evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-PAD, p);
456 + evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-(PAD+0.05f), q);
457 + appendArrowHead(dd, p, q, as1, col);
458 + }
459 459 }
460 460
461 461 void duAppendArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
462 - const float x1, const float y1, const float z1,
463 - const float as0, const float as1, unsigned int col)
462 + const float x1, const float y1, const float z1,
463 + const float as0, const float as1, unsigned int col)
464 464 {
465 - if (!dd) return;
465 + if (!dd) return;
466 466
467 - dd->vertex(x0,y0,z0, col);
468 - dd->vertex(x1,y1,z1, col);
469 -
470 - // End arrows
471 - const float p[3] = {x0,y0,z0}, q[3] = {x1,y1,z1};
472 - if (as0 > 0.001f)
473 - appendArrowHead(dd, p, q, as0, col);
474 - if (as1 > 0.001f)
475 - appendArrowHead(dd, q, p, as1, col);
467 + dd->vertex(x0,y0,z0, col);
468 + dd->vertex(x1,y1,z1, col);
469 +
470 + // End arrows
471 + const float p[3] = {x0,y0,z0}, q[3] = {x1,y1,z1};
472 + if (as0 > 0.001f)
473 + appendArrowHead(dd, p, q, as0, col);
474 + if (as1 > 0.001f)
475 + appendArrowHead(dd, q, p, as1, col);
476 476 }
477 477
478 478 void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
479 - const float r, unsigned int col)
479 + const float r, unsigned int col)
480 480 {
481 - if (!dd) return;
482 - static const int NUM_SEG = 40;
483 - static float dir[40*2];
484 - static bool init = false;
485 - if (!init)
486 - {
487 - init = true;
488 - for (int i = 0; i < NUM_SEG; ++i)
489 - {
490 - const float a = (float)i/(float)NUM_SEG*DU_PI*2;
491 - dir[i*2] = cosf(a);
492 - dir[i*2+1] = sinf(a);
493 - }
494 - }
495 -
496 - for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
497 - {
498 - dd->vertex(x+dir[j*2+0]*r, y, z+dir[j*2+1]*r, col);
499 - dd->vertex(x+dir[i*2+0]*r, y, z+dir[i*2+1]*r, col);
500 - }
481 + if (!dd) return;
482 + static const int NUM_SEG = 40;
483 + static float dir[40*2];
484 + static bool init = false;
485 + if (!init)
486 + {
487 + init = true;
488 + for (int i = 0; i < NUM_SEG; ++i)
489 + {
490 + const float a = (float)i/(float)NUM_SEG*DU_PI*2;
491 + dir[i*2] = cosf(a);
492 + dir[i*2+1] = sinf(a);
493 + }
494 + }
495 +
496 + for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
497 + {
498 + dd->vertex(x+dir[j*2+0]*r, y, z+dir[j*2+1]*r, col);
499 + dd->vertex(x+dir[i*2+0]*r, y, z+dir[i*2+1]*r, col);
500 + }
501 501 }
502 502
503 503 void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
504 - const float s, unsigned int col)
504 + const float s, unsigned int col)
505 505 {
506 - if (!dd) return;
507 - dd->vertex(x-s,y,z, col);
508 - dd->vertex(x+s,y,z, col);
509 - dd->vertex(x,y-s,z, col);
510 - dd->vertex(x,y+s,z, col);
511 - dd->vertex(x,y,z-s, col);
512 - dd->vertex(x,y,z+s, col);
506 + if (!dd) return;
507 + dd->vertex(x-s,y,z, col);
508 + dd->vertex(x+s,y,z, col);
509 + dd->vertex(x,y-s,z, col);
510 + dd->vertex(x,y+s,z, col);
511 + dd->vertex(x,y,z-s, col);
512 + dd->vertex(x,y,z+s, col);
513 513 }
514 514
515 515 duDisplayList::duDisplayList(int cap) :
516 - m_pos(0),
517 - m_color(0),
518 - m_size(0),
519 - m_cap(0),
520 - m_depthMask(true),
521 - m_prim(DU_DRAW_LINES),
522 - m_primSize(1.0f)
523 - {
524 - if (cap < 8)
525 - cap = 8;
526 - resize(cap);
516 + m_pos(0),
517 + m_color(0),
518 + m_size(0),
519 + m_cap(0),
520 + m_depthMask(true),
521 + m_prim(DU_DRAW_LINES),
522 + m_primSize(1.0f)
523 + {
524 + if (cap < 8)
525 + cap = 8;
526 + resize(cap);
527 527 }
528 528
529 529 duDisplayList::~duDisplayList()
530 530 {
531 - delete [] m_pos;
532 - delete [] m_color;
531 + delete [] m_pos;
532 + delete [] m_color;
533 533 }
534 534
535 535 void duDisplayList::resize(int cap)
536 536 {
537 - float* newPos = new float[cap*3];
538 - if (m_size)
539 - memcpy(newPos, m_pos, sizeof(float)*3*m_size);
540 - delete [] m_pos;
541 - m_pos = newPos;
542 -
543 - unsigned int* newColor = new unsigned int[cap];
544 - if (m_size)
545 - memcpy(newColor, m_color, sizeof(unsigned int)*m_size);
546 - delete [] m_color;
547 - m_color = newColor;
548 -
549 - m_cap = cap;
537 + float* newPos = new float[cap*3];
538 + if (m_size)
539 + memcpy(newPos, m_pos, sizeof(float)*3*m_size);
540 + delete [] m_pos;
541 + m_pos = newPos;
542 +
543 + unsigned int* newColor = new unsigned int[cap];
544 + if (m_size)
545 + memcpy(newColor, m_color, sizeof(unsigned int)*m_size);
546 + delete [] m_color;
547 + m_color = newColor;
548 +
549 + m_cap = cap;
550 550 }
551 551
552 552 void duDisplayList::clear()
553 553 {
554 - m_size = 0;
554 + m_size = 0;
555 555 }
556 556
557 557 void duDisplayList::depthMask(bool state)
558 558 {
559 - m_depthMask = state;
559 + m_depthMask = state;
560 560 }
561 561
562 562 void duDisplayList::begin(duDebugDrawPrimitives prim, float size)
563 563 {
564 - clear();
565 - m_prim = prim;
566 - m_primSize = size;
564 + clear();
565 + m_prim = prim;
566 + m_primSize = size;
567 567 }
568 568
569 569 void duDisplayList::vertex(const float x, const float y, const float z, unsigned int color)
570 570 {
571 - if (m_size+1 >= m_cap)
572 - resize(m_cap*2);
573 - float* p = &m_pos[m_size*3];
574 - p[0] = x;
575 - p[1] = y;
576 - p[2] = z;
577 - m_color[m_size] = color;
578 - m_size++;
571 + if (m_size+1 >= m_cap)
572 + resize(m_cap*2);
573 + float* p = &m_pos[m_size*3];
574 + p[0] = x;
575 + p[1] = y;
576 + p[2] = z;
577 + m_color[m_size] = color;
578 + m_size++;
579 579 }
580 580
581 581 void duDisplayList::vertex(const float* pos, unsigned int color)
582 582 {
583 - vertex(pos[0],pos[1],pos[2],color);
583 + vertex(pos[0],pos[1],pos[2],color);
584 584 }
585 585
586 586 void duDisplayList::end()
  @@ -589,11 +589,11 @@
589 589
590 590 void duDisplayList::draw(struct duDebugDraw* dd)
591 591 {
592 - if (!dd) return;
593 - if (!m_size) return;
594 - dd->depthMask(m_depthMask);
595 - dd->begin(m_prim, m_primSize);
596 - for (int i = 0; i < m_size; ++i)
597 - dd->vertex(&m_pos[i*3], m_color[i]);
598 - dd->end();
592 + if (!dd) return;
593 + if (!m_size) return;
594 + dd->depthMask(m_depthMask);
595 + dd->begin(m_prim, m_primSize);
596 + for (int i = 0; i < m_size; ++i)
597 + dd->vertex(&m_pos[i*3], m_color[i]);
598 + dd->end();
599 599 }