13. Элементы виртуальной реальности Если верхний конец отрезка стены top оказывается лежащим ниже соответст-юшей линии горизонта, то на этом месте должен находиться фрагмент потолка.

Аналогично если нижний конец отрезка стены bottom находится выше нижней нии горизонта, то между ними должен находиться фрагмент пола.

Ниже приведена процедура для построения простой (односторонней) стены.

void drawSimpleWall (int coll, int col2, int bottomHeight,
int topHeight, int v1, int v2 )
{
Fixed M = int2Fixed ( 1001 + ( bottomHeight * VSCALE ) / vl ); Fixed b2 = int2Fixed ( 1001 + ( bottomHeight * VSCALE ) / v2 ); Fixed t1 = int2Fixed ( 1001 - (topHeight * VSCALE ) / v1 ); Fixed t2 = int2Fixed ( 100I - (topHeight * VSCALE ) / v2 ); Fixed db = (b2-b1 )/(co!2-col1 ); Fixed dt = (t2-t1 )/(col2-col1 ); int top, bottom;
if ( coM < 0 ) // clip invisible part
{

Ы -= coM * db; t1 -= coh * dt; coh = 0;

}
if ( col2 > 320 ) col2 = 320;
for (int col = coM; col < col2; col++ ) {

top = fixed2lnt (t1 ); bottom = fixed2lnt ( Ы ); t1 += dt; Ы +=db;

if (topLine [col] >'bottomLine [col] ) // nothing to draw here continue;
if (top > bottomLine [col] ) top = bottomLine [col];
if ( bottom < topLine [col]) bottom = topLine [col];
if (top >= topLine [col]) // draw ceiling {
drawVertLine (col, topLine [col], top,
CEILING_COLOR); topLine [col] = ++top;
}
else // otherwise correct to
top = topLine [col]; // draw only visible part
if ( bottom <= bottomLine [col] ) // draw floor {
drawVertLine ( col, bottom, bottomLine [col], FLOOR_COLOR ); bottomLine [col] = -bottom;

Компьютерная графика. Полигональные модели

}
else
bottom = bottomLine [col];
topLine [col] = bottom + 1; bottomLine [col] = top -1;
// now draw visible part of wall drawVertLine ( col, top, bottom, WALL_COLOR );
}
}

Жирными линиями выделены (рис. 13.21) линии горизонта после вывода грани. Для написания простейшего рендерера, способного работать с WAD-файл потребуется класс для чтения данных из него, а также описание основных его ст тур.


⇐ Предыдущая| |Следующая ⇒