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/RecastDebugDraw.cpp

Diff revisions: vs.
  @@ -23,1040 +23,1040 @@
23 23 #include "Recast.h"
24 24
25 25 void duDebugDrawTriMesh(duDebugDraw* dd, const float* verts, int /*nverts*/,
26 - const int* tris, const float* normals, int ntris,
27 - const unsigned char* flags, const float texScale)
26 + const int* tris, const float* normals, int ntris,
27 + const unsigned char* flags, const float texScale)
28 28 {
29 - if (!dd) return;
30 - if (!verts) return;
31 - if (!tris) return;
32 - if (!normals) return;
33 -
34 - float uva[2];
35 - float uvb[2];
36 - float uvc[2];
37 -
38 - const unsigned int unwalkable = duRGBA(192,128,0,255);
39 -
40 - dd->texture(true);
41 -
42 - dd->begin(DU_DRAW_TRIS);
43 - for (int i = 0; i < ntris*3; i += 3)
44 - {
45 - const float* norm = &normals[i];
46 - unsigned int color;
47 - unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
48 - if (flags && !flags[i/3])
49 - color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
50 - else
51 - color = duRGBA(a,a,a,255);
52 -
53 - const float* va = &verts[tris[i+0]*3];
54 - const float* vb = &verts[tris[i+1]*3];
55 - const float* vc = &verts[tris[i+2]*3];
56 -
57 - int ax = 0, ay = 0;
58 - if (rcAbs(norm[1]) > rcAbs(norm[ax]))
59 - ax = 1;
60 - if (rcAbs(norm[2]) > rcAbs(norm[ax]))
61 - ax = 2;
62 - ax = (1<<ax)&3; // +1 mod 3
63 - ay = (1<<ax)&3; // +1 mod 3
64 -
65 - uva[0] = va[ax]*texScale;
66 - uva[1] = va[ay]*texScale;
67 - uvb[0] = vb[ax]*texScale;
68 - uvb[1] = vb[ay]*texScale;
69 - uvc[0] = vc[ax]*texScale;
70 - uvc[1] = vc[ay]*texScale;
71 -
72 - dd->vertex(va, color, uva);
73 - dd->vertex(vb, color, uvb);
74 - dd->vertex(vc, color, uvc);
75 - }
76 - dd->end();
77 - dd->texture(false);
29 + if (!dd) return;
30 + if (!verts) return;
31 + if (!tris) return;
32 + if (!normals) return;
33 +
34 + float uva[2];
35 + float uvb[2];
36 + float uvc[2];
37 +
38 + const unsigned int unwalkable = duRGBA(192,128,0,255);
39 +
40 + dd->texture(true);
41 +
42 + dd->begin(DU_DRAW_TRIS);
43 + for (int i = 0; i < ntris*3; i += 3)
44 + {
45 + const float* norm = &normals[i];
46 + unsigned int color;
47 + unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
48 + if (flags && !flags[i/3])
49 + color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
50 + else
51 + color = duRGBA(a,a,a,255);
52 +
53 + const float* va = &verts[tris[i+0]*3];
54 + const float* vb = &verts[tris[i+1]*3];
55 + const float* vc = &verts[tris[i+2]*3];
56 +
57 + int ax = 0, ay = 0;
58 + if (rcAbs(norm[1]) > rcAbs(norm[ax]))
59 + ax = 1;
60 + if (rcAbs(norm[2]) > rcAbs(norm[ax]))
61 + ax = 2;
62 + ax = (1<<ax)&3; // +1 mod 3
63 + ay = (1<<ax)&3; // +1 mod 3
64 +
65 + uva[0] = va[ax]*texScale;
66 + uva[1] = va[ay]*texScale;
67 + uvb[0] = vb[ax]*texScale;
68 + uvb[1] = vb[ay]*texScale;
69 + uvc[0] = vc[ax]*texScale;
70 + uvc[1] = vc[ay]*texScale;
71 +
72 + dd->vertex(va, color, uva);
73 + dd->vertex(vb, color, uvb);
74 + dd->vertex(vc, color, uvc);
75 + }
76 + dd->end();
77 + dd->texture(false);
78 78 }
79 79
80 80 void duDebugDrawTriMeshSlope(duDebugDraw* dd, const float* verts, int /*nverts*/,
81 - const int* tris, const float* normals, int ntris,
82 - const float walkableSlopeAngle, const float texScale)
81 + const int* tris, const float* normals, int ntris,
82 + const float walkableSlopeAngle, const float texScale)
83 83 {
84 - if (!dd) return;
85 - if (!verts) return;
86 - if (!tris) return;
87 - if (!normals) return;
88 -
89 - const float walkableThr = cosf(walkableSlopeAngle/180.0f*DU_PI);
90 -
91 - float uva[2];
92 - float uvb[2];
93 - float uvc[2];
94 -
95 - dd->texture(true);
96 -
97 - const unsigned int unwalkable = duRGBA(192,128,0,255);
98 -
99 - dd->begin(DU_DRAW_TRIS);
100 - for (int i = 0; i < ntris*3; i += 3)
101 - {
102 - const float* norm = &normals[i];
103 - unsigned int color;
104 - unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
105 - if (norm[1] < walkableThr)
106 - color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
107 - else
108 - color = duRGBA(a,a,a,255);
109 -
110 - const float* va = &verts[tris[i+0]*3];
111 - const float* vb = &verts[tris[i+1]*3];
112 - const float* vc = &verts[tris[i+2]*3];
113 -
114 - int ax = 0, ay = 0;
115 - if (rcAbs(norm[1]) > rcAbs(norm[ax]))
116 - ax = 1;
117 - if (rcAbs(norm[2]) > rcAbs(norm[ax]))
118 - ax = 2;
119 - ax = (1<<ax)&3; // +1 mod 3
120 - ay = (1<<ax)&3; // +1 mod 3
121 -
122 - uva[0] = va[ax]*texScale;
123 - uva[1] = va[ay]*texScale;
124 - uvb[0] = vb[ax]*texScale;
125 - uvb[1] = vb[ay]*texScale;
126 - uvc[0] = vc[ax]*texScale;
127 - uvc[1] = vc[ay]*texScale;
128 -
129 - dd->vertex(va, color, uva);
130 - dd->vertex(vb, color, uvb);
131 - dd->vertex(vc, color, uvc);
132 - }
133 - dd->end();
84 + if (!dd) return;
85 + if (!verts) return;
86 + if (!tris) return;
87 + if (!normals) return;
88 +
89 + const float walkableThr = cosf(walkableSlopeAngle/180.0f*DU_PI);
90 +
91 + float uva[2];
92 + float uvb[2];
93 + float uvc[2];
94 +
95 + dd->texture(true);
96 +
97 + const unsigned int unwalkable = duRGBA(192,128,0,255);
98 +
99 + dd->begin(DU_DRAW_TRIS);
100 + for (int i = 0; i < ntris*3; i += 3)
101 + {
102 + const float* norm = &normals[i];
103 + unsigned int color;
104 + unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
105 + if (norm[1] < walkableThr)
106 + color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
107 + else
108 + color = duRGBA(a,a,a,255);
109 +
110 + const float* va = &verts[tris[i+0]*3];
111 + const float* vb = &verts[tris[i+1]*3];
112 + const float* vc = &verts[tris[i+2]*3];
113 +
114 + int ax = 0, ay = 0;
115 + if (rcAbs(norm[1]) > rcAbs(norm[ax]))
116 + ax = 1;
117 + if (rcAbs(norm[2]) > rcAbs(norm[ax]))
118 + ax = 2;
119 + ax = (1<<ax)&3; // +1 mod 3
120 + ay = (1<<ax)&3; // +1 mod 3
121 +
122 + uva[0] = va[ax]*texScale;
123 + uva[1] = va[ay]*texScale;
124 + uvb[0] = vb[ax]*texScale;
125 + uvb[1] = vb[ay]*texScale;
126 + uvc[0] = vc[ax]*texScale;
127 + uvc[1] = vc[ay]*texScale;
128 +
129 + dd->vertex(va, color, uva);
130 + dd->vertex(vb, color, uvb);
131 + dd->vertex(vc, color, uvc);
132 + }
133 + dd->end();
134 134
135 - dd->texture(false);
135 + dd->texture(false);
136 136 }
137 137
138 138 void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
139 139 {
140 - if (!dd) return;
140 + if (!dd) return;
141 141
142 - const float* orig = hf.bmin;
143 - const float cs = hf.cs;
144 - const float ch = hf.ch;
145 -
146 - const int w = hf.width;
147 - const int h = hf.height;
148 -
149 - unsigned int fcol[6];
150 - duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(255,255,255,255));
151 -
152 - dd->begin(DU_DRAW_QUADS);
153 -
154 - for (int y = 0; y < h; ++y)
155 - {
156 - for (int x = 0; x < w; ++x)
157 - {
158 - float fx = orig[0] + x*cs;
159 - float fz = orig[2] + y*cs;
160 - const rcSpan* s = hf.spans[x + y*w];
161 - while (s)
162 - {
163 - duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
164 - s = s->next;
165 - }
166 - }
167 - }
168 - dd->end();
142 + const float* orig = hf.bmin;
143 + const float cs = hf.cs;
144 + const float ch = hf.ch;
145 +
146 + const int w = hf.width;
147 + const int h = hf.height;
148 +
149 + unsigned int fcol[6];
150 + duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(255,255,255,255));
151 +
152 + dd->begin(DU_DRAW_QUADS);
153 +
154 + for (int y = 0; y < h; ++y)
155 + {
156 + for (int x = 0; x < w; ++x)
157 + {
158 + float fx = orig[0] + x*cs;
159 + float fz = orig[2] + y*cs;
160 + const rcSpan* s = hf.spans[x + y*w];
161 + while (s)
162 + {
163 + duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
164 + s = s->next;
165 + }
166 + }
167 + }
168 + dd->end();
169 169 }
170 170
171 171 void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
172 172 {
173 - if (!dd) return;
173 + if (!dd) return;
174 174
175 - const float* orig = hf.bmin;
176 - const float cs = hf.cs;
177 - const float ch = hf.ch;
178 -
179 - const int w = hf.width;
180 - const int h = hf.height;
181 -
182 - unsigned int fcol[6];
183 - duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(217,217,217,255));
184 -
185 - dd->begin(DU_DRAW_QUADS);
186 -
187 - for (int y = 0; y < h; ++y)
188 - {
189 - for (int x = 0; x < w; ++x)
190 - {
191 - float fx = orig[0] + x*cs;
192 - float fz = orig[2] + y*cs;
193 - const rcSpan* s = hf.spans[x + y*w];
194 - while (s)
195 - {
196 - if (s->area == RC_WALKABLE_AREA)
197 - fcol[0] = duRGBA(64,128,160,255);
198 - else if (s->area == RC_NULL_AREA)
199 - fcol[0] = duRGBA(64,64,64,255);
200 - else
201 - fcol[0] = duMultCol(duIntToCol(s->area, 255), 200);
202 -
203 - duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
204 - s = s->next;
205 - }
206 - }
207 - }
208 -
209 - dd->end();
175 + const float* orig = hf.bmin;
176 + const float cs = hf.cs;
177 + const float ch = hf.ch;
178 +
179 + const int w = hf.width;
180 + const int h = hf.height;
181 +
182 + unsigned int fcol[6];
183 + duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(217,217,217,255));
184 +
185 + dd->begin(DU_DRAW_QUADS);
186 +
187 + for (int y = 0; y < h; ++y)
188 + {
189 + for (int x = 0; x < w; ++x)
190 + {
191 + float fx = orig[0] + x*cs;
192 + float fz = orig[2] + y*cs;
193 + const rcSpan* s = hf.spans[x + y*w];
194 + while (s)
195 + {
196 + if (s->area == RC_WALKABLE_AREA)
197 + fcol[0] = duRGBA(64,128,160,255);
198 + else if (s->area == RC_NULL_AREA)
199 + fcol[0] = duRGBA(64,64,64,255);
200 + else
201 + fcol[0] = duMultCol(duIntToCol(s->area, 255), 200);
202 +
203 + duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
204 + s = s->next;
205 + }
206 + }
207 + }
208 +
209 + dd->end();
210 210 }
211 211
212 212 void duDebugDrawCompactHeightfieldSolid(duDebugDraw* dd, const rcCompactHeightfield& chf)
213 213 {
214 - if (!dd) return;
214 + if (!dd) return;
215 215
216 - const float cs = chf.cs;
217 - const float ch = chf.ch;
216 + const float cs = chf.cs;
217 + const float ch = chf.ch;
218 218
219 - dd->begin(DU_DRAW_QUADS);
220 -
221 - for (int y = 0; y < chf.height; ++y)
222 - {
223 - for (int x = 0; x < chf.width; ++x)
224 - {
225 - const float fx = chf.bmin[0] + x*cs;
226 - const float fz = chf.bmin[2] + y*cs;
227 - const rcCompactCell& c = chf.cells[x+y*chf.width];
228 -
229 - for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
230 - {
231 - const rcCompactSpan& s = chf.spans[i];
232 -
233 - unsigned int color;
234 - if (chf.areas[i] == RC_WALKABLE_AREA)
235 - color = duRGBA(0,192,255,64);
236 - else if (chf.areas[i] == RC_NULL_AREA)
237 - color = duRGBA(0,0,0,64);
238 - else
239 - color = duIntToCol(chf.areas[i], 255);
240 -
241 - const float fy = chf.bmin[1] + (s.y+1)*ch;
242 - dd->vertex(fx, fy, fz, color);
243 - dd->vertex(fx, fy, fz+cs, color);
244 - dd->vertex(fx+cs, fy, fz+cs, color);
245 - dd->vertex(fx+cs, fy, fz, color);
246 - }
247 - }
248 - }
249 - dd->end();
219 + dd->begin(DU_DRAW_QUADS);
220 +
221 + for (int y = 0; y < chf.height; ++y)
222 + {
223 + for (int x = 0; x < chf.width; ++x)
224 + {
225 + const float fx = chf.bmin[0] + x*cs;
226 + const float fz = chf.bmin[2] + y*cs;
227 + const rcCompactCell& c = chf.cells[x+y*chf.width];
228 +
229 + for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
230 + {
231 + const rcCompactSpan& s = chf.spans[i];
232 +
233 + unsigned int color;
234 + if (chf.areas[i] == RC_WALKABLE_AREA)
235 + color = duRGBA(0,192,255,64);
236 + else if (chf.areas[i] == RC_NULL_AREA)
237 + color = duRGBA(0,0,0,64);
238 + else
239 + color = duIntToCol(chf.areas[i], 255);
240 +
241 + const float fy = chf.bmin[1] + (s.y+1)*ch;
242 + dd->vertex(fx, fy, fz, color);
243 + dd->vertex(fx, fy, fz+cs, color);
244 + dd->vertex(fx+cs, fy, fz+cs, color);
245 + dd->vertex(fx+cs, fy, fz, color);
246 + }
247 + }
248 + }
249 + dd->end();
250 250 }
251 251
252 252 void duDebugDrawCompactHeightfieldRegions(duDebugDraw* dd, const rcCompactHeightfield& chf)
253 253 {
254 - if (!dd) return;
254 + if (!dd) return;
255 255
256 - const float cs = chf.cs;
257 - const float ch = chf.ch;
256 + const float cs = chf.cs;
257 + const float ch = chf.ch;
258 258
259 - dd->begin(DU_DRAW_QUADS);
259 + dd->begin(DU_DRAW_QUADS);
260 260
261 - for (int y = 0; y < chf.height; ++y)
262 - {
263 - for (int x = 0; x < chf.width; ++x)
264 - {
265 - const float fx = chf.bmin[0] + x*cs;
266 - const float fz = chf.bmin[2] + y*cs;
267 - const rcCompactCell& c = chf.cells[x+y*chf.width];
268 -
269 - for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
270 - {
271 - const rcCompactSpan& s = chf.spans[i];
272 - const float fy = chf.bmin[1] + (s.y)*ch;
273 - unsigned int color;
274 - if (s.reg)
275 - color = duIntToCol(s.reg, 192);
276 - else
277 - color = duRGBA(0,0,0,64);
278 -
279 - dd->vertex(fx, fy, fz, color);
280 - dd->vertex(fx, fy, fz+cs, color);
281 - dd->vertex(fx+cs, fy, fz+cs, color);
282 - dd->vertex(fx+cs, fy, fz, color);
283 - }
284 - }
285 - }
286 -
287 - dd->end();
261 + for (int y = 0; y < chf.height; ++y)
262 + {
263 + for (int x = 0; x < chf.width; ++x)
264 + {
265 + const float fx = chf.bmin[0] + x*cs;
266 + const float fz = chf.bmin[2] + y*cs;
267 + const rcCompactCell& c = chf.cells[x+y*chf.width];
268 +
269 + for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
270 + {
271 + const rcCompactSpan& s = chf.spans[i];
272 + const float fy = chf.bmin[1] + (s.y)*ch;
273 + unsigned int color;
274 + if (s.reg)
275 + color = duIntToCol(s.reg, 192);
276 + else
277 + color = duRGBA(0,0,0,64);
278 +
279 + dd->vertex(fx, fy, fz, color);
280 + dd->vertex(fx, fy, fz+cs, color);
281 + dd->vertex(fx+cs, fy, fz+cs, color);
282 + dd->vertex(fx+cs, fy, fz, color);
283 + }
284 + }
285 + }
286 +
287 + dd->end();
288 288 }
289 289
290 290
291 291 void duDebugDrawCompactHeightfieldDistance(duDebugDraw* dd, const rcCompactHeightfield& chf)
292 292 {
293 - if (!dd) return;
294 - if (!chf.dist) return;
295 -
296 - const float cs = chf.cs;
297 - const float ch = chf.ch;
298 -
299 - float maxd = chf.maxDistance;
300 - if (maxd < 1.0f) maxd = 1;
301 - const float dscale = 255.0f / maxd;
302 -
303 - dd->begin(DU_DRAW_QUADS);
304 -
305 - for (int y = 0; y < chf.height; ++y)
306 - {
307 - for (int x = 0; x < chf.width; ++x)
308 - {
309 - const float fx = chf.bmin[0] + x*cs;
310 - const float fz = chf.bmin[2] + y*cs;
311 - const rcCompactCell& c = chf.cells[x+y*chf.width];
312 -
313 - for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
314 - {
315 - const rcCompactSpan& s = chf.spans[i];
316 - const float fy = chf.bmin[1] + (s.y+1)*ch;
317 - const unsigned char cd = (unsigned char)(chf.dist[i] * dscale);
318 - const unsigned int color = duRGBA(cd,cd,cd,255);
319 - dd->vertex(fx, fy, fz, color);
320 - dd->vertex(fx, fy, fz+cs, color);
321 - dd->vertex(fx+cs, fy, fz+cs, color);
322 - dd->vertex(fx+cs, fy, fz, color);
323 - }
324 - }
325 - }
326 - dd->end();
293 + if (!dd) return;
294 + if (!chf.dist) return;
295 +
296 + const float cs = chf.cs;
297 + const float ch = chf.ch;
298 +
299 + float maxd = chf.maxDistance;
300 + if (maxd < 1.0f) maxd = 1;
301 + const float dscale = 255.0f / maxd;
302 +
303 + dd->begin(DU_DRAW_QUADS);
304 +
305 + for (int y = 0; y < chf.height; ++y)
306 + {
307 + for (int x = 0; x < chf.width; ++x)
308 + {
309 + const float fx = chf.bmin[0] + x*cs;
310 + const float fz = chf.bmin[2] + y*cs;
311 + const rcCompactCell& c = chf.cells[x+y*chf.width];
312 +
313 + for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
314 + {
315 + const rcCompactSpan& s = chf.spans[i];
316 + const float fy = chf.bmin[1] + (s.y+1)*ch;
317 + const unsigned char cd = (unsigned char)(chf.dist[i] * dscale);
318 + const unsigned int color = duRGBA(cd,cd,cd,255);
319 + dd->vertex(fx, fy, fz, color);
320 + dd->vertex(fx, fy, fz+cs, color);
321 + dd->vertex(fx+cs, fy, fz+cs, color);
322 + dd->vertex(fx+cs, fy, fz, color);
323 + }
324 + }
325 + }
326 + dd->end();
327 327 }
328 328
329 329 static void drawLayerPortals(duDebugDraw* dd, const rcHeightfieldLayer* layer)
330 330 {
331 - const float cs = layer->cs;
332 - const float ch = layer->ch;
333 - const int w = layer->width;
334 - const int h = layer->height;
335 -
336 - unsigned int pcol = duRGBA(255,255,255,255);
337 -
338 - const int segs[4*4] = {0,0,0,1, 0,1,1,1, 1,1,1,0, 1,0,0,0};
339 -
340 - // Layer portals
341 - dd->begin(DU_DRAW_LINES, 2.0f);
342 - for (int y = 0; y < h; ++y)
343 - {
344 - for (int x = 0; x < w; ++x)
345 - {
346 - const int idx = x+y*w;
347 - const int lh = (int)layer->heights[idx];
348 - if (lh == 255) continue;
349 -
350 - for (int dir = 0; dir < 4; ++dir)
351 - {
352 - if (layer->cons[idx] & (1<<(dir+4)))
353 - {
354 - const int* seg = &segs[dir*4];
355 - const float ax = layer->bmin[0] + (x+seg[0])*cs;
356 - const float ay = layer->bmin[1] + (lh+2)*ch;
357 - const float az = layer->bmin[2] + (y+seg[1])*cs;
358 - const float bx = layer->bmin[0] + (x+seg[2])*cs;
359 - const float by = layer->bmin[1] + (lh+2)*ch;
360 - const float bz = layer->bmin[2] + (y+seg[3])*cs;
361 - dd->vertex(ax, ay, az, pcol);
362 - dd->vertex(bx, by, bz, pcol);
363 - }
364 - }
365 - }
366 - }
367 - dd->end();
331 + const float cs = layer->cs;
332 + const float ch = layer->ch;
333 + const int w = layer->width;
334 + const int h = layer->height;
335 +
336 + unsigned int pcol = duRGBA(255,255,255,255);
337 +
338 + const int segs[4*4] = {0,0,0,1, 0,1,1,1, 1,1,1,0, 1,0,0,0};
339 +
340 + // Layer portals
341 + dd->begin(DU_DRAW_LINES, 2.0f);
342 + for (int y = 0; y < h; ++y)
343 + {
344 + for (int x = 0; x < w; ++x)
345 + {
346 + const int idx = x+y*w;
347 + const int lh = (int)layer->heights[idx];
348 + if (lh == 255) continue;
349 +
350 + for (int dir = 0; dir < 4; ++dir)
351 + {
352 + if (layer->cons[idx] & (1<<(dir+4)))
353 + {
354 + const int* seg = &segs[dir*4];
355 + const float ax = layer->bmin[0] + (x+seg[0])*cs;
356 + const float ay = layer->bmin[1] + (lh+2)*ch;
357 + const float az = layer->bmin[2] + (y+seg[1])*cs;
358 + const float bx = layer->bmin[0] + (x+seg[2])*cs;
359 + const float by = layer->bmin[1] + (lh+2)*ch;
360 + const float bz = layer->bmin[2] + (y+seg[3])*cs;
361 + dd->vertex(ax, ay, az, pcol);
362 + dd->vertex(bx, by, bz, pcol);
363 + }
364 + }
365 + }
366 + }
367 + dd->end();
368 368 }
369 369
370 370 void duDebugDrawHeightfieldLayer(duDebugDraw* dd, const struct rcHeightfieldLayer& layer, const int idx)
371 371 {
372 - const float cs = layer.cs;
373 - const float ch = layer.ch;
374 - const int w = layer.width;
375 - const int h = layer.height;
376 -
377 - unsigned int color = duIntToCol(idx+1, 255);
378 -
379 - // Layer bounds
380 - float bmin[3], bmax[3];
381 - bmin[0] = layer.bmin[0] + layer.minx*cs;
382 - bmin[1] = layer.bmin[1];
383 - bmin[2] = layer.bmin[2] + layer.miny*cs;
384 - bmax[0] = layer.bmin[0] + (layer.maxx+1)*cs;
385 - bmax[1] = layer.bmax[1];
386 - bmax[2] = layer.bmin[2] + (layer.maxy+1)*cs;
387 - duDebugDrawBoxWire(dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duTransCol(color,128), 2.0f);
388 -
389 - // Layer height
390 - dd->begin(DU_DRAW_QUADS);
391 - for (int y = 0; y < h; ++y)
392 - {
393 - for (int x = 0; x < w; ++x)
394 - {
395 - const int lidx = x+y*w;
396 - const int lh = (int)layer.heights[lidx];
397 - if (h == 0xff) continue;
398 - const unsigned char area = layer.areas[lidx];
399 -
400 - unsigned int col;
401 - if (area == RC_WALKABLE_AREA)
402 - col = duLerpCol(color, duRGBA(0,192,255,64), 32);
403 - else if (area == RC_NULL_AREA)
404 - col = duLerpCol(color, duRGBA(0,0,0,64), 32);
405 - else
406 - col = duLerpCol(color, duIntToCol(area, 255), 32);
407 -
408 - const float fx = layer.bmin[0] + x*cs;
409 - const float fy = layer.bmin[1] + (lh+1)*ch;
410 - const float fz = layer.bmin[2] + y*cs;
411 -
412 - dd->vertex(fx, fy, fz, col);
413 - dd->vertex(fx, fy, fz+cs, col);
414 - dd->vertex(fx+cs, fy, fz+cs, col);
415 - dd->vertex(fx+cs, fy, fz, col);
416 - }
417 - }
418 - dd->end();
419 -
420 - // Portals
421 - drawLayerPortals(dd, &layer);
372 + const float cs = layer.cs;
373 + const float ch = layer.ch;
374 + const int w = layer.width;
375 + const int h = layer.height;
376 +
377 + unsigned int color = duIntToCol(idx+1, 255);
378 +
379 + // Layer bounds
380 + float bmin[3], bmax[3];
381 + bmin[0] = layer.bmin[0] + layer.minx*cs;
382 + bmin[1] = layer.bmin[1];
383 + bmin[2] = layer.bmin[2] + layer.miny*cs;
384 + bmax[0] = layer.bmin[0] + (layer.maxx+1)*cs;
385 + bmax[1] = layer.bmax[1];
386 + bmax[2] = layer.bmin[2] + (layer.maxy+1)*cs;
387 + duDebugDrawBoxWire(dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duTransCol(color,128), 2.0f);
388 +
389 + // Layer height
390 + dd->begin(DU_DRAW_QUADS);
391 + for (int y = 0; y < h; ++y)
392 + {
393 + for (int x = 0; x < w; ++x)
394 + {
395 + const int lidx = x+y*w;
396 + const int lh = (int)layer.heights[lidx];
397 + if (h == 0xff) continue;
398 + const unsigned char area = layer.areas[lidx];
399 +
400 + unsigned int col;
401 + if (area == RC_WALKABLE_AREA)
402 + col = duLerpCol(color, duRGBA(0,192,255,64), 32);
403 + else if (area == RC_NULL_AREA)
404 + col = duLerpCol(color, duRGBA(0,0,0,64), 32);
405 + else
406 + col = duLerpCol(color, duIntToCol(area, 255), 32);
407 +
408 + const float fx = layer.bmin[0] + x*cs;
409 + const float fy = layer.bmin[1] + (lh+1)*ch;
410 + const float fz = layer.bmin[2] + y*cs;
411 +
412 + dd->vertex(fx, fy, fz, col);
413 + dd->vertex(fx, fy, fz+cs, col);
414 + dd->vertex(fx+cs, fy, fz+cs, col);
415 + dd->vertex(fx+cs, fy, fz, col);
416 + }
417 + }
418 + dd->end();
419 +
420 + // Portals
421 + drawLayerPortals(dd, &layer);
422 422 }
423 423
424 424 void duDebugDrawHeightfieldLayers(duDebugDraw* dd, const struct rcHeightfieldLayerSet& lset)
425 425 {
426 - if (!dd) return;
427 - for (int i = 0; i < lset.nlayers; ++i)
428 - duDebugDrawHeightfieldLayer(dd, lset.layers[i], i);
426 + if (!dd) return;
427 + for (int i = 0; i < lset.nlayers; ++i)
428 + duDebugDrawHeightfieldLayer(dd, lset.layers[i], i);
429 429 }
430 430
431 431 /*
432 432 void duDebugDrawLayerContours(duDebugDraw* dd, const struct rcLayerContourSet& lcset)
433 433 {
434 - if (!dd) return;
435 -
436 - const float* orig = lcset.bmin;
437 - const float cs = lcset.cs;
438 - const float ch = lcset.ch;
439 -
440 - const unsigned char a = 255;// (unsigned char)(alpha*255.0f);
441 -
442 - const int offs[2*4] = {-1,0, 0,1, 1,0, 0,-1};
443 -
444 - dd->begin(DU_DRAW_LINES, 2.0f);
445 -
446 - for (int i = 0; i < lcset.nconts; ++i)
447 - {
448 - const rcLayerContour& c = lcset.conts[i];
449 - unsigned int color = 0;
450 -
451 - color = duIntToCol(i, a);
452 -
453 - for (int j = 0; j < c.nverts; ++j)
454 - {
455 - const int k = (j+1) % c.nverts;
456 - const unsigned char* va = &c.verts[j*4];
457 - const unsigned char* vb = &c.verts[k*4];
458 - const float ax = orig[0] + va[0]*cs;
459 - const float ay = orig[1] + (va[1]+1+(i&1))*ch;
460 - const float az = orig[2] + va[2]*cs;
461 - const float bx = orig[0] + vb[0]*cs;
462 - const float by = orig[1] + (vb[1]+1+(i&1))*ch;
463 - const float bz = orig[2] + vb[2]*cs;
464 - unsigned int col = color;
465 - if ((va[3] & 0xf) != 0xf)
466 - {
467 - col = duRGBA(255,255,255,128);
468 - int d = va[3] & 0xf;
469 -
470 - const float cx = (ax+bx)*0.5f;
471 - const float cy = (ay+by)*0.5f;
472 - const float cz = (az+bz)*0.5f;
473 -
474 - const float dx = cx + offs[d*2+0]*2*cs;
475 - const float dy = cy;
476 - const float dz = cz + offs[d*2+1]*2*cs;
477 -
478 - dd->vertex(cx,cy,cz,duRGBA(255,0,0,255));
479 - dd->vertex(dx,dy,dz,duRGBA(255,0,0,255));
480 - }
481 -
482 - duAppendArrow(dd, ax,ay,az, bx,by,bz, 0.0f, cs*0.5f, col);
483 - }
484 - }
485 - dd->end();
486 -
487 - dd->begin(DU_DRAW_POINTS, 4.0f);
488 -
489 - for (int i = 0; i < lcset.nconts; ++i)
490 - {
491 - const rcLayerContour& c = lcset.conts[i];
492 - unsigned int color = 0;
493 -
494 - for (int j = 0; j < c.nverts; ++j)
495 - {
496 - const unsigned char* va = &c.verts[j*4];
497 -
498 - color = duDarkenCol(duIntToCol(i, a));
499 - if (va[3] & 0x80)
500 - color = duRGBA(255,0,0,255);
501 -
502 - float fx = orig[0] + va[0]*cs;
503 - float fy = orig[1] + (va[1]+1+(i&1))*ch;
504 - float fz = orig[2] + va[2]*cs;
505 - dd->vertex(fx,fy,fz, color);
506 - }
507 - }
508 - dd->end();
434 + if (!dd) return;
435 +
436 + const float* orig = lcset.bmin;
437 + const float cs = lcset.cs;
438 + const float ch = lcset.ch;
439 +
440 + const unsigned char a = 255;// (unsigned char)(alpha*255.0f);
441 +
442 + const int offs[2*4] = {-1,0, 0,1, 1,0, 0,-1};
443 +
444 + dd->begin(DU_DRAW_LINES, 2.0f);
445 +
446 + for (int i = 0; i < lcset.nconts; ++i)
447 + {
448 + const rcLayerContour& c = lcset.conts[i];
449 + unsigned int color = 0;
450 +
451 + color = duIntToCol(i, a);
452 +
453 + for (int j = 0; j < c.nverts; ++j)
454 + {
455 + const int k = (j+1) % c.nverts;
456 + const unsigned char* va = &c.verts[j*4];
457 + const unsigned char* vb = &c.verts[k*4];
458 + const float ax = orig[0] + va[0]*cs;
459 + const float ay = orig[1] + (va[1]+1+(i&1))*ch;
460 + const float az = orig[2] + va[2]*cs;
461 + const float bx = orig[0] + vb[0]*cs;
462 + const float by = orig[1] + (vb[1]+1+(i&1))*ch;
463 + const float bz = orig[2] + vb[2]*cs;
464 + unsigned int col = color;
465 + if ((va[3] & 0xf) != 0xf)
466 + {
467 + col = duRGBA(255,255,255,128);
468 + int d = va[3] & 0xf;
469 +
470 + const float cx = (ax+bx)*0.5f;
471 + const float cy = (ay+by)*0.5f;
472 + const float cz = (az+bz)*0.5f;
473 +
474 + const float dx = cx + offs[d*2+0]*2*cs;
475 + const float dy = cy;
476 + const float dz = cz + offs[d*2+1]*2*cs;
477 +
478 + dd->vertex(cx,cy,cz,duRGBA(255,0,0,255));
479 + dd->vertex(dx,dy,dz,duRGBA(255,0,0,255));
480 + }
481 +
482 + duAppendArrow(dd, ax,ay,az, bx,by,bz, 0.0f, cs*0.5f, col);
483 + }
484 + }
485 + dd->end();
486 +
487 + dd->begin(DU_DRAW_POINTS, 4.0f);
488 +
489 + for (int i = 0; i < lcset.nconts; ++i)
490 + {
491 + const rcLayerContour& c = lcset.conts[i];
492 + unsigned int color = 0;
493 +
494 + for (int j = 0; j < c.nverts; ++j)
495 + {
496 + const unsigned char* va = &c.verts[j*4];
497 +
498 + color = duDarkenCol(duIntToCol(i, a));
499 + if (va[3] & 0x80)
500 + color = duRGBA(255,0,0,255);
501 +
502 + float fx = orig[0] + va[0]*cs;
503 + float fy = orig[1] + (va[1]+1+(i&1))*ch;
504 + float fz = orig[2] + va[2]*cs;
505 + dd->vertex(fx,fy,fz, color);
506 + }
507 + }
508 + dd->end();
509 509 }
510 510
511 511 void duDebugDrawLayerPolyMesh(duDebugDraw* dd, const struct rcLayerPolyMesh& lmesh)
512 512 {
513 - if (!dd) return;
514 -
515 - const int nvp = lmesh.nvp;
516 - const float cs = lmesh.cs;
517 - const float ch = lmesh.ch;
518 - const float* orig = lmesh.bmin;
519 -
520 - const int offs[2*4] = {-1,0, 0,1, 1,0, 0,-1};
521 -
522 - dd->begin(DU_DRAW_TRIS);
523 -
524 - for (int i = 0; i < lmesh.npolys; ++i)
525 - {
526 - const unsigned short* p = &lmesh.polys[i*nvp*2];
527 -
528 - unsigned int color;
529 - if (lmesh.areas[i] == RC_WALKABLE_AREA)
530 - color = duRGBA(0,192,255,64);
531 - else if (lmesh.areas[i] == RC_NULL_AREA)
532 - color = duRGBA(0,0,0,64);
533 - else
534 - color = duIntToCol(lmesh.areas[i], 255);
535 -
536 - unsigned short vi[3];
537 - for (int j = 2; j < nvp; ++j)
538 - {
539 - if (p[j] == RC_MESH_NULL_IDX) break;
540 - vi[0] = p[0];
541 - vi[1] = p[j-1];
542 - vi[2] = p[j];
543 - for (int k = 0; k < 3; ++k)
544 - {
545 - const unsigned short* v = &lmesh.verts[vi[k]*3];
546 - const float x = orig[0] + v[0]*cs;
547 - const float y = orig[1] + (v[1]+1)*ch;
548 - const float z = orig[2] + v[2]*cs;
549 - dd->vertex(x,y,z, color);
550 - }
551 - }
552 - }
553 - dd->end();
554 -
555 - // Draw neighbours edges
556 - const unsigned int coln = duRGBA(0,48,64,32);
557 - dd->begin(DU_DRAW_LINES, 1.5f);
558 - for (int i = 0; i < lmesh.npolys; ++i)
559 - {
560 - const unsigned short* p = &lmesh.polys[i*nvp*2];
561 - for (int j = 0; j < nvp; ++j)
562 - {
563 - if (p[j] == RC_MESH_NULL_IDX) break;
564 - if (p[nvp+j] & 0x8000) continue;
565 - const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
566 - int vi[2] = {p[j], p[nj]};
567 -
568 - for (int k = 0; k < 2; ++k)
569 - {
570 - const unsigned short* v = &lmesh.verts[vi[k]*3];
571 - const float x = orig[0] + v[0]*cs;
572 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
573 - const float z = orig[2] + v[2]*cs;
574 - dd->vertex(x, y, z, coln);
575 - }
576 - }
577 - }
578 - dd->end();
579 -
580 - // Draw boundary edges
581 - const unsigned int colb = duRGBA(0,48,64,220);
582 - dd->begin(DU_DRAW_LINES, 2.5f);
583 - for (int i = 0; i < lmesh.npolys; ++i)
584 - {
585 - const unsigned short* p = &lmesh.polys[i*nvp*2];
586 - for (int j = 0; j < nvp; ++j)
587 - {
588 - if (p[j] == RC_MESH_NULL_IDX) break;
589 - if ((p[nvp+j] & 0x8000) == 0) continue;
590 - const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
591 - int vi[2] = {p[j], p[nj]};
592 -
593 - unsigned int col = colb;
594 - if ((p[nvp+j] & 0xf) != 0xf)
595 - {
596 - const unsigned short* va = &lmesh.verts[vi[0]*3];
597 - const unsigned short* vb = &lmesh.verts[vi[1]*3];
598 -
599 - const float ax = orig[0] + va[0]*cs;
600 - const float ay = orig[1] + (va[1]+1+(i&1))*ch;
601 - const float az = orig[2] + va[2]*cs;
602 - const float bx = orig[0] + vb[0]*cs;
603 - const float by = orig[1] + (vb[1]+1+(i&1))*ch;
604 - const float bz = orig[2] + vb[2]*cs;
605 -
606 - const float cx = (ax+bx)*0.5f;
607 - const float cy = (ay+by)*0.5f;
608 - const float cz = (az+bz)*0.5f;
609 -
610 - int d = p[nvp+j] & 0xf;
611 -
612 - const float dx = cx + offs[d*2+0]*2*cs;
613 - const float dy = cy;
614 - const float dz = cz + offs[d*2+1]*2*cs;
615 -
616 - dd->vertex(cx,cy,cz,duRGBA(255,0,0,255));
617 - dd->vertex(dx,dy,dz,duRGBA(255,0,0,255));
618 -
619 - col = duRGBA(255,255,255,128);
620 - }
621 -
622 - for (int k = 0; k < 2; ++k)
623 - {
624 - const unsigned short* v = &lmesh.verts[vi[k]*3];
625 - const float x = orig[0] + v[0]*cs;
626 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
627 - const float z = orig[2] + v[2]*cs;
628 - dd->vertex(x, y, z, col);
629 - }
630 - }
631 - }
632 - dd->end();
633 -
634 - dd->begin(DU_DRAW_POINTS, 3.0f);
635 - const unsigned int colv = duRGBA(0,0,0,220);
636 - for (int i = 0; i < lmesh.nverts; ++i)
637 - {
638 - const unsigned short* v = &lmesh.verts[i*3];
639 - const float x = orig[0] + v[0]*cs;
640 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
641 - const float z = orig[2] + v[2]*cs;
642 - dd->vertex(x,y,z, colv);
643 - }
644 - dd->end();
513 + if (!dd) return;
514 +
515 + const int nvp = lmesh.nvp;
516 + const float cs = lmesh.cs;
517 + const float ch = lmesh.ch;
518 + const float* orig = lmesh.bmin;
519 +
520 + const int offs[2*4] = {-1,0, 0,1, 1,0, 0,-1};
521 +
522 + dd->begin(DU_DRAW_TRIS);
523 +
524 + for (int i = 0; i < lmesh.npolys; ++i)
525 + {
526 + const unsigned short* p = &lmesh.polys[i*nvp*2];
527 +
528 + unsigned int color;
529 + if (lmesh.areas[i] == RC_WALKABLE_AREA)
530 + color = duRGBA(0,192,255,64);
531 + else if (lmesh.areas[i] == RC_NULL_AREA)
532 + color = duRGBA(0,0,0,64);
533 + else
534 + color = duIntToCol(lmesh.areas[i], 255);
535 +
536 + unsigned short vi[3];
537 + for (int j = 2; j < nvp; ++j)
538 + {
539 + if (p[j] == RC_MESH_NULL_IDX) break;
540 + vi[0] = p[0];
541 + vi[1] = p[j-1];
542 + vi[2] = p[j];
543 + for (int k = 0; k < 3; ++k)
544 + {
545 + const unsigned short* v = &lmesh.verts[vi[k]*3];
546 + const float x = orig[0] + v[0]*cs;
547 + const float y = orig[1] + (v[1]+1)*ch;
548 + const float z = orig[2] + v[2]*cs;
549 + dd->vertex(x,y,z, color);
550 + }
551 + }
552 + }
553 + dd->end();
554 +
555 + // Draw neighbours edges
556 + const unsigned int coln = duRGBA(0,48,64,32);
557 + dd->begin(DU_DRAW_LINES, 1.5f);
558 + for (int i = 0; i < lmesh.npolys; ++i)
559 + {
560 + const unsigned short* p = &lmesh.polys[i*nvp*2];
561 + for (int j = 0; j < nvp; ++j)
562 + {
563 + if (p[j] == RC_MESH_NULL_IDX) break;
564 + if (p[nvp+j] & 0x8000) continue;
565 + const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
566 + int vi[2] = {p[j], p[nj]};
567 +
568 + for (int k = 0; k < 2; ++k)
569 + {
570 + const unsigned short* v = &lmesh.verts[vi[k]*3];
571 + const float x = orig[0] + v[0]*cs;
572 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
573 + const float z = orig[2] + v[2]*cs;
574 + dd->vertex(x, y, z, coln);
575 + }
576 + }
577 + }
578 + dd->end();
579 +
580 + // Draw boundary edges
581 + const unsigned int colb = duRGBA(0,48,64,220);
582 + dd->begin(DU_DRAW_LINES, 2.5f);
583 + for (int i = 0; i < lmesh.npolys; ++i)
584 + {
585 + const unsigned short* p = &lmesh.polys[i*nvp*2];
586 + for (int j = 0; j < nvp; ++j)
587 + {
588 + if (p[j] == RC_MESH_NULL_IDX) break;
589 + if ((p[nvp+j] & 0x8000) == 0) continue;
590 + const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
591 + int vi[2] = {p[j], p[nj]};
592 +
593 + unsigned int col = colb;
594 + if ((p[nvp+j] & 0xf) != 0xf)
595 + {
596 + const unsigned short* va = &lmesh.verts[vi[0]*3];
597 + const unsigned short* vb = &lmesh.verts[vi[1]*3];
598 +
599 + const float ax = orig[0] + va[0]*cs;
600 + const float ay = orig[1] + (va[1]+1+(i&1))*ch;
601 + const float az = orig[2] + va[2]*cs;
602 + const float bx = orig[0] + vb[0]*cs;
603 + const float by = orig[1] + (vb[1]+1+(i&1))*ch;
604 + const float bz = orig[2] + vb[2]*cs;
605 +
606 + const float cx = (ax+bx)*0.5f;
607 + const float cy = (ay+by)*0.5f;
608 + const float cz = (az+bz)*0.5f;
609 +
610 + int d = p[nvp+j] & 0xf;
611 +
612 + const float dx = cx + offs[d*2+0]*2*cs;
613 + const float dy = cy;
614 + const float dz = cz + offs[d*2+1]*2*cs;
615 +
616 + dd->vertex(cx,cy,cz,duRGBA(255,0,0,255));
617 + dd->vertex(dx,dy,dz,duRGBA(255,0,0,255));
618 +
619 + col = duRGBA(255,255,255,128);
620 + }
621 +
622 + for (int k = 0; k < 2; ++k)
623 + {
624 + const unsigned short* v = &lmesh.verts[vi[k]*3];
625 + const float x = orig[0] + v[0]*cs;
626 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
627 + const float z = orig[2] + v[2]*cs;
628 + dd->vertex(x, y, z, col);
629 + }
630 + }
631 + }
632 + dd->end();
633 +
634 + dd->begin(DU_DRAW_POINTS, 3.0f);
635 + const unsigned int colv = duRGBA(0,0,0,220);
636 + for (int i = 0; i < lmesh.nverts; ++i)
637 + {
638 + const unsigned short* v = &lmesh.verts[i*3];
639 + const float x = orig[0] + v[0]*cs;
640 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
641 + const float z = orig[2] + v[2]*cs;
642 + dd->vertex(x,y,z, colv);
643 + }
644 + dd->end();
645 645 }
646 646 */
647 647
648 648 static void getContourCenter(const rcContour* cont, const float* orig, float cs, float ch, float* center)
649 649 {
650 - center[0] = 0;
651 - center[1] = 0;
652 - center[2] = 0;
653 - if (!cont->nverts)
654 - return;
655 - for (int i = 0; i < cont->nverts; ++i)
656 - {
657 - const int* v = &cont->verts[i*4];
658 - center[0] += (float)v[0];
659 - center[1] += (float)v[1];
660 - center[2] += (float)v[2];
661 - }
662 - const float s = 1.0f / cont->nverts;
663 - center[0] *= s * cs;
664 - center[1] *= s * ch;
665 - center[2] *= s * cs;
666 - center[0] += orig[0];
667 - center[1] += orig[1] + 4*ch;
668 - center[2] += orig[2];
650 + center[0] = 0;
651 + center[1] = 0;
652 + center[2] = 0;
653 + if (!cont->nverts)
654 + return;
655 + for (int i = 0; i < cont->nverts; ++i)
656 + {
657 + const int* v = &cont->verts[i*4];
658 + center[0] += (float)v[0];
659 + center[1] += (float)v[1];
660 + center[2] += (float)v[2];
661 + }
662 + const float s = 1.0f / cont->nverts;
663 + center[0] *= s * cs;
664 + center[1] *= s * ch;
665 + center[2] *= s * cs;
666 + center[0] += orig[0];
667 + center[1] += orig[1] + 4*ch;
668 + center[2] += orig[2];
669 669 }
670 670
671 671 static const rcContour* findContourFromSet(const rcContourSet& cset, unsigned short reg)
672 672 {
673 - for (int i = 0; i < cset.nconts; ++i)
674 - {
675 - if (cset.conts[i].reg == reg)
676 - return &cset.conts[i];
677 - }
678 - return 0;
673 + for (int i = 0; i < cset.nconts; ++i)
674 + {
675 + if (cset.conts[i].reg == reg)
676 + return &cset.conts[i];
677 + }
678 + return 0;
679 679 }
680 680
681 681 void duDebugDrawRegionConnections(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
682 682 {
683 - if (!dd) return;
684 -
685 - const float* orig = cset.bmin;
686 - const float cs = cset.cs;
687 - const float ch = cset.ch;
688 -
689 - // Draw centers
690 - float pos[3], pos2[3];
691 -
692 - unsigned int color = duRGBA(0,0,0,196);
693 -
694 - dd->begin(DU_DRAW_LINES, 2.0f);
695 -
696 - for (int i = 0; i < cset.nconts; ++i)
697 - {
698 - const rcContour* cont = &cset.conts[i];
699 - getContourCenter(cont, orig, cs, ch, pos);
700 - for (int j = 0; j < cont->nverts; ++j)
701 - {
702 - const int* v = &cont->verts[j*4];
703 - if (v[3] == 0 || (unsigned short)v[3] < cont->reg) continue;
704 - const rcContour* cont2 = findContourFromSet(cset, (unsigned short)v[3]);
705 - if (cont2)
706 - {
707 - getContourCenter(cont2, orig, cs, ch, pos2);
708 - duAppendArc(dd, pos[0],pos[1],pos[2], pos2[0],pos2[1],pos2[2], 0.25f, 0.6f, 0.6f, color);
709 - }
710 - }
711 - }
712 -
713 - dd->end();
714 -
715 - unsigned char a = (unsigned char)(alpha * 255.0f);
716 -
717 - dd->begin(DU_DRAW_POINTS, 7.0f);
718 -
719 - for (int i = 0; i < cset.nconts; ++i)
720 - {
721 - const rcContour* cont = &cset.conts[i];
722 - unsigned int col = duDarkenCol(duIntToCol(cont->reg,a));
723 - getContourCenter(cont, orig, cs, ch, pos);
724 - dd->vertex(pos, col);
725 - }
726 - dd->end();
683 + if (!dd) return;
684 +
685 + const float* orig = cset.bmin;
686 + const float cs = cset.cs;
687 + const float ch = cset.ch;
688 +
689 + // Draw centers
690 + float pos[3], pos2[3];
691 +
692 + unsigned int color = duRGBA(0,0,0,196);
693 +
694 + dd->begin(DU_DRAW_LINES, 2.0f);
695 +
696 + for (int i = 0; i < cset.nconts; ++i)
697 + {
698 + const rcContour* cont = &cset.conts[i];
699 + getContourCenter(cont, orig, cs, ch, pos);
700 + for (int j = 0; j < cont->nverts; ++j)
701 + {
702 + const int* v = &cont->verts[j*4];
703 + if (v[3] == 0 || (unsigned short)v[3] < cont->reg) continue;
704 + const rcContour* cont2 = findContourFromSet(cset, (unsigned short)v[3]);
705 + if (cont2)
706 + {
707 + getContourCenter(cont2, orig, cs, ch, pos2);
708 + duAppendArc(dd, pos[0],pos[1],pos[2], pos2[0],pos2[1],pos2[2], 0.25f, 0.6f, 0.6f, color);
709 + }
710 + }
711 + }
712 +
713 + dd->end();
714 +
715 + unsigned char a = (unsigned char)(alpha * 255.0f);
716 +
717 + dd->begin(DU_DRAW_POINTS, 7.0f);
718 +
719 + for (int i = 0; i < cset.nconts; ++i)
720 + {
721 + const rcContour* cont = &cset.conts[i];
722 + unsigned int col = duDarkenCol(duIntToCol(cont->reg,a));
723 + getContourCenter(cont, orig, cs, ch, pos);
724 + dd->vertex(pos, col);
725 + }
726 + dd->end();
727 727 }
728 728
729 729 void duDebugDrawRawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
730 730 {
731 - if (!dd) return;
731 + if (!dd) return;
732 732
733 - const float* orig = cset.bmin;
734 - const float cs = cset.cs;
735 - const float ch = cset.ch;
736 -
737 - const unsigned char a = (unsigned char)(alpha*255.0f);
738 -
739 - dd->begin(DU_DRAW_LINES, 2.0f);
740 -
741 - for (int i = 0; i < cset.nconts; ++i)
742 - {
743 - const rcContour& c = cset.conts[i];
744 - unsigned int color = duIntToCol(c.reg, a);
745 -
746 - for (int j = 0; j < c.nrverts; ++j)
747 - {
748 - const int* v = &c.rverts[j*4];
749 - float fx = orig[0] + v[0]*cs;
750 - float fy = orig[1] + (v[1]+1+(i&1))*ch;
751 - float fz = orig[2] + v[2]*cs;
752 - dd->vertex(fx,fy,fz,color);
753 - if (j > 0)
754 - dd->vertex(fx,fy,fz,color);
755 - }
756 - // Loop last segment.
757 - const int* v = &c.rverts[0];
758 - float fx = orig[0] + v[0]*cs;
759 - float fy = orig[1] + (v[1]+1+(i&1))*ch;
760 - float fz = orig[2] + v[2]*cs;
761 - dd->vertex(fx,fy,fz,color);
762 - }
763 - dd->end();
764 -
765 - dd->begin(DU_DRAW_POINTS, 2.0f);
766 -
767 - for (int i = 0; i < cset.nconts; ++i)
768 - {
769 - const rcContour& c = cset.conts[i];
770 - unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
771 -
772 - for (int j = 0; j < c.nrverts; ++j)
773 - {
774 - const int* v = &c.rverts[j*4];
775 - float off = 0;
776 - unsigned int colv = color;
777 - if (v[3] & RC_BORDER_VERTEX)
778 - {
779 - colv = duRGBA(255,255,255,a);
780 - off = ch*2;
781 - }
782 -
783 - float fx = orig[0] + v[0]*cs;
784 - float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
785 - float fz = orig[2] + v[2]*cs;
786 - dd->vertex(fx,fy,fz, colv);
787 - }
788 - }
789 - dd->end();
733 + const float* orig = cset.bmin;
734 + const float cs = cset.cs;
735 + const float ch = cset.ch;
736 +
737 + const unsigned char a = (unsigned char)(alpha*255.0f);
738 +
739 + dd->begin(DU_DRAW_LINES, 2.0f);
740 +
741 + for (int i = 0; i < cset.nconts; ++i)
742 + {
743 + const rcContour& c = cset.conts[i];
744 + unsigned int color = duIntToCol(c.reg, a);
745 +
746 + for (int j = 0; j < c.nrverts; ++j)
747 + {
748 + const int* v = &c.rverts[j*4];
749 + float fx = orig[0] + v[0]*cs;
750 + float fy = orig[1] + (v[1]+1+(i&1))*ch;
751 + float fz = orig[2] + v[2]*cs;
752 + dd->vertex(fx,fy,fz,color);
753 + if (j > 0)
754 + dd->vertex(fx,fy,fz,color);
755 + }
756 + // Loop last segment.
757 + const int* v = &c.rverts[0];
758 + float fx = orig[0] + v[0]*cs;
759 + float fy = orig[1] + (v[1]+1+(i&1))*ch;
760 + float fz = orig[2] + v[2]*cs;
761 + dd->vertex(fx,fy,fz,color);
762 + }
763 + dd->end();
764 +
765 + dd->begin(DU_DRAW_POINTS, 2.0f);
766 +
767 + for (int i = 0; i < cset.nconts; ++i)
768 + {
769 + const rcContour& c = cset.conts[i];
770 + unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
771 +
772 + for (int j = 0; j < c.nrverts; ++j)
773 + {
774 + const int* v = &c.rverts[j*4];
775 + float off = 0;
776 + unsigned int colv = color;
777 + if (v[3] & RC_BORDER_VERTEX)
778 + {
779 + colv = duRGBA(255,255,255,a);
780 + off = ch*2;
781 + }
782 +
783 + float fx = orig[0] + v[0]*cs;
784 + float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
785 + float fz = orig[2] + v[2]*cs;
786 + dd->vertex(fx,fy,fz, colv);
787 + }
788 + }
789 + dd->end();
790 790 }
791 791
792 792 void duDebugDrawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
793 793 {
794 - if (!dd) return;
794 + if (!dd) return;
795 795
796 - const float* orig = cset.bmin;
797 - const float cs = cset.cs;
798 - const float ch = cset.ch;
799 -
800 - const unsigned char a = (unsigned char)(alpha*255.0f);
801 -
802 - dd->begin(DU_DRAW_LINES, 2.5f);
803 -
804 - for (int i = 0; i < cset.nconts; ++i)
805 - {
806 - const rcContour& c = cset.conts[i];
807 - if (!c.nverts)
808 - continue;
809 - const unsigned int color = duIntToCol(c.reg, a);
810 - const unsigned int bcolor = duLerpCol(color,duRGBA(255,255,255,a),128);
811 - for (int j = 0, k = c.nverts-1; j < c.nverts; k=j++)
812 - {
813 - const int* va = &c.verts[k*4];
814 - const int* vb = &c.verts[j*4];
815 - unsigned int col = (va[3] & RC_AREA_BORDER) ? bcolor : color;
816 - float fx,fy,fz;
817 - fx = orig[0] + va[0]*cs;
818 - fy = orig[1] + (va[1]+1+(i&1))*ch;
819 - fz = orig[2] + va[2]*cs;
820 - dd->vertex(fx,fy,fz, col);
821 - fx = orig[0] + vb[0]*cs;
822 - fy = orig[1] + (vb[1]+1+(i&1))*ch;
823 - fz = orig[2] + vb[2]*cs;
824 - dd->vertex(fx,fy,fz, col);
825 - }
826 - }
827 - dd->end();
828 -
829 - dd->begin(DU_DRAW_POINTS, 3.0f);
830 -
831 - for (int i = 0; i < cset.nconts; ++i)
832 - {
833 - const rcContour& c = cset.conts[i];
834 - unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
835 - for (int j = 0; j < c.nverts; ++j)
836 - {
837 - const int* v = &c.verts[j*4];
838 - float off = 0;
839 - unsigned int colv = color;
840 - if (v[3] & RC_BORDER_VERTEX)
841 - {
842 - colv = duRGBA(255,255,255,a);
843 - off = ch*2;
844 - }
845 -
846 - float fx = orig[0] + v[0]*cs;
847 - float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
848 - float fz = orig[2] + v[2]*cs;
849 - dd->vertex(fx,fy,fz, colv);
850 - }
851 - }
852 - dd->end();
796 + const float* orig = cset.bmin;
797 + const float cs = cset.cs;
798 + const float ch = cset.ch;
799 +
800 + const unsigned char a = (unsigned char)(alpha*255.0f);
801 +
802 + dd->begin(DU_DRAW_LINES, 2.5f);
803 +
804 + for (int i = 0; i < cset.nconts; ++i)
805 + {
806 + const rcContour& c = cset.conts[i];
807 + if (!c.nverts)
808 + continue;
809 + const unsigned int color = duIntToCol(c.reg, a);
810 + const unsigned int bcolor = duLerpCol(color,duRGBA(255,255,255,a),128);
811 + for (int j = 0, k = c.nverts-1; j < c.nverts; k=j++)
812 + {
813 + const int* va = &c.verts[k*4];
814 + const int* vb = &c.verts[j*4];
815 + unsigned int col = (va[3] & RC_AREA_BORDER) ? bcolor : color;
816 + float fx,fy,fz;
817 + fx = orig[0] + va[0]*cs;
818 + fy = orig[1] + (va[1]+1+(i&1))*ch;
819 + fz = orig[2] + va[2]*cs;
820 + dd->vertex(fx,fy,fz, col);
821 + fx = orig[0] + vb[0]*cs;
822 + fy = orig[1] + (vb[1]+1+(i&1))*ch;
823 + fz = orig[2] + vb[2]*cs;
824 + dd->vertex(fx,fy,fz, col);
825 + }
826 + }
827 + dd->end();
828 +
829 + dd->begin(DU_DRAW_POINTS, 3.0f);
830 +
831 + for (int i = 0; i < cset.nconts; ++i)
832 + {
833 + const rcContour& c = cset.conts[i];
834 + unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
835 + for (int j = 0; j < c.nverts; ++j)
836 + {
837 + const int* v = &c.verts[j*4];
838 + float off = 0;
839 + unsigned int colv = color;
840 + if (v[3] & RC_BORDER_VERTEX)
841 + {
842 + colv = duRGBA(255,255,255,a);
843 + off = ch*2;
844 + }
845 +
846 + float fx = orig[0] + v[0]*cs;
847 + float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
848 + float fz = orig[2] + v[2]*cs;
849 + dd->vertex(fx,fy,fz, colv);
850 + }
851 + }
852 + dd->end();
853 853 }
854 854
855 855 void duDebugDrawPolyMesh(duDebugDraw* dd, const struct rcPolyMesh& mesh)
856 856 {
857 - if (!dd) return;
857 + if (!dd) return;
858 858
859 - const int nvp = mesh.nvp;
860 - const float cs = mesh.cs;
861 - const float ch = mesh.ch;
862 - const float* orig = mesh.bmin;
863 -
864 - dd->begin(DU_DRAW_TRIS);
865 -
866 - for (int i = 0; i < mesh.npolys; ++i)
867 - {
868 - const unsigned short* p = &mesh.polys[i*nvp*2];
869 -
870 - unsigned int color;
871 - if (mesh.areas[i] == RC_WALKABLE_AREA)
872 - color = duRGBA(0,192,255,64);
873 - else if (mesh.areas[i] == RC_NULL_AREA)
874 - color = duRGBA(0,0,0,64);
875 - else
876 - color = duIntToCol(mesh.areas[i], 255);
877 -
878 - unsigned short vi[3];
879 - for (int j = 2; j < nvp; ++j)
880 - {
881 - if (p[j] == RC_MESH_NULL_IDX) break;
882 - vi[0] = p[0];
883 - vi[1] = p[j-1];
884 - vi[2] = p[j];
885 - for (int k = 0; k < 3; ++k)
886 - {
887 - const unsigned short* v = &mesh.verts[vi[k]*3];
888 - const float x = orig[0] + v[0]*cs;
889 - const float y = orig[1] + (v[1]+1)*ch;
890 - const float z = orig[2] + v[2]*cs;
891 - dd->vertex(x,y,z, color);
892 - }
893 - }
894 - }
895 - dd->end();
896 -
897 - // Draw neighbours edges
898 - const unsigned int coln = duRGBA(0,48,64,32);
899 - dd->begin(DU_DRAW_LINES, 1.5f);
900 - for (int i = 0; i < mesh.npolys; ++i)
901 - {
902 - const unsigned short* p = &mesh.polys[i*nvp*2];
903 - for (int j = 0; j < nvp; ++j)
904 - {
905 - if (p[j] == RC_MESH_NULL_IDX) break;
906 - if (p[nvp+j] & 0x8000) continue;
907 - const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
908 - const int vi[2] = {p[j], p[nj]};
909 -
910 - for (int k = 0; k < 2; ++k)
911 - {
912 - const unsigned short* v = &mesh.verts[vi[k]*3];
913 - const float x = orig[0] + v[0]*cs;
914 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
915 - const float z = orig[2] + v[2]*cs;
916 - dd->vertex(x, y, z, coln);
917 - }
918 - }
919 - }
920 - dd->end();
921 -
922 - // Draw boundary edges
923 - const unsigned int colb = duRGBA(0,48,64,220);
924 - dd->begin(DU_DRAW_LINES, 2.5f);
925 - for (int i = 0; i < mesh.npolys; ++i)
926 - {
927 - const unsigned short* p = &mesh.polys[i*nvp*2];
928 - for (int j = 0; j < nvp; ++j)
929 - {
930 - if (p[j] == RC_MESH_NULL_IDX) break;
931 - if ((p[nvp+j] & 0x8000) == 0) continue;
932 - const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
933 - const int vi[2] = {p[j], p[nj]};
934 -
935 - unsigned int col = colb;
936 - if ((p[nvp+j] & 0xf) != 0xf)
937 - col = duRGBA(255,255,255,128);
938 - for (int k = 0; k < 2; ++k)
939 - {
940 - const unsigned short* v = &mesh.verts[vi[k]*3];
941 - const float x = orig[0] + v[0]*cs;
942 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
943 - const float z = orig[2] + v[2]*cs;
944 - dd->vertex(x, y, z, col);
945 - }
946 - }
947 - }
948 - dd->end();
949 -
950 - dd->begin(DU_DRAW_POINTS, 3.0f);
951 - const unsigned int colv = duRGBA(0,0,0,220);
952 - for (int i = 0; i < mesh.nverts; ++i)
953 - {
954 - const unsigned short* v = &mesh.verts[i*3];
955 - const float x = orig[0] + v[0]*cs;
956 - const float y = orig[1] + (v[1]+1)*ch + 0.1f;
957 - const float z = orig[2] + v[2]*cs;
958 - dd->vertex(x,y,z, colv);
959 - }
960 - dd->end();
859 + const int nvp = mesh.nvp;
860 + const float cs = mesh.cs;
861 + const float ch = mesh.ch;
862 + const float* orig = mesh.bmin;
863 +
864 + dd->begin(DU_DRAW_TRIS);
865 +
866 + for (int i = 0; i < mesh.npolys; ++i)
867 + {
868 + const unsigned short* p = &mesh.polys[i*nvp*2];
869 +
870 + unsigned int color;
871 + if (mesh.areas[i] == RC_WALKABLE_AREA)
872 + color = duRGBA(0,192,255,64);
873 + else if (mesh.areas[i] == RC_NULL_AREA)
874 + color = duRGBA(0,0,0,64);
875 + else
876 + color = duIntToCol(mesh.areas[i], 255);
877 +
878 + unsigned short vi[3];
879 + for (int j = 2; j < nvp; ++j)
880 + {
881 + if (p[j] == RC_MESH_NULL_IDX) break;
882 + vi[0] = p[0];
883 + vi[1] = p[j-1];
884 + vi[2] = p[j];
885 + for (int k = 0; k < 3; ++k)
886 + {
887 + const unsigned short* v = &mesh.verts[vi[k]*3];
888 + const float x = orig[0] + v[0]*cs;
889 + const float y = orig[1] + (v[1]+1)*ch;
890 + const float z = orig[2] + v[2]*cs;
891 + dd->vertex(x,y,z, color);
892 + }
893 + }
894 + }
895 + dd->end();
896 +
897 + // Draw neighbours edges
898 + const unsigned int coln = duRGBA(0,48,64,32);
899 + dd->begin(DU_DRAW_LINES, 1.5f);
900 + for (int i = 0; i < mesh.npolys; ++i)
901 + {
902 + const unsigned short* p = &mesh.polys[i*nvp*2];
903 + for (int j = 0; j < nvp; ++j)
904 + {
905 + if (p[j] == RC_MESH_NULL_IDX) break;
906 + if (p[nvp+j] & 0x8000) continue;
907 + const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
908 + const int vi[2] = {p[j], p[nj]};
909 +
910 + for (int k = 0; k < 2; ++k)
911 + {
912 + const unsigned short* v = &mesh.verts[vi[k]*3];
913 + const float x = orig[0] + v[0]*cs;
914 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
915 + const float z = orig[2] + v[2]*cs;
916 + dd->vertex(x, y, z, coln);
917 + }
918 + }
919 + }
920 + dd->end();
921 +
922 + // Draw boundary edges
923 + const unsigned int colb = duRGBA(0,48,64,220);
924 + dd->begin(DU_DRAW_LINES, 2.5f);
925 + for (int i = 0; i < mesh.npolys; ++i)
926 + {
927 + const unsigned short* p = &mesh.polys[i*nvp*2];
928 + for (int j = 0; j < nvp; ++j)
929 + {
930 + if (p[j] == RC_MESH_NULL_IDX) break;
931 + if ((p[nvp+j] & 0x8000) == 0) continue;
932 + const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
933 + const int vi[2] = {p[j], p[nj]};
934 +
935 + unsigned int col = colb;
936 + if ((p[nvp+j] & 0xf) != 0xf)
937 + col = duRGBA(255,255,255,128);
938 + for (int k = 0; k < 2; ++k)
939 + {
940 + const unsigned short* v = &mesh.verts[vi[k]*3];
941 + const float x = orig[0] + v[0]*cs;
942 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
943 + const float z = orig[2] + v[2]*cs;
944 + dd->vertex(x, y, z, col);
945 + }
946 + }
947 + }
948 + dd->end();
949 +
950 + dd->begin(DU_DRAW_POINTS, 3.0f);
951 + const unsigned int colv = duRGBA(0,0,0,220);
952 + for (int i = 0; i < mesh.nverts; ++i)
953 + {
954 + const unsigned short* v = &mesh.verts[i*3];
955 + const float x = orig[0] + v[0]*cs;
956 + const float y = orig[1] + (v[1]+1)*ch + 0.1f;
957 + const float z = orig[2] + v[2]*cs;
958 + dd->vertex(x,y,z, colv);
959 + }
960 + dd->end();
961 961 }
962 962
963 963 void duDebugDrawPolyMeshDetail(duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh)
964 964 {
965 - if (!dd) return;
965 + if (!dd) return;
966 966
967 - dd->begin(DU_DRAW_TRIS);
968 -
969 - for (int i = 0; i < dmesh.nmeshes; ++i)
970 - {
971 - const unsigned int* m = &dmesh.meshes[i*4];
972 - const unsigned int bverts = m[0];
973 - const unsigned int btris = m[2];
974 - const int ntris = (int)m[3];
975 - const float* verts = &dmesh.verts[bverts*3];
976 - const unsigned char* tris = &dmesh.tris[btris*4];
977 -
978 - unsigned int color = duIntToCol(i, 192);
979 -
980 - for (int j = 0; j < ntris; ++j)
981 - {
982 - dd->vertex(&verts[tris[j*4+0]*3], color);
983 - dd->vertex(&verts[tris[j*4+1]*3], color);
984 - dd->vertex(&verts[tris[j*4+2]*3], color);
985 - }
986 - }
987 - dd->end();
988 -
989 - // Internal edges.
990 - dd->begin(DU_DRAW_LINES, 1.0f);
991 - const unsigned int coli = duRGBA(0,0,0,64);
992 - for (int i = 0; i < dmesh.nmeshes; ++i)
993 - {
994 - const unsigned int* m = &dmesh.meshes[i*4];
995 - const unsigned int bverts = m[0];
996 - const unsigned int btris = m[2];
997 - const int ntris = (int)m[3];
998 - const float* verts = &dmesh.verts[bverts*3];
999 - const unsigned char* tris = &dmesh.tris[btris*4];
1000 -
1001 - for (int j = 0; j < ntris; ++j)
1002 - {
1003 - const unsigned char* t = &tris[j*4];
1004 - for (int k = 0, kp = 2; k < 3; kp=k++)
1005 - {
1006 - unsigned char ef = (t[3] >> (kp*2)) & 0x3;
1007 - if (ef == 0)
1008 - {
1009 - // Internal edge
1010 - if (t[kp] < t[k])
1011 - {
1012 - dd->vertex(&verts[t[kp]*3], coli);
1013 - dd->vertex(&verts[t[k]*3], coli);
1014 - }
1015 - }
1016 - }
1017 - }
1018 - }
1019 - dd->end();
1020 -
1021 - // External edges.
1022 - dd->begin(DU_DRAW_LINES, 2.0f);
1023 - const unsigned int cole = duRGBA(0,0,0,64);
1024 - for (int i = 0; i < dmesh.nmeshes; ++i)
1025 - {
1026 - const unsigned int* m = &dmesh.meshes[i*4];
1027 - const unsigned int bverts = m[0];
1028 - const unsigned int btris = m[2];
1029 - const int ntris = (int)m[3];
1030 - const float* verts = &dmesh.verts[bverts*3];
1031 - const unsigned char* tris = &dmesh.tris[btris*4];
1032 -
1033 - for (int j = 0; j < ntris; ++j)
1034 - {
1035 - const unsigned char* t = &tris[j*4];
1036 - for (int k = 0, kp = 2; k < 3; kp=k++)
1037 - {
1038 - unsigned char ef = (t[3] >> (kp*2)) & 0x3;
1039 - if (ef != 0)
1040 - {
1041 - // Ext edge
1042 - dd->vertex(&verts[t[kp]*3], cole);
1043 - dd->vertex(&verts[t[k]*3], cole);
1044 - }
1045 - }
1046 - }
1047 - }
1048 - dd->end();
1049 -
1050 - dd->begin(DU_DRAW_POINTS, 3.0f);
1051 - const unsigned int colv = duRGBA(0,0,0,64);
1052 - for (int i = 0; i < dmesh.nmeshes; ++i)
1053 - {
1054 - const unsigned int* m = &dmesh.meshes[i*4];
1055 - const unsigned int bverts = m[0];
1056 - const int nverts = (int)m[1];
1057 - const float* verts = &dmesh.verts[bverts*3];
1058 - for (int j = 0; j < nverts; ++j)
1059 - dd->vertex(&verts[j*3], colv);
1060 - }
1061 - dd->end();
967 + dd->begin(DU_DRAW_TRIS);
968 +
969 + for (int i = 0; i < dmesh.nmeshes; ++i)
970 + {
971 + const unsigned int* m = &dmesh.meshes[i*4];
972 + const unsigned int bverts = m[0];
973 + const unsigned int btris = m[2];
974 + const int ntris = (int)m[3];
975 + const float* verts = &dmesh.verts[bverts*3];
976 + const unsigned char* tris = &dmesh.tris[btris*4];
977 +
978 + unsigned int color = duIntToCol(i, 192);
979 +
980 + for (int j = 0; j < ntris; ++j)
981 + {
982 + dd->vertex(&verts[tris[j*4+0]*3], color);
983 + dd->vertex(&verts[tris[j*4+1]*3], color);
984 + dd->vertex(&verts[tris[j*4+2]*3], color);
985 + }
986 + }
987 + dd->end();
988 +
989 + // Internal edges.
990 + dd->begin(DU_DRAW_LINES, 1.0f);
991 + const unsigned int coli = duRGBA(0,0,0,64);
992 + for (int i = 0; i < dmesh.nmeshes; ++i)
993 + {
994 + const unsigned int* m = &dmesh.meshes[i*4];
995 + const unsigned int bverts = m[0];
996 + const unsigned int btris = m[2];
997 + const int ntris = (int)m[3];
998 + const float* verts = &dmesh.verts[bverts*3];
999 + const unsigned char* tris = &dmesh.tris[btris*4];
1000 +
1001 + for (int j = 0; j < ntris; ++j)
1002 + {
1003 + const unsigned char* t = &tris[j*4];
1004 + for (int k = 0, kp = 2; k < 3; kp=k++)
1005 + {
1006 + unsigned char ef = (t[3] >> (kp*2)) & 0x3;
1007 + if (ef == 0)
1008 + {
1009 + // Internal edge
1010 + if (t[kp] < t[k])
1011 + {
1012 + dd->vertex(&verts[t[kp]*3], coli);
1013 + dd->vertex(&verts[t[k]*3], coli);
1014 + }
1015 + }
1016 + }
1017 + }
1018 + }
1019 + dd->end();
1020 +
1021 + // External edges.
1022 + dd->begin(DU_DRAW_LINES, 2.0f);
1023 + const unsigned int cole = duRGBA(0,0,0,64);
1024 + for (int i = 0; i < dmesh.nmeshes; ++i)
1025 + {
1026 + const unsigned int* m = &dmesh.meshes[i*4];
1027 + const unsigned int bverts = m[0];
1028 + const unsigned int btris = m[2];
1029 + const int ntris = (int)m[3];
1030 + const float* verts = &dmesh.verts[bverts*3];
1031 + const unsigned char* tris = &dmesh.tris[btris*4];
1032 +
1033 + for (int j = 0; j < ntris; ++j)
1034 + {
1035 + const unsigned char* t = &tris[j*4];
1036 + for (int k = 0, kp = 2; k < 3; kp=k++)
1037 + {
1038 + unsigned char ef = (t[3] >> (kp*2)) & 0x3;
1039 + if (ef != 0)
1040 + {
1041 + // Ext edge
1042 + dd->vertex(&verts[t[kp]*3], cole);
1043 + dd->vertex(&verts[t[k]*3], cole);
1044 + }
1045 + }
1046 + }
1047 + }
1048 + dd->end();
1049 +
1050 + dd->begin(DU_DRAW_POINTS, 3.0f);
1051 + const unsigned int colv = duRGBA(0,0,0,64);
1052 + for (int i = 0; i < dmesh.nmeshes; ++i)
1053 + {
1054 + const unsigned int* m = &dmesh.meshes[i*4];
1055 + const unsigned int bverts = m[0];
1056 + const int nverts = (int)m[1];
1057 + const float* verts = &dmesh.verts[bverts*3];
1058 + for (int j = 0; j < nverts; ++j)
1059 + dd->vertex(&verts[j*3], colv);
1060 + }
1061 + dd->end();
1062 1062 }