Issue 45:Input triangle based area creation

This commit is contained in:
Mikko Mononen 2010-07-13 07:02:03 +00:00
parent a87947cc3f
commit a48b50d89c
3 changed files with 25 additions and 26 deletions

View File

@ -74,6 +74,15 @@ inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
unsigned int duIntToCol(int i, int a);
void duIntToCol(int i, float* col);
inline unsigned int duMultCol(const unsigned int col, const unsigned int d)
{
const unsigned int r = col & 0xff;
const unsigned int g = (col >> 8) & 0xff;
const unsigned int b = (col >> 16) & 0xff;
const unsigned int a = (col >> 24) & 0xff;
return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
}
inline unsigned int duDarkenColor(unsigned int col)
{
return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);

View File

@ -51,25 +51,16 @@ void duIntToCol(int i, float* col)
col[2] = 1 - b*63.0f/255.0f;
}
inline unsigned int multCol(const unsigned int col, const unsigned int d)
{
const unsigned int r = col & 0xff;
const unsigned int g = (col >> 8) & 0xff;
const unsigned int b = (col >> 16) & 0xff;
const unsigned int a = (col >> 24) & 0xff;
return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
}
void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide)
{
if (!colors) return;
colors[0] = multCol(colTop, 250);
colors[1] = multCol(colSide, 140);
colors[2] = multCol(colSide, 165);
colors[3] = multCol(colSide, 217);
colors[4] = multCol(colSide, 165);
colors[5] = multCol(colSide, 217);
colors[0] = duMultCol(colTop, 250);
colors[1] = duMultCol(colSide, 140);
colors[2] = duMultCol(colSide, 165);
colors[3] = duMultCol(colSide, 217);
colors[4] = duMultCol(colSide, 165);
colors[5] = duMultCol(colSide, 217);
}
void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,

View File

@ -121,29 +121,28 @@ void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
const int w = hf.width;
const int h = hf.height;
unsigned int fcol0[6], fcol1[6], fcol2[6];
duCalcBoxColors(fcol0, duRGBA(64,48,32,255), duRGBA(217,217,217,255)); // Culled
duCalcBoxColors(fcol1, duRGBA(77,140,165,255), duRGBA(217,217,217,255)); // Walkable
duCalcBoxColors(fcol2, duRGBA(128,38,102,255), duRGBA(217,217,217,255)); // Ledge
unsigned int fcol[6];
duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(217,217,217,255));
dd->begin(DU_DRAW_QUADS);
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
float fx = orig[0] + x*cs;
float fz = orig[2] + y*cs;
const rcSpan* s = hf.spans[x + y*w];
while (s)
{
const unsigned int* c = fcol0;
if (s->flags & RC_LEDGE)
c = fcol2;
else if (s->flags & RC_WALKABLE)
c = fcol1;
duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, c);
if (s->area == RC_WALKABLE_AREA)
fcol[0] = duRGBA(0,130,200,255);
else if (s->area == RC_NULL_AREA)
fcol[0] = duRGBA(64,64,64,255);
else
fcol[0] = duMultCol(duIntToCol(s->area, 255), 200);
duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
s = s->next;
}
}