Ôðàêòàëüíûå ðåëüåôû
Ñîäåðæàíèå
Ââåäåíèå
1.Ôðàêòàëû
è èõ
ïðèìåíåíèå
2.Ïîñòàíîâêà
çàäà÷è
3.Âõîäíûå
è âûõîäíûå
äàííûå
4.Ìåòîä
ðåøåíèÿ
5.Òðåáîâàíèÿ
ê
àïïàðàòíûì
è
ïðîãðàììíûì
ñðåäñòâàì
6.Îïèñàíèå
è
âçàèìîäåéñòâèå
ïðîöåäóð è ôóíêöèé
Çàêëþ÷åíèå
Ñïèñîê
èñïîëüçîâàííîé
ëèòåðàòóðû
Ïðèëîæåíèå
1. Ëèñòèíã
ïðîãðàììû VOXEL
Ïðèëîæåíèå
2. Ëèñòèíã
ïðîãðàììû LANDSCAPE
Ïðèëîæåíèå
3. Òåõíè÷åêîå
çàäàíèå
Ïðèëîæåíèå
4. Ýêðàííûå
ôîðìû
Ïðèëîæåíèå
5.
Ðóêîâîäñòâî
ïîëüçîâàòåëÿ
Çàêëþ÷åíèå
Äàííûé
ïðîãðàììíûé
ïðîäóêò
ñîçäàâàëñÿ
êàê ñðåäñòâî
äëÿ ñîçäàíèÿ
ðåàëèñòè÷íûõ
ôðàêòàëüíûõ
ðåëüåôîâ.
Îáëàñòü
ïðèìåíåíèÿ
ðàññìîòðåííûõ
àëãîðèòìîâ
î÷åíü âåëèêà
- îò
êîìïüþòåðíûõ
èãð äî
èñïîëüçîâàíèÿ
äëÿ
âèçóàëèçàöèè
íåêîòîðûõ
ìàòåìàòè÷åñêèõ
è ôèçè÷åñêèõ
çàäà÷.
Áûë
ðàññìîòðåí
VOXEL-ìåòîä,
ïîçâîëÿþùèé
ñîçäàâàòü
íà îñíîâå
ôðàêòàëîâ
ðåàëèñòè÷íîå
èçîáðàæåíèå
ãîð, äîëèí,
âîäîåìîâ. Ïðîãðàììà
áûëà
ðåàëèçîâàíà
íà ÿçûêå Pascal ñ
èñïîëüçîâàíèåì
àññåìáëåðíûõ
âñòàâîê â ñðåäå
Borland Pascal 7.0. Íàèáîëåå
êðèòè÷íàÿ
êî âðåìåíè
âûïîëíåíèÿ
÷àñòü êîäà -
÷àñòü,
îòâå÷àþùàÿ
çà âûâîä íà
ýêðàí áûëà
ðåàëèçîâàíà
ïîëíîñòüþ
íà ÿçûêå
àññåìáëåðà,
÷òî
ïîçâîëèëî
"îæèâèòü"
ïîëó÷åííûé
ðåëüåô. Ó
ïðîãðàììû
èìååòñÿ ðÿä
íåçíà÷èòåëüíûõ
íåäîñòàòêîâ
è íåäîðàáîòîê,
ê ÷èñëó
êîòîðûõ
îòíîñèòñÿ
ïðîðèñîâêà
îáúåêòîâ íà
çàäíåì ïëàíå(ýòè
îáúåêòû
ñêðûòû îò
ãëàçà
íàáëþäàòåëÿ).
Ìåòîä
ðåøåíèÿ
Ðàññìîòðèì
ìåòîä
ðåøåíèÿ ïðè
èñïîëüçîâàíèè
ïåðâîãî
àëãîðèòìà (VOXELS)
Èçîáðàæåíèå
ìîæíî
óñëîâíî
ïðåäñòàâèòü
â âèäå
ìàññèâà
òî÷åê 256õ256, ó
êàæäîé èõ
êîòîðûõ åñòü
ñâîÿ öåëàÿ
8-áèòîâàÿ
âûñîòà è öâåò.
Èçîáðàæåíèå
çàìûêàåòñÿ
òàêèì îáðàçîì,
÷òî ôóíêöèÿ
âûñîòû
òî÷êè ñ
êîîðäèíàòàìè
(u,v) âîçâðàùàåò
îäèíàêîâûå
çíà÷åíèÿ â
óãëàõ
óñëîâíîé
ñåòêè òî÷åê.
Ò.å. w(0,0)=w(256,0)=w(0,256)=w(256,256). w(1,1)=w(257,257)
è ò.ä.
Êîîðäèíàòû
òî÷åê íà
ïîâåðõíîñòè:
(u,v) -
êîîðäèíàòû,
îïèñûâàþùèå
ïîëîæåíèå
íà
ïîâåðõíîñòè.
Ò.î.
ïîâåðõíîñòü
ìîæåò áûòü
çàäàíà êàê
ôóíêöèÿ
âûñîòû h=w(u,v).
Ýêðàííûå
êîîðäèíàòû: (x,y)
- êîîðäèíàòû
òî÷êè íà
ýêðàíå.
Ãåíåðàöèÿ
ïîâåðõíîñòè
Ïîâåðõíîñòü
ãåíåðèðóåòñÿ
ðåêóðñèâíûì
ôðàêòàëüíûì
àëãîðèòìîì.
 äàííîì
ñëó÷àå
öåëåñîîáðàçíî
âîñïîëüçîâàòüñÿ
ðàçíîâèäíîñòüþ
ôðàêòàëîâ,
èìåþùåé
îáùåå
íàçâàíèå
"ïëàçìà". Àëãîðèòì
íà÷èíàåò
ñâîþ ðàáîòó
â òî÷êå (0,0) (ýêâèâàëåíòíî
(256,0), (0,256), (256,256)).
Àëãîðèòì
îñíîâàí íà
ðåêóðñèâíîì
âûçîâå
ïðîöåäóðû,
êîòîðàÿ â
êà÷åñòâå
ïàðàìåòðîâ
ïîëó÷àåò
ðàçìåð è
êîîðäèíàòû
ïðÿìîóãîëüíîãî
ó÷àñòêà
ïîâåðõíîñòè.
Âî âðåìÿ
ïåðâîãî
ñâîåãî
âûçîâà îíà
ïîëó÷àåò
êîîðäèíàòû
è ðàçìåð
âñåé
ïîâåðõíîñòè.
Ýòà
ïðîöåäóðà ïîëó÷àåò
âûñîòû
òî÷åê èç
óãëîâ
ïðÿìîóãîëüíèêà,
ïîëó÷åííîãî
â êà÷åñòâå
ïàðàìåòðà. Çàòåì
ïîäñ÷èòûâàåòñÿ
ñðåäíÿÿ
âûñîòà
òî÷åê,
ëåæàùèõ íà
îäíîì ðåáðå.
Ðåçóëüòàò ñ
ó÷åòîì
äëèíû ðåáðà
"çàïèñûâàåòñÿ"
íà
ïîâåðõíîñòü.
Âûñîòà
òî÷êè â öåíòðå
ïðÿìîóãîëüíèêà
ïîäñ÷èòûâàåòñÿ
êàê ñðåäíåå
ìåæäó
âûñîòàìè
÷åòûðåõ
âåðøèí è
òàêæå ñ
ó÷åòîì äëèí
ðåáåð
"çàïèñûâàåòñÿ"
íà
ïîâåðõíîñòü.
Çàòåì
ïðîöåäóðà
âûçûâàåò
ñåáÿ æå,
ðàçáèâàÿ
ïðÿìîóãîëüíèê
íà ÷åòûðå
÷àñòè.
Ïðîöåññ
ïðîäîëæàåòñÿ
äî òåõ ïîð, ïîêà
äëèíà ðåáðà
íå ñòàíåò
ðàâíà äâóì
ïèêñåëÿì.
Ïîâåðõíîñòü
ïîëó÷àåòñÿ
áîëåå ðåàëèñòè÷íîé,
åñëè
èñïîëüçîâàòü
blur-ýôôåêò ïî ñëåäóþùåé
ôîðìóëå:
w(u,v)=k1*w(u,v)+k2*w(u+3,v-2)+k3*w(u-2,v+4)
Êîýôôèöèåíòû
k1, k2, k3
ïîäáèðàþòñÿ
òàêèì
îáðàçîì,
÷òîáû èõ
ñóììà
ðàâíÿëàñü 1.
Öâåò
òî÷êè
âûáèðàåòñÿ
ïî ñëåäóþùåé
ôîðìóëå:
Color
= A*[ w(u+1,v)-w(u,v) ] + B
Êîýôôèöèåíòû
À è Â
ïîäáèðàþòñÿ
òàêèì îáðàçîì,
÷òîáû áûëà
èñïîëüçîâàíà
âñÿ ïàëèòðà
öâåòîâ.
Óñëîâíî
òî, ÷òî áóäåò
íà äèñïëåå
ìîæíî ïðåäñòàâèòü
òàê:
íåáî
ëèíèÿ
ãîðèçîíòà
à
çåìëÿ êîîðäèíàòû
òî÷êè à (0,0)
îñü õ
íàïðàâëåíà
âïðàâî, îñü ó -
âíèç
Ïðåäïîëîæèì,
íàáëþäàòåëü
íàõîäèòñÿ â
òî÷êå ñ
êîîðäèíàòàìè
(p,q,r), ãäå (p,q) - ýòî
êîîðäèíàòû (u,v)
ïîâåðõíîñòè,
à r - ýòî
âûñîòà.
Òåïåðü
äëÿ êàæäîé
ãîðèçîíòàëüíîé
ëèíèè (v=const)
áóäåì
ìåíÿòü v â ïðåäåëàõ
îò v=q+100 äî v=q è
âûïîëíÿòü
ñëåäóþùèå
øàãè:
1.
Ïîëó÷èòü
ó-êîîðäèíàòó
èç
êîîðäèíàò
íà ïîâåðõíîñòè
(p,q,0), ò.å. ñäåëàòü
ïåðñïåêòèâíîå
ïðåîáðàçîâàíèå
íàáëþäàòåëü
r
P Çåìëÿ
q v
Äàëåå
íóæíî íàéòè
òî÷êó
ïåðåñå÷åíèÿ
ëèíèè,
ñîåäèíÿþùåé
Ð è
íàáëþäàòåëÿ,
ñ ýêðàíîì.
Äàííîå
ïðåîáðàçîâàíèå
ïåðñïåêòèâû
äåëàåòñÿ ïî
ôîðìóëå:
y = r /
(q-v).
2.
Ïîäñ÷èòàòü
ìàñøòàáèðóþùèé
êîýôôèöèåíò
f, îò êîòîðîãî
çàâèñèò
êîë-âî
îòîáðàæàåìûõ
ïèêñåëåé ïî
âåðòèêàëè -
÷åì äàëüøå v
îò q, òåì îí
ìåíüøå è
íàîáîðîò. F
äîëæíî
ïîëó÷èòüñÿ
òàêèì, ÷òîáû
ïðè åãî
óìíîæåíèè
íà âûñîòó
òî÷êè
ïîëó÷àëîñü
êîëè÷åñòâî
ïèêñåëåé íà
ýêðàíå.
3.Âûïîëíèòü
âûøåîïèñàííûå
äåéñòâèÿ äëÿ
âñåõ u. (v=const)
4.Íà÷èíàÿ
ñ ïîñ÷èòàííîé
òî÷êè (u,v),
ïåðåñå÷ü
âåñü ýêðàí,
óâåëè÷èâàÿ
õ-êîîðäèíàòó
è äîáàâëÿÿ ê u
êîíñòàíòó
ñ. Ò.î.
êîîðäèíàòû (u+c,v)
ÿâëÿþòñÿ â
ýêðàííûõ
êîîðäèíàòàõ
(1,ó)
Ò.î., ÷åì
äàëüøå
íàõîäèòñÿ
ñêàíèðóåìàÿ
ëèíèÿ, òåì
"ëåâåå"
áóäåò
íà÷èíàòüñÿ
îòñ÷åò u è òåì
áîëüøå
áóäåò ñ
è íàîáîðîò.
Ïîñòàíîâêà
çàäà÷è
Çàäà÷à
ñîñòîèò â
ãåíåðàöèè
ôðàêòàëüíîãî
ðåëüåôà. Â
äàííîé
ïðîãðàììå
ðåàëèçîâàíî
äâà ïîäõîäà ê
ðåøåíèþ
ýòîé çàäà÷è.
Ïåðâûé
ïîäõîä
çàêëþ÷àåòñÿ
â ãåíåðàöèè
ðåëüåôà
ìåòîäîì
âîêñåëåé (voxel -
ìèíèìàëüíûé
ýëåìåíò
òðåõìåðíîãî
èçîáðàæåíèÿ,
ýëåìåíò
îáúåìà). Ïðè
òàêîì
ïîäõîäå
ìîæíî
äîáèòüñÿ
ìàêñèìàëüíîé
ðåàëèñòè÷íîñòè
ïîëó÷åííîãî
èçîáðàæåíèÿ.
Ãðóáî ãîâîðÿ,
ìåòîä
çàêëþ÷àåòñÿ
â òîì, ÷òî
ñíà÷àëà
ñòðîèòñÿ
ïëîñêèé ôðàêòàë,
à çàòåì,
öâåòó
êàæäîé åãî
òî÷êè ñòàâèòñÿ
â
ñîîòâåòñòâèå
åå âûñîòà.
Ïîäîáðàâ ïàëèòðó
öâåòîâ
ñîîòâåòñâóþùèì
îáðàçîì, ìîæíî
äîáèòüñÿ
ðåàëèñòè÷íîãî
èçîáðàæåíèÿ
ãîð, äîëèí,
âîäîåìîâ. Ïðîñòîòà
àëãîðèòìà
ïîñòðîåíèÿ
ïîçâîëÿåò
âûâîäèòü íà
ýêðàí
ïîëó÷åííûé
ïåéçàæ ñî
ñêîðîñòüþ,
äîñòàòî÷íîé
äëÿ ñîçäàíèÿ
èëëþçèè
ïåðåäâèæåíèÿ
ïî
ïîñòðîåííîé
ïîâåðõíîñòè.
Òàêæå, ñâîåé
ñêîðîñòüþ
àëãîðèòì
îáÿçàí òîìó,
÷òî ñàì
ôðàêòàë
ñòðîèòñÿ
âñåãî ëèøü
îäèí ðàç.
Âòîðîé
ïîäõîä
ÿâëÿåòñÿ
áîëåå
ïðîñòûì. Àëãîðèòì
ïðè òàêîì
ïîäõîäå
ÿâëÿåòñÿ
ñèëüíûì óïðîùåíèåì
âûøåîïèñàííîãî.
 äàííîì ñëó÷àå
òàêæå
âíà÷àëå
ñòðîèòñÿ
íåêîòîðûé ôðàêòàë,
à çàòåì íà
ýêðàí
âûâîäÿòñÿ
òîëüêî óçëîâûå
òî÷êè ñåòêè,
ïîëó÷åííîé
ïðè ðàçáèåíèè
ôðàêòàëà.
Îáà
îïèñàííûõ
ïîäõîäà
ìîãóò
íàéòè ñâîå ïðèìåíåíèå
â ðàçíûõ
îáëàñòÿõ
êîìïüþòåðíîé
ãðàôèêè à
òàêæå
èñïîëüçîâàíû
äëÿ âèçóàëèçàöèè
íåêîòîðûõ
çàäà÷.
Ïåðâûé ìåòîä
àêòèâíî
èñïîëüçóåòñÿ
ïðè ñîçäàíèè
êîìïüþòåðíûõ
èãð,
òðåáóþùèõ
áûñòðîé
ïðîðèñîâêè
ïåéçàæà.
Òåõíè÷åñêîå
çàäàíèå
Ââåäåíèå
Äàííàÿ
ðàáîòà
áóäåò
ïîñâÿùåíà îäíîìó
èç àñïåêòîâ
ïðèìåíåíèÿ
ôðàêòàëîâ - ñîçäàíèþ
ôðàêòàëüíûõ
ðåëüåôîâ.
Èçîáðàæåíèå
áóäåò
ñòðîèòüñÿ
ïðè ïîìîùè
VOXEL-ìåòîäà, êîòîðûé
ïîçâîëÿåò
ïîëó÷àòü
ðåàëèñòè÷íûå
ãîðû, äîëèíû
è âîäîåìû.
1.
Íàçíà÷åíèå
ðàçðàáîòêè
Ïîëó÷åííûå
ïðîãðàììû
áóäóò ïðåäíàçíà÷åíû
äëÿ
âèçóàëèçàöèè
íåêîòîðûõ ìàòåìàòè÷åñêèõ
çàäà÷. Òàêæå
VOXEL-òåõíîëîãèÿ
ìîæåò áûòü
èñïîëüçîâàíà
ïðè
ñîçäàíèè êîìïüþòåðíûõ
èãð,
òðåáóþùèõ
áûñòðîé
ïðîðèñîâêè
ïåéçàæà
âûñîêîé
äåòàëèçàöèè
2.Îñíîâàíèå
äëÿ
ðàçðàáîòêè
Êóðñîâîé
ïðîåêò âûäàí
êàôåäðîé ÏÈÈ
ïî
äèñöèïëèíå
"Ãðàôè÷åñêîå
è ãåîìåòðè÷åñêîå
ìîäåëèðîâàíèå"
íà 6-é ñåìåñòð
3-ãî êóðñà.
3.
Òðåáîâàíèÿ
ê
ïðîãðàììíîìó
ïðîäóêòó
3.1
Òðåáîâàíèÿ
ê àïïðàòíûì
ñðåäñòâàì
Äëÿ
íîðìàëüíîé
ðàáîòû
ïðîãðàììû
äîñòàòî÷íî IBM
ñîâìåñòèìîãî
êîìïüþòåðà êëàññà IBM PC/AT 286 c
2Ìá ÎÇÓ.
Òàêæå íåîáõîäèì
VGA äèñïëåé. Ó
ïðîãðàììû
èìååòñÿ
âîçìîæíîñòü
âûâîäà
ïîëó÷åííûõ
èçîáðàæåíèé
íà
ïðèíòåð(íàëè÷èå
íåîáÿçàòåëüíî).
Äëÿ ïîëó÷åíèÿ
êà÷åñòâåííîé
àíèìàöèè
(áåç ðûâêîâ)
ïðè
ïîñòðîåíèè
ðåëüåôîâ
VOXEL-ìåòîäîì
òðåáóåòñÿ
êîìïüþòåð
êëàññà IBM PC/AT 386.
3.2
Òðåáîâàíèÿ
ê
ïðîãðàììíûì
ñðåäñòâàì
Äëÿ
ðàáîòû
ïðîãðàììû
áóäåò
äîñòàòî÷íî MS
DOS 3.30. Îáå
ïðîãðàììû
áóäóò
ðåàëèçîâàíû
íà ÿçûêå Borland Pascal c
èñïîëüçîâàíèåì
àññåìáëåðíûõ
âñòàâîê äëÿ
óâåëè÷åíèÿ
ñêîðîñòè
âûâîäà.
3.3
Òðåáîâàíèÿ
ê ïðîãðàììå
Ïðîãðàììà
äîëæíà
îáðàáàòûâàòü
âõîäíûå äàííûå
è â
çàâèñèìîñòè
îò ïàëèòðû è
ïîëó÷åííîãî
ôðàêòàëà
ñòðîèòü
ôðàêòàëüíûé
ðåëüåô è
ïîçâîëÿòü
ïîëüçîâàòåëþ
äèíàìè÷åñêè
ïî íåìó
ïåðåìåùàòüñÿ(ïðîãðàììà
VOXEL) èëè ñòîðîèòü
ãðóïïó
óçëîâûõ
òî÷åê è
ïîçâîëÿòü ïåðåìåùàòüñÿ
ïî
ïîñòðîåííîé
ïîâðõíîñòè
â ïðåäåëàõ
îáëàñòè
çàäàíèÿ
ôðàêòàëà(ïðîãðàììà
LANDSCAPE).
3.4
Òðåáîâàíèÿ
ê
ïðîãðàììíîé
äîêóìåíòàöèè
Êóðñîâîé
ïðîåêò
ñîïðîâîæäàåòñÿ
Ïîÿñíèòåëüíîé
çàïèñêîé,
âêëþ÷àþùåé
â ñåáÿ Òåõíè÷åêîå
çàäàíèå,
îïèñàíèå
ìåòîäîâ
ðàáîòû
ïðîãðàììû à
òàêæå
îñíîâíûõ
ïðîöåäóð è
ôóíêöèé,
Ðóêîâîäñòâî
ïîëüçîâàòåëÿ
è âèäû
ýêðàíîâ.
4.
Ñòàäèè è
ýòàïû
ðàçðàáîòêè
Òåõíè÷åñêîå
çàäàíèå 8 íåäåëÿ
Íàïèñàíèå
àëãîðèòìîâ 10 íåäåëÿ
Îòëàäêà è
òåñòèðîâàíèå 14 íåäåëÿ
Ñäà÷à
ïðîåêòà 15 íåäåëÿ
Äîíåöêèé
Ãîñóäàðñòâåííûé
Èíñòèòóò
Èñêóññòâåííîãî
Èíòåëëåêòà
ÊÓÐÑÎÂÎÉ
ÏÐÎÅÊÒ
ïî êóðñó
"Ãðàôè÷åñêîå
è
ãåîìåòðè÷åñêîå
ìîäåëèðîâàíèå"
íà òåìó:
"Ãåíåðàöèÿ
ôðàêòàëüíûõ
ðåëüåôîâ"
Âûïîëíèë:
ñòóäåíò ãðóïïû
ÏÎ94á Áîòåâ Ì.Â.
Ïðîâåðèë:
Ãóáåíêî Í.Å.
Äîíåöê-1997
> Can someone explain the details of how to
make game graphics like
> in commanche over kill ?
It's called Voxel.
Don't ask me why. Below is a text that explains it.
---------------------------------------------------------------
From:
pleung@cs.buffalo.edu (Patrick Leung)
Newsgroups:
rec.games.programmer
Subject: How To: Mars
Landscape (Repost)
Well, since I posted
something about the: 'Voxel landscapes and
How I did it' post by
Tim Clarke, a coupla people have asked about it. So, here it is, Tim Clarke's :
Voxel landscapes and How I did it with some corrections and modifications he
added in later postings. Hope I dont infringe on any of his rights in doing
this...
The 'I' s in the following
represent Tim Clarke, not me :)
Voxel landscapes and How
I did it
This document
describes the method I used in my demo of a Martian terrain, which can be found
at garbo.uwasa.fi:/pc/demo/mars10.zip.
It's similar to a floating horizon hidden line removal algorithm, so
you'll find discussion of the salient points in many computer graphics books.
The difference is the vertical line interpolation.
First, some general
points:
The map is a 256x256 grid of points, each having an 8-bit integer
height and a colour. The map wraps round such that, calling w(u,v) the height
at (u,v), then w(0,0)=w(256,0)=w(0,256)=w(256,256). w(1,1)=w(257,257), etc.
Map
co-ords: (u,v) co-ordinates that describe a position on the map. The map can be
thought of as a height function h=w(u,v) sampled discretely.
Screen co-ords: (x,y)
co-ordinates for a pixel on the screen.
To generate the map:
This is a recursive
subdivision, or plasma, fractal. You start of with
a random height at (0,0)
and therefore also at (256,0), (0,256), (256,256).
Call a routine that takes
as input the size and position of a square, in the first case the entire map.
This routine get the
heights from the corners of the square it gets given. Across each edge (if the
map has not been written to at the point halfway along that edge), it takes the
average of the heights of the 2 corners on that edge, applies some noise
proportional to the length of the edge, and writes the result into the map at a
position halfway along the edge. The centre of the square is the average of the
four corners+noise.
The routine then calls itself recursively, splitting each square into
four quadrants, calling itself for each quadrant until the length of the side
is 2 pixels.
This is probably old-hat to many people, but the map is made more
realistic by blurring:
w(u,v)=k1*w(u,v)+k2*w(u+3,v-2)+k3*w(u-2,v+4)
or something.
Choose k1,k2,k3 such that k1+k2+k3=1. The points at which the map is
sampled for the blurring filter do not really matter - they give different
effects, and you don't need any theoretical reason to choose one lot as long as
it looks good. Of course do everything in fixed point integer arithmetic.
The colours are done so that the sun is on
the horizon to the East:
Colour=A*[ w(u+1,v)-w(u,v) ]+B
with A and B chosen so
that the full range of the palette is used.
The sky is a similar fractal but without
the colour transformation.
How to draw each frame
First, draw the sky, and blank off about 50 or so scan lines below the
horizon since the routine may not write to all of them (eg. if you are on top
of a high mountain looking onto a flat plane, the plane will not go to the
horizon).
Now, down to business. The screen is as
follows:
---------------------------
| |
| |
| Sky |
| |
| |
|a------------------------|
Horizon
| |
| | Point (a)=screen co-ords (0,0)
| Ground | x increases horizontally
| | y increases downwards
| |
Imagine the viewpoint
is at a position (p,q,r) where (p,q) are the (u,v)
map co-ordinates and r
is the altitude. Now, for each horizontal (constant v)
line of map from v=q+100 (say) down to
v=q, do this:
1. Calculate the y co-ordinate of map
co-ord (p,v,0) (perspective transform)
you:->------------------------
Horizontal view
:
r :
:
:
-----------------------------P
Ground
.........................
(q-v)
q v
You have to find where
the line between P and you intersects with the
screen (vertical, just in
front of 'you'). This is the perspective transform:
y=r/(q-v).
2. Calculate scale
factor f which is how many screen pixels high a mountain of constant height
would be if at distance v from q. Therefore, f is small for map co-ords far
away (v>>q) and gets bigger as v comes down towards q.
So, f is a number such that if you multiply a height from the map by f,
you get the number of pixels on the screen high that height would be. For
example, take a spot height of 250 on the map. If this was very close, it could
occupy 500 pixels on the screen (before clipping)->f=2.
3. Work out the map u co-ord corresponding to (0,y). v is constant
along each line.
4. Starting at the calculated (u,v), traverse the screen, incrementing
the x co-ordinate and adding on a constant, c, to u such that (u+c,v) are the
map co-ords corresponding to the screen co-ords (1,y). You then have 256 map
co-ords along a line of constant v. Get the height, w, at each map co-ord and
draw a spot at (x,y-w*f) for all x.
I.e. the further away
the scan line is, the more to the "left" u will start, and the larger
c will be (possibly skipping some u columns if c > 1); the closer the scan
line, the lesser u will start on the "left", and c will be smaller.
Sorry, but that
probably doesn't make much sense. Here's an example:
Imagine sometime in the middle of drawing
the frame, everything behind a point (say v=q+50) will have been drawn:
---------------------------
| |
| |
| |
| **** |
| ********* | <- A mountain
half-drawn.
|-----**************------|
|*************************|
|********* *********|
|****** ******|
|.........................|
<- The row of dots is at screen co-ord y
| | corresponding to an altitude of 0 for that
--------------------------- particular distance v.
Now the screen-scanning routine will get called for v=q+50. It draws in
a point for every x corresponding to heights at map positions (u,v) where u
goes from p-something to p+something, v constant. The routine would put points
at these positions: (ignoring what was there before) *** *** ******* ******* .........................
So,
you can see that the screen gets drawn from the back, one vertical section
after another. In fact, there's more to it than drawing one pixel at every x
during the scan - you need to draw a vertical line between (x,y old) to (x,y
new), so you have to have a buffer containing the y values for every x that
were calculated in the previous pass. You interpolate along this line (Gouraud
style) from the old colour to the new colour also, so you have to keep a buffer
of the colours done in the last pass.
Only draw the vertical
lines if they are visible (ie. going down,
y new>y old). The screen
is drawn from the back so that objects can be drawn
inbetween drawing each
vertical section at the appropriate time.
If you need further
information or details, mail me or post here... Posting will allow others to
benefit from your points and my replies, though.
_
Ôðàêòàëû
è îáëàñòü èõ
ïðèìåíåíèÿ
Òåðìèí
"ôðàêòàë" (îò
ëàòèíñêîãî
"fractus" - äðîáü) áûë
ââåäåí
áåëüãèéñêèì
ìàòåìàòèêîì
Áåíóà
Ìàíäåëüáðîòîì
è îáîçíà÷àåò
ìíîæåñòâî,
èìåþùåå
äðîáíóþ
ôðàêòàëüíóþ
ðàçìåðíîñòü.
Ðàññìîòðèì
êëàññè÷åñêèé
ïðèìåð
ôðàêòàëà -
òðèàäíóþ
êðèâóþ Êîõ à
òàêæå øàãè
åãî ïîñòðîåíèÿ.
1.
Ïîñòðîåíèå
êðèâîé
íà÷èíàåòñÿ
ñ åäèíè÷íîãî
îòðåçêà,
êîòîðûé
íàçûâàåòñÿ
èíèöèàòîðîì
è ÿâëÿåòñÿ
ïðåäôðàêòàëîì
0-ãî ïîðÿäêà
2.
Äàëåå
èíèöèàòîð
çàìåíÿåòñÿ
íà îáðàçóþùèé
ýëåìåíò -
êðèâóþ èõ
÷åòûðåõ
çâåíüåâ, êàæäîå
èõ êîòîðûõ
èìååò äëèíó
1/3, òàê îáðàçóåòñÿ
ïðåäôðàêòàë
1-ãî ïîðÿäêà
Äëèíà
ïîëó÷åííîãî
ôðàêòàëà
ðàâíà 4/3 îò èñõîäíîé
3.
Êàæäûé èç
îòðåçêîâ
îïÿòü
äåëèòñÿ íà
÷åòûðå
çâåíà
Î÷åâèäíî,
÷òî ïðè n,
ñòðåìÿùåìñÿ
ê áåñêîíå÷íîñòè
äëèíà
ôðàêòàëà
òàêæå
ñòðåìèòñÿ ê
áåñêîíå÷íîñòè.
Â
äàííîå âðåìÿ
ôðàêòàëû
èñïîëüçóþòñÿ
âî ìíîãèõ
îáëàñòÿõ
ïðîãðàììèðîâàíèÿ.
Íàèáîëåå
èçâåñòíûå
îáëàñòè
ïðèìåíåíèÿ -
ôðàêòàëüíîå
ñæàòèå
èçîáðàæåíèé
è ãåíåðàöèÿ
ôðàêòàëüíûõ
ðåëüåôîâ,
ðàññìîòðåííàÿ
â äàííîé
ðàáîòå
Òðåáîâàíèÿ
ê
àïïàðàòíûì
è ïðîãðàììíûì
ñðåäñòâàì
1.
Òðåáîâàíèÿ
ê
àïïàðàòíûì
ñðåäñòâàì
Äëÿ
íîðìàëüíîé
ðàáîòû
ïðîãðàììû
äîñòàòî÷íî IBM
ñîâìåñòèìîãî
êîìïüþòåðà
êëàññà IBM PC/AT 286 c 2Ìá
ÎÇÓ. Òàêæå
íåîáõîäèì VGA
äèñïëåé. Ó
ïðîãðàììû
èìååòñÿ
âîçìîæíîñòü
âûâîäà
ïîëó÷åííûõ
èçîáðàæåíèé
íà
ïðèíòåð(íàëè÷èå
íåîáÿçàòåëüíî).
Äëÿ
ïîëó÷åíèÿ
êà÷åñòâåííîé
àíèìàöèè (áåç
ðûâêîâ) ïðè
ïîñòðîåíèè
ðåëüåôîâ
VOXEL-ìåòîäîì
òðåáóåòñÿ
êîìïüþòåð
êëàññà IBM PC/AT 386.
2. Òðåáîâàíèÿ
ê
ïðîãðàììíûì
ñðåäñòâàì
Äëÿ
ðàáîòû
ïðîãðàììû
äîñòàòî÷íî MS
DOS 3.30. Òàêæå íå
áûëî
çàìå÷åíî
íèêàêèõ
îùèáîê è
ñáîåâ
ïðîãðàììû
ïðè ðàáîòå â
ñðåäå MS Windows è OS/2
3.
Òðåáîâàíèÿ
ê ïðîãðàììå
Ïðîãðàììà
äîëæíà
îáðàáàòûâàòü
âõîäíûå äàííûå
è â
çàâèñèìîñòè
îò ïàëèòðû è
ïîëó÷åííîãî
ôðàêòàëà
ñòðîèòü
ôðàêòàëüíûé
ðåëüåô è
ïîçâîëÿòü
ïîëüçîâàòåëþ
äèíàìè÷åñêè
ïî íåìó ïåðåìåùàòüñÿ(ïðîãðàììà
VOXEL) èëè
ñòîðîèòü
ãðóïïó
óçëîâûõ
òî÷åê è ïîçâîëÿòü
ïåðåìåùàòüñÿ
ïî
ïîñòðîåííîé
ïîâðõíîñòè â
ïðåäåëàõ
îáëàñòè
çàäàíèÿ
ôðàêòàëà(ïðîãðàììà
LANDSCAPE).
Âõîäíûå
è âûõîäíûå
äàííûå
1.
Ïðîãðàììà VOXEL
1.1
Âõîäíûå
äàííûå
Âõîäíûìè
äàííûìè äëÿ
äàííîé
ïðîãðàììû
ÿâëÿþòñÿ:
-
ïàëèòðà
öâåòîâ,
êîòîðàÿ
áóäåò
èñïîëüçîâàíà
ïðè
ïîñòðîåíèè
ðåëüåôà. Âàðüèðóÿ
çíà÷åíèÿ
ïàëèòðû(èñïîëüçóåòñÿ
256 öâåòîâ),
ìîæíî
äîáèâàòüñÿ ðàçëè÷íûõ
ýôôåêòîâ.
Ïàëèòðà ïî
óìîë÷àíèþ
ïîäîáðàíà
òàêèì
îáðàçîì, ÷òî
áîëåå
íèçêèå ÷àñòè
ðåëüåôà(âîäîåìû)
èìåþò
îòòåíêè
ãîëóáîãî öâåòà.
Áîëåå
âûñîêèå(äîëèíû
è ïðåäãîðüÿ)
èìåþò
îòòåíêè
çåëåíîãî è æåëòîãî
öâåòîâ. È,
íàêîíåö, ñàìûå
âûñîêèå(ãîðû
ñî ñíåæíûìè
øàïêàìè) èìåþò
îòòåíêè
ñåðîãî è
áåëîãî
öâåòîâ.
-
äàííûå,
ïîñòóïàþùèå
ñ
êëàâèàòóðû.
Íàæèìàÿ íà
êëàâèøè
óïðàâëåíèÿ êóðñîðîì,
ïîëüçîâàòåëü
ìîæåò
äèíàìè÷åñêè
ïåðåìåùàòüñÿ
ïî ñîçäàííîìó
ôðàêòàëüíîìó
ðåëüåôó.
-
äàííûå,
ïîñòóïàþùèå
èç
ãåíåðàòîðà
ñëó÷àéíûõ
÷èñåë,
êîòîðûå èñïîëüçóþòñÿ
ïðè
ïîñòðîåíèè
ôðàêòàëà.
1.2
Âûõîäíûå
äàííûå
Âûõîäíûìè
äàííûìè
ïðîãðàììû
ÿâëÿåòñÿ
ôðàêòàëüíûé
ðåëüåô, âûâîäèìûé
íà ýêðàí
êîìïüþòåðà
2.
Ïðîãðàììà LANDSCAPE
2.1
Âõîäíûå
äàííûå
-
äàííûå, ïîñòóïàþùèå
ñ
ìàíèïóëÿòîðà
"ìûøü", ïðè ïîìîùè
êîòîðîãî ìîæíî
ïåðåìåùàòüñÿ
ïî ïîñòðîåííîé
ïîâåðõíîñòè
-
äàííûå,
ïîñòóïàþùèå
èç
ãåíåðàòîðà
ñëó÷àéíûõ
÷èñåë, êîòîðûå
èñïîëüçóþòñÿ
ïðè
ïîñòðîåíèè
ôðàêòàëà.
2.2
Âûõîäíûå
äàííûå
Âûõîäíûìè
äàííûìè
ïðîãðàììû
ÿâëÿåòñÿ
ïîâåðõíîñòü,
ïðåäñòàâëåííàÿ
â âèäå
íàáîðà
óçëâûõ
òî÷åê
Ââåäåíèå
Ôðàêòàëû
âñòðå÷àþòñÿ
âåçäå, ãäå
çàêàí÷èâàþòñÿ
ïðàâèëüíûå
ôîðìû
åâêëèäîâîé
ãåîìåòðèè.
Âñå, ÷òî
ñîçäàíî
÷åëîâåêîì,
îãðàíè÷åíî
ïëîñêîñòÿìè.
Åñëè
âñòðå÷àåòñÿ
ïðèðîäíûé
îáúåêò, òî ñ
ïåðâîãî
âçãëÿäà
âèäíî, ÷òî
îñîçíàòü,
îïèñàòü åãî
ôîðìó ñî
âñåìè
øåðîõîâàòîñòÿìè
ìîæíî òîëüêî
ïðèáëèçèòåëüíî.
Çäåñü íà
ïîìîùü ïðèõîäÿò
ôðàêòàëû.
Òåðìèí
«ôðàêòàë» (îò
ëàòèíñêîãî
ñëîâà
«fractus»
äðîáü) ââåäåí áåëüãèéñêèì
ìàòåìàòèêîì
Áåíóà Ìàíäåëüáðîòîì
è
îáîçíà÷àåò
ìíîæåñòâî,
èìåþùåå
äðîáíóþ
ôðàêòàëüíóþ
ðàçìåðíîñòü.
Äëÿ
ïîÿñíåíèÿ ôðàêòàëüíîé
ðàçìåðíîñòè
íåîáõîäèìî
ââåñòè
ïîíÿòèå
òîïîëîãè÷åñêîé
ðàçìåðíîñòè.
Ïîä
òîïîëîãè÷åñêîé
ðàçìåðíîñòüþ Dt
ìíîæåñòâà â
ëèíåéíîì
ïðîñòðàíñòâå
ïîíèìàþò
÷èñëî ëèíåéíî
íåçàâèñèìûõ
êîîðäèíàò â
ïðîñòðàíñòâå.
Íàïðèìåð, îêðóæíîñòü
è ëèíèÿ
èìåþò
òîïîëîãè÷åñêóþ
ðàçìåðíîñòü
1; êðóã è
êâàäðàò
2; øàð è
êóá 3. Ôðàêòàëüíàÿ
ðàçìåðíîñòü
ìíîæåñòâà D ðàçìåðíîñòü
òîãî
ïðîñòðàíñòâà,
êîòîðîå
ïîëíîñòüþ
çàïîëíÿåòñÿ
ìíîæåñòâîì.
Äëÿ ñâÿçè
ôðàêòàëüíîé
è òîïîëîãè÷åñêîé
ðàçìåðíîñòåé
èñïîëüçóþò
ïîêàçàòåëü Õåðñòà Í,
âû÷èñëÿåìûé
ïî ôîðìóëå: Í
= DDt. Ôðàêòàëîì
íàçûâàþò
ìíîæåñòâî,
ôðàêòàëüíàÿ
ðàçìåðíîñòü
êîòîðîãî íå
ñîâïàäàåò
ñ
òîïîëîãè÷åñêîé.
Ðàññìîòðèì
êëàññè÷åñêèé
ïðèìåð
ôðàêòàëüíîãî
ìíîæåñòâà
òðèàäíóþ
êðèâóþ Êîõ.
Ïîñòðîåíèå
êðèâîé íà÷èíàåòñÿ
ñ
åäèíè÷íîãî
îòðåçêà,
êîòîðûé
íàçûâàåòñÿ
èíèöèàòîðîì
è ÿâëÿåòñÿ ïðåäôðàêòàëîì 0-ãî ïîðÿäêà.
Äàëåå
èíèöèàòîð
çàìåíÿåòñÿ
íà îáðàçóþùèé
ýëåìåíò
êðèâóþ èç
÷åòûðåõ
ïðÿìîëèíåéíûõ
çâåíüåâ,
êàæäîå èç
êîòîðûõ
èìååò äëèíó
1/3. Òàê
îáðàçóåòñÿ ïðåäôðàêòàë
1-ãî ïîðÿäêà.
Åãî äëèíà
ðàâíà 4/3. Äëÿ
ïîñòðîåíèÿ ïðåäôðàêòàëà
ñëåäóþùåãî
ïîðÿäêà
êàæäîå
çâåíî
çàìåíÿåòñÿ
íà
óìåíüøåííûé
îáðàçóþùèé
ýëåìåíò. Â
ðåçóëüòàòå
ïîëó÷àåì
êðèâóþ,
ñîñòîÿùóþ èç
4õ4=16 çâåíüåâ,
êàæäîå èç
êîòîðûõ
èìååò äëèíó
(1/3)/3= 1/9, îáùàÿ
äëèíà ðàâíà 16/9. Äëèíà
ïðåäôðàêòàëà
n-ãî
ïîðÿäêà
ðàâíà (4/3) â
ñòåïåíè n.
Î÷åâèäíî,
÷òî ïðåäåë
äëèíû êðèâîé
ïðè n, ñòðåìÿùåìñÿ
ê
áåñêîíå÷íîñòè,
ðàâåí
áåñêîíå÷íîñòè.
Åñëè
ïîñòðîåíèå
êðèâîé íà÷èíàòü
íå ñ
îòðåçêà, à ñ
òðåóãîëüíèêà,
è ïðèìåíèòü
âûøåïåðå÷èñëåííûå
ïîñòðîåíèÿ ê
êàæäîé åãî
ñòîðîíå, òî
ïîëó÷èì «ñíåæèíêó»
Êîõ. Ýòà
ôèãóðà
èíòåðåñíà
òåì, ÷òî åå
ïåðèìåòð
ëèíèÿ
áåñêîíå÷íîé
äëèíû
îãðàíè÷èâàåò
êîíå÷íóþ
ïëîùàäü.
Â
íàøå âðåìÿ
ôðàêòàëû
àêòèâíî
èñïîëüçóþòñÿ
âî ìíîãèõ
îáëàñòÿõ
ïðîãðàììèðîâàíèÿ.
Äàííàÿ
ðàáîòà
ïîñâÿùåíà
ëèøü îäíîìó
àñïåêòó èõ
ïðèìåíåíèÿ -
ãåíåðàöèè
ðåëüåôîâ ïðè
ïîìîùè
ôðàêòàëîâ.
Ðàññìîòðåí
àëãîðèòì
ïîñòîðåíèÿ
ðåëüåôà ïðè
ïîìîùè âîêñåëåé (voxel -
ìèíèìàëüíûé
ýëåìåíò
òðåõìåðíîãî
èçîáðàæåíèÿ,
ýëåìåíò
îáúåìà) . Ïîëó÷åííûé
ïåéçàæ
âåñüìà
ðåàëèñòè÷åí,
ïîýòîìó
ýòîò
àëãîðèòì
÷àñòî
èñïîëüçóåòñÿ
ïðè
ñîçäàíèè
êîìïüþòåðíûõ
èãð, òðåáóþùèõ
áûñòðîé
ïðîðèñîâêè
ïåéçàæà.
Èãðû, íàïèñàííûå
ñ ïðèìåíèåì
âîêñåëåé
ãîðàçäî äèíàìè÷íåå
èãð, â
êîòîðûõ
èñïîëüçóåòñÿ
"íàòÿãèâàíèå"
òåêñòóð íà
îáúåêòû.
Òàêæå â äàííîé
ðàáîòå ðàññìîòðåí
ñïîñîá
ïðåîáðàçîâàíèÿ
ôðàêòàëüíîãî
èçîáðàæåíèÿ
â îáúåìíîå.
Ñïèñîê
ëèòåðàòóðû
1.
Âèðò Í. Àëãîðèòìû
è ñòðóêòóðû
äàííûõ: Ïåð. ñ àíãë.: Ì.:
Ìèð, 1989. 360 ñ.
2.
Äæîíñ Æ., Õàððîó Ê.
Ðåøåíèå
çàäà÷ â ñèñòåìå
Òóðáî
Ïàñêàëü: Ïåð. ñ
àíãë.;
Ïðåäèñë. Þ.Ï.Øèðîêîãî.-
Ì.: Ôèíàíñû è
ñòàòèñòèêà,
1991.-720 ñ.: èë.
3.
Åïàíåøíèêîâ
À., Åïàíåøíèêîâ
Â. Ïðîãðàììèðîâàíèå
â
ñðåäå Turbo
Pascal
7.0. - Ì.:
"ÄÈÀËÎÃ_ÌÈÔÈ",
1993. - 288 ñ.
4.
Ïîëÿêîâ Ä.Á., Êðóãëîâ È.Þ.
Ïðîãðàììèðîâàíèå
â ñðåäå Òóðáî
Ïàñêàëü
(âåðñèÿ
5.5):
Ñïðàâ.-ìåòîä.ïîñîáèå.-Ì.:
Èçä-âî ÌÀÈ, 1992. - 576
ñ.
5.
Ïðàéñ Ä.
Ïðîãðàììèðîâàíèå
íà ÿçûêå
Ïàñêàëü:
Ïðàêòè÷åñêîå
ðóêîâîäñ-
òâî.
Ïåð. ñ
àíãë.-Ì.:Ìèð, 1987.- 232
ñ., èë.
Òàêæå
áûëè
èñïîëüçîâàíû
ìàòåðèàëû,
ïîëó÷åííûå
ïî ñåòè FIDONet.
Èçîáðàæåíèå
ìîæíî
óñëîâíî
ïðåäñòàâèòü
â âèäå
ìàññèâà
òî÷åê 256õ256, ó êàæäîé
èõ êîòîðûõ
åñòü ñâîÿ
öåëàÿ
8-áèòîâàÿ âûñîòà
è öâåò.
Èçîáðàæåíèå
çàìûêàåòñÿ
òàêèì
îáðàçîì, ÷òî
ôóíêöèÿ
âûñîòû
òî÷êè ñ êîîðäèíàòàìè
(u,v) âîçâðàùàåò
îäèíàêîâûå
çíà÷åíèÿ â
óãëàõ óñëîâíîé
ñåòêè òî÷åê.
Ò.å. w(0,0)=w(256,0)=w(0,256)=w(256,256). w(1,1)=w(257,257)
è ò.ä.
Êîîðäèíàòû
ïîâåðõíîñòè:
(u,v) - êîîðäèíàòû,
îïèñûâàþùèå
ïîëîæåíèå
íà ïîâåðõíîñòè.
Ò.î.
ïîâåðõíîñòü
ìîæåò áûòü
çàäàíà êàê
ôóíêöèÿ
âûñîòû h=w(u,v).
Ýêðàííûå
êîîðäèíàòû: (x,y)
- êîîðäèíàòû
òî÷êè íà
ýêðàíå.
Ãåíåðàöèÿ
ïîâåðõíîñòè
Ïîâåðõíîñòü
ãåíåðèðóåòñÿ
ðåêóðñèâíûì
ôðàêòàëüíûì
àëãîðèòìîì.
 äàííîì
ñëó÷àå
öåëåñîîáðàçíî
âîñïîëüçîâàòüñÿ
ðàçíîâèäíîñòüþ
ôðàêòàëîâ,
èìåþùåé îáùåå
íàçâàíèå
"ïëàçìà".
Àëãîðèòì
íà÷èíàåò
ñâîþ ðàáîòó
â òî÷êå (0,0)
(ýêâèâàëåíòíî
(256,0), (0,256), (256,256)). Àëãîðèòì
îñíîâàí íà
ðåêóðñèâíîì
âûçîâå ïðîöåäóðû,
êîòîðàÿ â
êà÷åñòâå
ïàðàìåòðîâ
ïîëó÷àåò
ðàçìåð è
êîîðäèíàòû
ïðÿìîóãîëüíîãî
ó÷àñòêà
ïîâåðõíîñòè.
Âî âðåìÿ
ïåðâîãî ñâîåãî
âûçîâà îíà
ïîëó÷àåò
êîîðäèíàòû
è ðàçìåð
âñåé
ïîâåðõíîñòè.
Ýòà
ïðîöåäóðà ïîëó÷àåò
âûñîòû
òî÷åê èç
óãëîâ
ïðÿìîóãîëüíèêà,
ïîëó÷åííîãî
â êà÷åñòâå
ïàðàìåòðà. Çàòåì
ïîäñ÷èòûâàåòñÿ
ñðåäíÿÿ
âûñîòà òî÷åê,
ëåæàùèõ íà
îäíîì ðåáðå.
Ðåçóëüòàò ñ
ó÷åòîì
äëèíû ðåáðà
"çàïèñûâàåòñÿ"
íà ïîâåðõíîñòü.
Âûñîòà
òî÷êè â
öåíòðå
ïðÿìîóãîëüíèêà
ïîäñ÷èòûâàåòñÿ
êàê ñðåäíåå
ìåæäó âûñîòàìè
÷åòûðåõ
âåðøèí è
òàêæå ñ
ó÷åòîì äëèí
ðåáåð
"çàïèñûâàåòñÿ"
íà
ïîâåðõíîñòü.
Çàòåì
ïðîöåäóðà
âûçûâàåò
ñåáÿ æå,
ðàçáèâàÿ
ïðÿìîóãîëüíèê
íà ÷åòûðå
÷àñòè.
Ïðîöåññ
ïðîäîëæàåòñÿ
äî òåõ ïîð,
ïîêà äëèíà
ðåáðà íå
ñòàíåò
ðàâíà äâóì
ïèêñåëÿì.
Ïîâåðõíîñòü
ïîëó÷àåòñÿ
áîëåå ðåàëèñòè÷íîé,
åñëè
èñïîëüçîâàòü
blur-ýôôåêò ïî ñëåäóþùåé
ôîðìóëå:
w(u,v)=k1*w(u,v)+k2*w(u+3,v-2)+k3*w(u-2,v+4)
Êîýôôèöèåíòû
k1, k2, k3
ïîäáèðàþòñÿ
òàêèì îáðàçîì,
÷òîáû èõ
ñóììà
ðàâíÿëàñü 1.
Öâåò
òî÷êè
âûáèðàåòñÿ
ïî ñëåäóþùåé
ôîðìóëå:
Color = A*[ w(u+1,v)-w(u,v) ] + B
Êîýôôèöèåíòû
À è Â
ïîäáèðàþòñÿ
òàêèì îáðàçîì,
÷òîáû áûëà
èñïîëüçîâàíà
âñÿ ïàëèòðà
öâåòîâ.
Óñëîâíî
òî, ÷òî áóäåò
íà äèñïëåå
ìîæíî ïðåäñòàâèòü
òàê:
íåáî
ëèíèÿ
ãîðèçîíòà
à
çåìëÿ êîîðäèíàòû
òî÷êè à (0,0)
îñü õ
íàïðàâëåíà
âïðàâî, îñü ó -
âíèç
Ïðåäïîëîæèì,
íàáëþäàòåëü
íàõîäèòñÿ â
òî÷êå ñ
êîîðäèíàòàìè
(p,q,r), ãäå (p,q) - ýòî
êîîðäèíàòû (u,v)
ïîâåðõíîñòè,
à r - ýòî
âûñîòà.
Òåïåðü
äëÿ êàæäîé
ãîðèçîíòàëüíîé
ëèíèè (v=const)
áóäåì
ìåíÿòü v â ïðåäåëàõ
îò v=q+100 äî v=q è
âûïîëíÿòü
ñëåäóþùèå
øàãè:
1. Ïîëó÷èòü
ó-êîîðäèíàòó
èç
êîîðäèíàò
íà ïîâåðõíîñòè
(p,q,0), ò.å. ñäåëàòü
ïåðñïåêòèâíîå
ïðåîáðàçîâàíèå
íàáëþäàòåëü
r
P Çåìëÿ
q v
Äàëåå
íóæíî íàéòè
òî÷êó
ïåðåñå÷åíèÿ
ëèíèè,
ñîåäèíÿþùåé
Ð è
íàáëþäàòåëÿ,
ñ ýêðàíîì.
Äàííîå
ïðåîáðàçîâàíèå
ïåðñïåêòèâû
äåëàåòñÿ ïî
ôîðìóëå:
y = r / (q-v).
2.
Íóæíî
ïîäñ÷èòàòü
ìàñøòàáèðóþùèé
êîýôôèöèåíò
f, îò êîòîðîãî
çàâèñèò
êîë-âî îòîáðàæàåìûõ
ïèêñåëåé ïî
âåðòèêàëè -
÷åì äàëüøå v
îò q, òåì îí
ìåíüøå è
íàîáîðîò. F
äîëæíî
ïîëó÷èòüñÿ
òàêèì, ÷òîáû
ïðè åãî
óìíîæåíèè
íà âûñîòó
òî÷êè
ïîëó÷àëîñü
êîëè÷åñòâî
ïèêñåëåé íà
ýêðàíå.
3.Âûïîëíèòü
âûøåîïèñàííûå
äåéñòâèÿ äëÿ
âñåõ u. (v=const)
4.Íà÷èíàÿ
ñ
ïîñ÷èòàííîé
òî÷êè (u,v),
ïåðåñå÷ü
âåñü ýêðàí,
óâåëè÷èâàÿ
õ-êîîðäèíàòó
è äîáàâëÿÿ ê u
êîíñòàíòó
ñ. Ò.î.
êîîðäèíàòû (u+c,v)
ÿâëÿþòñÿ â
ýêðàííûõ
êîîðäèíàòàõ
(1,ó)
Ò.î.,
÷åì äàëüøå
íàõîäèòñÿ
ñêàíèðóåìàÿ
ëèíèÿ, òåì "ëåâåå"
áóäåò
íà÷èíàòüñÿ
îòñ÷åò u è
òåì áîëüøå áóäåò
ñ è íàîáîðîò.
Ðóêîâîäñòâî
ïîëüçîâàòåëÿ
Ïðîãðàììû
ïîñòàâëÿþòñÿ
â âèäå äâóõ
íåçàâèñèìûõ
ìîäóëåé: VOXEL.EXE è LANDSCAP.EXE,
êîòîðûå íå òðåáóþò
äëÿ ñâîåé
ðàáîòû
íèêàêèõ
äîïîëíèòåëüíûõ
äðàéâåðîâ(çà
èñêëþ÷åíèåì
ñòàíäàðòíîãî
äðàéâåðà
"ìûøè")
1.
Ïðîãðàììà VOXEL.EXE
Ñðàçó
ïîñëå
çàïóñêà
ïðîãðàììû
áóäåò
ñãåíåðèðîâàí
ôðàêòàëüíûé
ðåëüåô.
Íàæèìàÿ
êëàâèøè óïðàâëåíèÿ
êóðñîðîì,
ìîæíî
ïåðåìåùàòüñÿ
ïî ýòîìó
ðåëüåôó.
Áëàãîäàðÿ
àññåìáëåðíûì
âñòàâêàì è
áûñòðîìó
âûâîäó
ãðàôèêè äîñòèíàåòñÿ
ïîëíûé
ýôôåêò
äâèæåíèÿ. Äëÿ
âûõîäà èç
ïðîãðàììû
ííóæíî
íàæàòü
êëàâèøó "Esc".
2.
Ïðîãðàììà LANDSCAP.EXE
Ñðàçó
æå ïîñëå
çàïóñêà
ïðîãðàììà
ãåíåðèðóåò
ôðàêòàë è
ñîõðàíÿò
åãî
èçîáðàæåíèå
â ôàéëå PLASMA.IMG.
Ýòà îïåðàöèÿ
ïðîèçâîäèòñÿ
òîëüêî îäèí
ðàç, ïðè
ïåðâîì
çàïóñêå
ïðîãðàììû. Äàëåå
ãåíåðèðóåòñÿ
ïîâåðõíîñòü,
ïðåäñòàâëåííàÿ
â âèäå
íàáîðà
óçëîâûõ òî÷åê
íåâèäèìîé
ñåòêè,
íàòÿíóòîé
íà ïîâåðõíîñòü.
Ïðè ïîìîùè
ìàíèïóëÿòîðà
"ìûøü" ìîæíî
ïåðåäâèãàòüñÿ
ïî
ïîñòðîåííîé
ïîâåðõíîñòè.
Âûõîä èç
ïðîãðàììû
îñóùåñòâëÿåòñÿ
íàæàåòèåì
ëþáîé
êëàâèøè
"ìûøè".
Îïèñàíèå
è
âçàèìîäåéñòâèå
ïðîöåäóð è ôóíêöèé
1.
Ïðîãðàììà VOXEL
procedure
draw(xp,yp,dir:integer);
ýòà
ïðîöåäóðà
ïåðåðèñîâûâàåò
ýêðàí.
Ïðè÷åì,
íàáëþäàòåëü
íàõîäèòñÿ â
òî÷êå (xp,yp) è
ñìîòðèò â
íàïðâàëåíèè
dir
procedure
plasma(x1,y1,x2,y2:word);
ýòî ðåêóðñèâíàÿ
ïðîöåäóðà,
êîòîðàÿ
ñòðîèò ôðàêòàë
ïëàçìà” â
ïðÿìîóãîëüíèêå
ñ êîîðäèíàòàìè
(x1,y1,x2,y2).
Ïðîöåäóðà plasma
âûçûâàåòñÿ
òîëüêî îäèí
ðàç - ïðè
ïåðâîì çàïóñêå
ïðîãðàììû. Â
äàëüíåéøåì
ïîñòðîåííûé
ôðàêòàë
ïðîñòî
õðàíèòñÿ íà
äèñêå(â ôàéë çàïèñûâàåòñÿ
îáðàç
ïàìÿòè
äëèíîé 64Êá, íà÷èíàÿ
ñ àäðåñà A000:0000) è
ïðè ñòàðòå
ïðîãðàììû ïðîñòî
ñ÷èòûâàåòñÿ
èç ôàéëà.
Ïîñëå
ïåðâîé
ïðîðèñîâêè
ðåëüåôà íà÷èíàåòñÿ
öèêë îïðîñà
êëàâèàòóðû,
â õîäå êîòîðîãî
ìîãóò
ïîìåíÿòüñÿ
êîîðäèíàòû
íàáëþäàòåëÿ
à òàêæå
íàïðàâëåíèå
åãî
äâèæåíèÿ.
Öèêë
îñòàíàâëèâàåòñÿ
ïîñëå íàæàòèÿ
êëàâèøè “Esc”.
2.
Ïðîãðàììà LANDSCAPE
function
mouseinstalled : boolean; assembler;
ýòà
ôóíêöèÿ
ïðîâåðÿåò
íàëè÷èå äðàéâåðà
ìûøè” â
ïàìÿòè
function getmousex :
word; assembler;
ýòà
ôóíêöèÿ
ïîëó÷àåò
õ-êîîðäèíàòó
ïîëîæåíèÿ
ìûøè”
function getmousey :
word; assembler;
ýòà
ôóíêöèÿ
ïîëó÷àåò
õ-êîîðäèíàòó
ïîëîæåíèÿ
ìûøè”
function leftpressed
: boolean; assembler;
ýòà
ôóíêöèÿ
ïðîâåðÿåò íà
íàæàòèå ëåâîé
êíîïêè “ìûøè”
procedure
mousesensetivity(x,y : word); assembler;
ýòà
ïðîöåäóðà
óñòàíàâëèâàåò
÷óâñòâèòåëüíîñòü
ìûøè”
procedure
mousewindow(l,t,r,b : word); assembler;
ýòà
ïðîöåäóðà
çàäàåò îêíî
äëÿ “ìûøè”
procedure setvideo(m
: word); assembler;
ýòû
ïðîöåäóðà
óñòàíàâëèâàåò
m-âèäåîðåæèì
procedure
putpixel(x,y : word; c : byte); assembler;
ýòà
ïðîöåäóðà
ðèñóåò
òî÷êó ñ
êîîðäèíàòàìè
(õ,ó) öâåòà ñ
function getpixel(x,y
: word) : byte; assembler;
ýòà
ïðîöåäóðà
âîçâðàùàåò
öâåò òî÷êè ñ
êîîðäèíàòàìè
(õ,ó)
procedure
setpal(c,r,g,b : byte); assembler;
ýòà
ïðîöåäóðà
óñòàíàâëèâàåò
çíà÷åíèÿ
êîìïîíåíò
öâåòà (r,g,b) äëÿ
öâåòà ñ
procedure retrace;
assembler;
ýòà
ïðîöåäóðà
æäåò
îáðàòíîãî
õîäà ëó÷à CRT
procedure initcolors;
ïîöåäóðà
èíèöèàëèçàöèè
ïàëèòðû
procedure
generatelandscape;
ýòà
ïðîöåäóðà
ãåíåðèðóåò
ïîâåðõíîñòü
procedure
displayscape;
ýòà
ïðîöåäóðà
âûâîäèò íà
ýêðàí ñãåíåðèðîâàííóþ
ïðîöåäóðîé generatelandscape
ïîâåðõíîñòü.
|