Вы находитесь на странице: 1из 36

Page 1/36

GLScene
beginner's guide
by
Jan Zizka
2005
GLScene beginner's guide, Jan Zizka, 2005
Page 2/36
Contents
1. Disclaimer
2. What is GLScene ?
3. Installing GLScene
4. How oes it wor! ?
". #Hello worl $% e&am'le
6. (asic things )o* sho*l !now a+o*t 3D gra'hics
6.1. ,oorinate s)stem
6.2. -loating 'oint n*m+ers
6.3. .ectors
6.4. /enering
6.". 0'enGL
1. ,om'onents
1.1. GLScene
1.2. GLScene P-2
1.3. GLScene 3tils
1.4. GLScene Shaers
4. 0+5ects
4.1. ,ommon o+5ect 'ro'erties
4.2. (asic geometr)
4.3. 67ance geometr)
4.4. 8esh o+5ects
4.". Gra'h9'lotting o+5ects
4.6. Particle s)stems
4.1. :n7ironment o+5ects
4.4. H3D o+5ects
4.;. G3I o+5ects
4.1<.S'ecial o+5ects
4.11.Dooa o+5ect
4.12.0ther o+5ects
;. /*ntime o+5ect creation
;.1. ,reating new class
1<. ,ase st*)= 3D >etris
1<.1.Design
1<.2.Str*ct*re
1<.3.>3D>(loc! class
1<.4.Homewor!
11. Lin!s
12. ,oncl*sion
GLScene beginner's guide, Jan Zizka, 2005
Page 3/36
Disclaimer
>his +oo! is intene ?or an)one who wants to @*ic!l) start to *se GLScene. >here is no
o??icial oc*mentation ?or GLScene e&ce't ?or the comments irectl) in so*rce coe. I also strongl)
recommen *sing so*rce coe as a 'rimar) so*rce o? in?ormation. :s'eciall) when the so*rce coe
is +eing e7elo'e constantl) an is changing all the time. 6nother great so*rce o? !nowlege are
GLScene emos. Howe7er GLScene is so com'le& that I ?in it rather i??ic*lt ?or an)one who
ne7er *se it +e?ore to start learning.
I consier m)sel? a GLScene *ser not GLScene e7elo'er. I o not ta!e 'art in e7elo'ing
GLScene so*rce coeA I onBt ha7e aministrators rights to access GLScene ,.S. I ha7e 5*st +een
*sing GLScene ?or m) 'ro5ects. >here are 'eo'le that !now a lot more a+o*t GLScene that I o. I
owe a lot to GLScene comm*nit) an I wante to gi7e something +ac! +) writing this oc*ment.
I? )o* are an e&'erience GLScene *ser )o* will 'ro+a+l) ?in this oc*ment 7er) sim'le
+*t I wo*l +e ha'') ?or an) ?ee+ac! ?rom )o*. I am s*re there are a lot o? s'elling an
grammatical errors as well as man) GLScene relate mista!es. >here are also sections that I onBt
!now an)thing a+o*t or IBm not ?amiliar eno*gh with. >hese 'arts are mar!e C>0D0D. I? )o* are
willing to contri+*te to this +oo! 'lease ?eel ?ree to sen me )o*r cha'ter. I will a it to the te&t
together with )o*r creit. 6n) corrections o? m) own te&t are also welcome. I? )o* are loo!ing ?or
answer )o* co*l not ?in in this +oo! 'lease on%t as! me. I? I !new it I wo*l ha7e written it in
the +oo!.
Ean FiG!aA Prag*eA 8a) 2<<"
GiGa5anHcentr*m.cG
GLScene beginner's guide, Jan Zizka, 2005
Page 4/36
What is GLScene ?
/eaing this oc*ment )o* ha7e 'ro+a+l) alrea) seen some GLScene a''lications or e7en
wor!e with GLScene itsel?. Sim'l) sai GLScene is Del'hi li+rar) ?or 0'enGL gra'hics. 0'enGL
is gra'hics 6PI originall) e7elo'e +) Silicone Gra'hics. 0'enGL is a stanar an it sho*l +e
installe on almost an) P, nowaa)s. GLScene ma!es e7elo'ing 0'enGL a''lications 7er) eas)
an sim'le. GLScene a''lications mae with Del'hi are 'rimaril) targete ?or Winows 'lat?ormA
there is clone o? GLScene ?or I)li& so 'orting to Lin*& sho*l +e 'ossi+le. (*t I ha7e ne7er one it
an I onBt !now i? the ?*nctionalit) remains the same. >here is no s*''ort ?or 8ac 'lat?orm.
GLScene was ?o*ne +) 8i!e Lisch!e an ?rom the 7er) +eginning it was e7elo'e as a
o'en so*rce li+rar) ?or 'rogrammerBs comm*nit). Later on it was ta!en o7er +) :ric Grange an is
steail) growing e7er since. >here is a n*m+er o? GLScene aministrators now. GLScene is hoste
+) www.so*rce?orge.net. >here is co*ntless n*m+er o? 'ro5ects mae with GLScene ranging ?rom
sim'le game emos to com'le& scienti?ic a''lications.
GLScene beginner's guide, Jan Zizka, 2005
Page "/36
Installing GLScene
>here are two wa)s how to o+tain GLScene so*rce coe. Which one will )o* choose
e'ens on )o*r intentions with this li+rar). I? )o* 5*st want to tr) it o*t ownloa the sna'shot
7ersion. Sna'shot is an archi7e ?ile containing all so*rce coe ?iles. Sna'shot is a7aila+le ?rom
www.glscene.org. It is 'ac!e with 1Gi' ?ormat Jwww.19Gi'.orgK. E*st *n'ac! it where7er )o* want
)o*r GLScene to resie.
6nother wa) how to ownloa GLScene is *sing ,.S. ,.S is an Internet 'rotocol s)stem
*se +) So*rce-orge ?or on line accessing so*rce coe re'ositories +) e7elo'ers. ,hoose this
metho i? )o* want to ha7e the latest 7ersion o? GLScene an chec! ?re@*entl) ?or changes an
*'ates. Lo* will nee ,.S client in orer to ownloa. >here are man) ,.S clients +*t I
recommen www.tortoisec7s.org.
6ll ,.S clients ha7e one thing in common. It is calle CVS root. It is a stringA in ?act an
aress that is *se to access we+. ,.S root ?or GLScene is=
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/glscene
I? )o* ha7e >ortoise,.S installe right clic! in irector) where )o* want GLScene to +e
ownloae an select CVS Checkout. :nter the a+o7e ,.S root. Lo* will also ha7e to s'eci?)
which irector) to ownloa. >his is calle module. Lo* nee these mo*les= DelphiX Jwhere 2 is
)o*r Del'hi 7ersionKA Source an Demos. Lo) ha7e to ownloa irectories one +) one.
0nce )o* ha7e all GLScene ?iles on )o*r har ri7e )o* can com'ile the 'ac!ages in Del'hi.
,hoose corres'oning irector) to )o*r Del'hi 7ersion. >here are se7en 'ac!ages in GLScene.
1. GL,g&.'! M ,g shaers.
2. GLSNDWS&.'! M C>0D0D
3. GLScene&.'! M core 'ac!age containing GLScene itsel?.
4. GLSN0D:&.'! M 0D: is 'h)sics 'l*g9in ?or GLScene.
". GLSNSDL&.'! M C>0D0D
6. GLSSN(6SS&.'! 9
1. GLSSN-80D&.'! M (6SS an -80D are so*n 'l*g9ins.
Lo* ma) ha7e to man*all) a GLScene irectories in Del'hi search 'ath. 6?ter s*ccess?*l
com'ilation there will +e ?o*r new com'onent ta+s. () e?a*lt the) will +e 'lace in the rightmost
'osition ne&t to other com'onent ta+s. Lo* will ha7e to scroll to the right in orer to see them or
rearrange the ta+s. Oow )o* are rea) to *se GLScene$
GLScene beginner's guide, Jan Zizka, 2005
Page 6/36
o! "oes it !ork?
Lo* are 'ro+a+l) *se to Del'hi .,L an Del'hi esign time ?*nctions. Designing Del'hi
?orm is a straight?orwar 'roce*re. .is*al com'onents that )o* '*t on the ?orm can +e right
7isi+le. With GLScene things are not that sim'le. Some com'onents are 7isi+le at esign time some
are not. >his cha'ter will e&'lain the 'hiloso'h) o? GLScene an the wa) GLScene is organiGe.
6ccoring to Del'hi naming con7entions e7er) GLScene class will start with >GL... 're?i&.
-irst o? all )o* sho*l !ee' in min that e7er)thing in GLScene has a strict hierarch). :7er)
o+5ect +elongs to other o+5ect which +elongs to another o+5ect. >his is calle 'arent P9Q chil
relationshi'. :7er) o+5ect can ha7e *nlimite n*m+er o? chilren +*t onl) one 'arent. >he to' o? the
o+5ect tree is TGLScene. >he analog) to this wo*l +e a TButton 'lace on a TPanel which is
'lace on TForm. >here is one interesting iss*e in the hierarch). 6n o+5ect alwa)s has a 'arent an
a owner. Parent an owner are not the same. 0wner m*st alwa)s +e TGLScene +eca*se it is
registere there. Parent howe7er can +e another o+5ect or >GLScene.0+5ects class.
>here are +asicall) two !ins o? o+5ects in GLScene = com#onents an scene ob$ects.
,om'onents are organiGe in ?o*r com'onent ta+s an can +e 'lace on the ?orm an accesse onl)
in o+5ect ins'ector. >he) can +e consiere Bser7icing com'onentsB ?or the secon t)'e o? o+5ects.
Scene o+5ects can +e aeA eite an elete in the scene eitor. Scene o+5ects act*all) re'resent
the content that is going to +e renere in the scene. Scene o+5ects are also is'la)e in o+5ect
ins'ector +*t o+5ect inspector lac!s the ?*nctionalit) o? scene eitor. >his is m) own classi?ication
an has nothing to o with Del'hi%s inter'retation o? wors #o+5ect% an #com'onent%.
Scene eitor is the heart o? GLScene. >o o'en scene eitor TGLScene has to +e 'lace on
the ?orm. Do*+le clic! on it in o+5ect ins'ector. Oew winow 'o's *'. >here are eiting +*ttons in
the to' row an a tree 7iew +o& +elow. Lo* can aA selectA mo7e an elete scene o+5ect in the tree
7iew +o&. Lo* can also is'la) each o+5ectBs e??ects an +eha7iors here.
GLScene beginner's guide, Jan Zizka, 2005
Page 1/36
%ello !orl" &' e(am#le
8an) 'rogramming g*ies contain the o+ligator) #Hello worl $% e&am'le. It is *s*all)
sim'le a''lication where *ser 'resses +*tton an message winow sa)ing #Hello worl $% a''ears.
>his is necessar) ?or reaers that can%t wait to start with something in 'ractice. In m) o'inion the
e@*i7alent to this in 3D gra'hics 'rogramming is a s'inning c*+e.
So here is ste' +) ste' g*ie how to create s'inning c*+e in GLScene=
1. Start new a''lication in Del'hi.
2. Do*+le clic! on GLScene to a GLScene1 M white c*+e on GLScene ta+ ?irst ?rom le?t.
3. Do*+le clic! on GLSceneViewer to a GLSceneViewer1 M white c*+e with camera on GLScene
ta+ secon ?rom le?t.
4. Select alClient as Alin 'ro'ert) ?or GLSceneViewer1.
". Do*+le clic! on GLCadencer to a GLCadencer1 M metronome on GLScene ta+ ?i?th ?rom le?t.
6. Select GLScene1 as Scene 'ro'ert) o? GLCadencer1.
1. Do*+le clic! on GLScene1 in o+5ect tree 7iew to o'en GLScene eitor.
4. /ight clic! on Cameras in GLScene eitor an clic! on Add camera.
;. Select Camera1 an set Position!X "# $% Position!& "# $% Position!' "# $% to mo7e the camera
+ac! so it can o7erloo! the scene.
1<./ight clic! on Scene o()ects in GLScene eitor an select Add o()ect then LihtSource.
11.Select GLLihtSource1 an set Position!' "# 1* to mo7e the light *' so it can shine on the c*+e
?rom a+o7e.
12./ight clic! on Scene o()ects in GLScene eitor an select Add o()ect then Basic eometr+ then
Cu(e.
13.Select Camera1 an set GLCu(e1 as Taret 'ro'ert) to ma!e the camera loo! at the c*+e.
14.Select GLSceneViewer1 an select GLCamera1 as Camera 'ro'ert).
1".Do*+le clic! on GLCu(e1 in o+5ect tree 7iew to a 'rogress e7ent on the ?orm.
16.Write GLCu(e1!TurnAnle "# GLCu(e1!TurnAnle , deltaTime - 1**% this will ma!e the c*+e
s'in aro*n F a&is.
11.Press -; an see )o*r ?irst s'inning c*+e$
0ne might sa) that a s'inning c*+e is a tri7ial thing. It inee is with GLScene +*t let%s
reconsier what it ta!es to raw a s'inning c*+e on moern harware an o'erating s)stem. -irst
GLScene itsel? has goo ?ew tho*sans o? lines o? coe. Oot all o? it is *se to rener a c*+e o?
co*rse. >hen we ha7e 0'enGL with all the 'ossi+le ri7ers. 6n in the en there is the o'erating
s)stem on to' o? all that. So )o* can see there was a lot o? wor! an e??ort one +) other 'eo'le so
)o* can ma!e )o*r s'inning c*+e.
GLScene beginner's guide, Jan Zizka, 2005
Page 4/36
)asic things yo* sho*l" kno! abo*t +D gra#hics
GLScene is a 7er) 'ower?*l tool +*t )o* still nee to !now at least something a+o*t 3D
com'*ter gra'hics. S!i' this cha'ter i? )o* are ?amiliar with this to'ic. >here is a lot o? theor) a+o*t
3D gra'hics. I onl) want to 'oint o*t some +asics an things s'eci?ic to GLScene an 0'enGL.
Coor"inate system
6 three imensional worl is escri+e with three a&es= 2A LA F. >he) intersect in the origin
'oint at 'osition C<A<A<D with ;<R angle. >he orientation o? these a&es can +e a +it con?*sing. 8ath
con7entions antici'ate that the *' an own a&is is LA le?t an right a&is is 2 an the e'th is
escri+e +) F. (*t 0'enGL stanar sa)s that F is *' an own an L is the e'th. 2 a&is remains
the same. So )o* sho*l remem+er that 0'enGL coorinate s)stem is i??erent then ?or e&am'le the
one other 3D eiting a''lications *se. Lo* can is'la) o+5ects% a&es +) setting ShowA.es"#true.
>he) will +e re'resente +) reA green an +l*e otte lines +oth esign an r*n time. >o ma!e
things e7en more com'licate some o+5ects *se the con7entional coorinate s)stem li!e TGLGraph
an TGLTerrain/enderer.
In the en which irection is *' will e'en on the camera rotation. Lo* can 'osition )o*r
o+5ect in the scene in whiche7er orientation )o* li!e. () e?a*lt a new o+5ect will +e 'lace in the
irection ?acing 'ositi7e L a&is an to' o? the o+5ect 'ointing to 'ositi7e F a&is.
It is im'ortant to *nerstan the i??erence +etween glo+al an local coorinate s)stem.
:7er) chil o+5ect e&ists in its own local coorinate s)stem. I? 'arent changes it%s 'osition or
rotation the chil will mo7e with the 'arent +*t it%s local 'osition will remain the same altho*gh it
change glo+al 'osition. >his ma) loo! a +it com'licate at the +eginning +*t it is an im'ortant
?eat*re that allows !ee'ing the scene hierarch) well organiGe.
,loating #oint n*mbers
0'enGL *ses single 'recision s)stem. What oes it mean? It means that e7er) ecimal
n*m+er is 4 +its long. LetBs e&'lain this more. Decimal n*m+ers can ha7e *nlimite n*m+er o?
igits a?ter the ecimal se'arator. >he S constant is a goo e&am'le. ,om'*ter can calc*late the S
constant ?or as man) igits as itBs memor) is ca'a+le o?. (*t that is not 7er) 'ractical. So where o
we set the limit? :7er)one can *nerstan the i??erence +etween 3.14 an 3.141";26"3". Del'hi
has strong s*''ort ?or t)'es. In Del'hi we ha7e singleA "o*ble an e(ten"e" t)'es ?or ecimal
n*m+ers. Single is 4 +it long so it means the 'rogram allocates 4 +its o? memor) ?or it. >he n*m+er
o? igits is limite. >he S constant wo*l +e 3.141";26 in single t)'e ?ormat. (*t what ha''ens i?
we a 1<<< ? >he res*lt sho*l +e 3<<<.141";26. (*t there are too man) igits in this ecimal
n*m+er ?or the single t)'e ?ormat. What ha''ens is that the last igits are trimme an we get the
right length = 3<<<.141". >his moel is sim'li?ie +eca*se the whole math is ha''ening on +inar)
le7el +*t )o* get the 'ict*re.
/emem+er that single 'recision is not acc*rate eno*gh when wor!ing with high n*m+ers or
when )o* nee e&tra 'recision. I? )o* are oing some scienti?ic calc*lations )o* can *se e&tene
t)'e to get more e&act res*lts. (*t i? there is an 0'enGL gra'hical o*t'*t li!e a gra'h all e&tene
n*m+ers will +e own sam'le to single 'recision.
It is not recommene to *se Del'hiBs nati7e 8ath *nit with GLScene +eca*se the ?*nctions
in this *nit are too slow ?or real time renering. 67oi *sing 8ath *nit i? )o* can.
-ectors
Oow when we !now what ?loating 'oint n*m+ers are we can e&'lain what the) are *se ?or.
GLScene beginner's guide, Jan Zizka, 2005
Page ;/36
In GLScene a lot o? calc*lations is one with 7ectors. .ector is an *ni7ersal t)'e that can escri+e
almost an)thing ?rom o+5ectBs 'ositionA rotationA s'ee e7en color. >here are i??erent t)'es o?
7ectors= .ector3?A .ector4?A 6??ine.ector. (*t 7ector generall) is an arra) o? three singles C2ALAFD.
Some 7ectors ha7e the m)sterio*s ?o*rth mem+er calle W. W is *se ?or escri+ing rotations or
al'ha 7al*e o? the color. 8an) GLScene ?*nctions are o7erloae an )o* can s*''l) most o? the
7ector t)'es as a 'arameter.
0'enGL internall) oes not o'erate on 7ectors +*t on matrices. 8atri& is a two imensional
arra) o? 4 & 4 singles. 8atri& trans?ormations ta!e care a+o*t *se?*l things li!e 7ector rotationsA
scaling etc. Lo* o not reall) nee to !now a+o*t matri& trans?ormations +eca*se GLScene has
?*nctions to o the 5o+ ?or )o*. >hese ?*nctions are in VectorGeometr+ *nit. Detaile escri'tion o?
7ector geometr) ?*nctions is ?ar +e)on the sco'e o? this +oo! +*t there is a goo article at
www.?li'coe.com a+o*t 7ector math.
.en"ering
:7er) o+5ect in 3D gra'hics is com'ose o? 'ol)gons. :7en c*r7e s*r?aces are mae *' o?
'ol)gons onl) 7er) small ones. Pol)gon is a triang*lar ?ace elimite +) three 7ertices. .erte& is a
'oint in s'ace. :ach 'ol)gon has ?ront an +ac! sies e?ine +) ?ace normal. Oormal is a 7ector
'ointing in ?ront irection o? the ?ace. 6nother in?ormation store +) ?ace is connecti7it) with other
?aces. Pol)gon !nows which s*rro*ning 'ol)gons are attache to which sie o? it. >his is *se ?or
smoothing eges +etween two a5acent 'ol)gons. Pol)gon also stores in?ormation a+o*t how
te&t*re is stretche o7er its s*r?ace. >e&t*re coorinates o? e7er) 7erte& are e?ine +) two n*m+ers
in range ?rom < to 1. >hese are calle 3 an . coorinates an s'eci?) e&act 'osition o? the 7erte&
on te&t*re.
When the 'ol)gon gets renere 'ossi+le s*rro*ning lights are consiereA the angle
+etween ?ace normal an irection to camera an lights is consiere an the 'ol)gon is lit an
te&t*re accoring to shaing moel. Di??erent shaes o? 'ol)gon along c*r7e s*r?ace create
ill*sion o? 'lasticit).
>o rener whole o+5ect which is mae *' o? 'ol)gons the o+5ect has to +e ?irst trans?orme
in 'ositionA rotation an scale. :7er) renere 'i&el is store in F +*??er. F +*??er is memor)
allocate ?or all 'i&els on the screen together with F e'th M istance ?rom the camera. :7er) time a
new 'ol)gon is renere the res*lting 'i&els o7erwrite 'ossi+le e&isting ones onl) i? the F e'th is
smaller than the one store in F +*??er ?or that 'artic*lar 'i&el. 8ore *nerstana+l) new 'ol)gon is
renere onl) i? it is closer than other 'ol)gons.
/#enGL
>his is a wie to'icA too com'licate ?or this +oo!. Lo* onBt necessaril) nee to !now
m*ch a+o*t 0'enGL to *se GLScene +*t it is certainl) +etter to ha7e some *nerstaning o? it.
GLScene beginner's guide, Jan Zizka, 2005
Page 1</36
Com#onents
>his cha'ter is i7ie in ?o*r 'arts escri+ing ?o*r gro*'s o? GLScene com'onents= GLSceneA
GLScene 0,1A GLScene *tils an GLScene sha"ers.
GLScene
GLScene
>he +asic com'onent. Lo* can o'en GLScene eitor +) o*+le clic!ing on it.
GLScene-ie!er
>he scene 7iewer re'resents a rectang*lar can7as where the scene gets renere. ItBs siGe or
with M length ration is not restricte. >he +igger the 7iewer the slower the renering will +e. Lo*
m*st s'eci?) Scene an Camera 'ro'erties. ,hange im'ortant renering conte&t thro*gh Bu00er
'ro'ert). Howe7er lea7ing Bu00er e?a*lt 'ro'erties will s*??ice in most cases.
GL,*llScreen-ie!er
Same as >GLScene.iewer +*t switches to ?*llscreen moe. >he resol*tion has to +e
reaa+le ?or the gra'hics car an monitor. So it sho*l +e something li!e 4<< & 6<< or 1<24 & 164.
GL2emory-ie!er
8emor) 7iewer is a 7irt*al can7as. Lo* can rener on itA rea it%s o*t'*t ?rom the memor).
(*t )o* can not see an) 'ict*re on the screen. It is *se ?or e&am'le ?or renering c*+e ma's ?or
real time re?lections or more a7ance shaow techni@*es.
GL2aterialLibrary
8aterial li+rar) is a storage com'onent ?or materials. It has collection o? materials an )o*
can access ini7i*al materials +) ine& or the material name.
6t this 'oint I sho*l e&'lain something a+o*t how materials are hanle in GLScene. :ach
o+5ect where material is a''lica+le has its 1aterial 'ro'ert). Lo* can eit materials irectl) in
o+5ect ins'ector or o*+le clic! on the elli'sis icon ne&t to material an o'en material eitor.
8aterial eitor has three ta+s an a winow with an e&am'le c*+e te&t*re with c*rrent material.
>he three ta+s are=
1. ,ront #ro#erties M eit material @*alit) o? o+5ect%s ?ront ?aces. Di??*se color +eing the most
im'ortant. It e?ines color o? the o+5ect on irect light. 6m+ient color e?ines the color o?
o+5ect in ar! s'ots. S'ec*lar color is color o? high re?lections an shininess e?ines how +ig
those re?lections are. :mission color ma!es the o+5ect glow. (*t ?or now 5*st remem+er that
to change o+5ect%s +asic color *se i??*se color. 0ther material @*alities li!e re?lection an
shininess can +e achie7e more realisticall) with material shaers.
GLScene beginner's guide, Jan Zizka, 2005
Page 11/36
2. )ack #ro#erties M same as ?ront 'ro'erties +*t ?or ?aces that wo*l +e normall) in7isi+le.
>he +ac! ?aces +ecome 7isi+le onl) i? the material is trans'arent an i? +ac! ?ace c*lling is
o??.
3. 3e(t*re M in orer ?or the te&t*re to +ecome 7isi+le )o* ha7e to set disa(led 'ro'ert) o??.
>his 'ro'ert) is +) e?a*lt on which means that the o+5ect is not *sing an) te&t*re. It is
colore an shae with settings escri+e +) ?ront an +ac! 'ro'erties. I? )o* want to a''l) a
te&t*re to the material *nchec! disa(led chec!+o& an loa an image. -ormats s*''orte +)
GLScene are +m'A 5'g an tga. >hen )o* ha7e to set te&t*re mo*lation to tm1odulate ?or
realistic lightning. /emem+er that a light has to ill*minate the o+5ect so )o* can see the
material. 6nother im'ortant thing is that te&t*re sho*l ha7e the siGe o? 'ower o? two. It
means 4A4A16A32A64A124A"12T >he length an with on%t ha7e to +e the same. Lo* can ha7e
a te&t*re 32 & "12. I? )o* *se a te&t*re with siGe other than 'ower o? two it will +e is'la)e
+*t it will also +e m*ch slower +eca*se GLScene will ha7e to resiGe it.
6t +ottom o? material eitor there is material blen"ing mo"e list+o& selection. Lo* can
s'eci?) how the material will +len or o7erla) other materials. 0'a@*e +lening moe creates a
soli s*r?ace o+5ect. >rans'arent +lening will ma!e it 'ossi+le to see thro*gh the o+5ect. >he
o+5ect can +e *ni?orml) trans'arent or the trans'arenc) can +e e?ine +) te&t*re. 6iti7e +lening
com+ines the colors o? the o+5ect with colors +ehin it.
6ltho*gh each o+5ect can ha7e its own material it is strongl) a7ise to store the materials
)o* *se in material li+rar). :s'eciall) i? man) o+5ects share the same te&t*re. I? )o* ha7e 1<< c*+es
with the same te&t*re an )o* loa the te&t*re to each c*+e it will occ*') the memor) o? 1<<
te&t*res. Lo* can loa this te&t*re in material li+rar) once an let the 1<< c*+es re?er to that te&t*re.
>o o this set 1aterial!1aterialLi(rar+ to the material li+rar) an 1aterial!Li(1aterial2ame to
the name o? the material )o* want to *se. Warning $ 0+5ects ha7e 1aterialLi(rar+ 'ro'ert)
themsel7esA )o* ha7e to *se 1aterial!1aterialLi(rar+ 3
8aterial li+rar) has one han) ?*nction= AddTe.ture1aterial! In this ?*nction )o* s'eci?)
new material name an image ?ile to +e loae. 6 new material is ae to the material li+rar) with
Te.ture!Disa(led"#0alse an Te.ture!1odulation"#tm1odulate!
GLCa"encer
8ost o? the GLScene a''lications o real time renering. >he time element ta!es im'ortant
'art here. We nee some !in o? time manager to eal with it. It is not a sim'le thing at all. -irst o?
all we o not !now how long will it ta!e ?or the com'*ter to rener the scene. >he camera ma) +e
loo!ing at com'le& geometr) with a lot o? 'ol)gons or the *ser ma) t*rn the camera awa) an no
'ol)gons will +e renere. >he 'rogram ma) r*n on an ol harware con?ig*ration or a to' high9
tech P, with the latest ,P3 an gra'hics accelerator. >hese are ?actors )o* on%t !now in a7ance
an )o* m*st ta!e them into acco*nt.
I? )o* want to 'rogress )o* scene o7er time a TGLCadencer on the ?orm. It will ta!e care
o? 'ro'er s)nchroniGing an *'ating o+5ects ?rame +) ?rame. Lo* m*st assign it to
TGLScene!Cadencer 'ro'ert).
>he 'rocess o? renering a ?rame res*lts in e7ent calle Proress in GLScene! :7er)
GLScene o+5ect has onProress e7ent where )o* can coe all e&tra actions to +e e&ec*te e7er)
time the scene is renere. Do*+le clic!ing on an o+5ect in o+5ect ins'ector as onProress e7ent
to the ?orm.
>he 'rogress 'roce*re 'asses one im'ortant 7aria+le= deltaTime! It is a time 'erio in
secons that too! since the last ?rame was renere. >he longer it is the more 5er!) the motion in the
scene will +e. Ieal ?rame rate is 3< ?rames 'er secon. DeltaTime wo*l +e <.<33333. 6n) time
GLScene beginner's guide, Jan Zizka, 2005
Page 12/36
)o* want to o an) calc*lations relate to time )o* ha7e to incl*e this 'arameter in )o*r e@*ations.
-or e&am'le i? )o* want to mo7e a c*+e along 2 a&es with s'ee o? 1< *nits 'er secon. >he
?orm*la wo*l +e li!e this= Position!X"#Position!X , 1* - deltaTime.
,aencer has ena(led 'ro'ert). Lo* ca sim'l) t*rn caencer on an o??. When it is t*rne
o?? the scene will ?reeGe. >here are also se7eral moes caencer can r*n in. cmASAP is the e?a*lt
moe an it will 'rogress the scene whene7er it can gi7ing it the highest 'riorit). cm4dle will
'rogress scene onl) when other 'rocesses are ?inishe an with cm1anual the scene will onl)
'rogress when )o* ma!e it to o so. 6nother interesting ?eat*re is minDeltaTime! I? )o* set 7al*e
?or minDeltaTime the scene will not 'rogress *ntil that time has 'asse e7en i? all renering is one.
>his can gi7e some rest ?or the s)stem. ma.DeltaTime on the other han will not allow the caencer
to r*n ?aster then s'eci?ie.
GLG*iLayo*t
G3I stans ?or #gra'hical *ser inter?ace%. >he '*r'ose o? G3I com'onents is to create
2D winow controllers well !nown ?rom Del'hi M ?ormsA 'anelsA la+elsA chec! +o&es etc. In G3I
manager )o* s'eci?) G3I la)o*t which is a ?ile with .la)o*t e&tension create with G3I eitor. >his
la)o*t s'eci?ies regions on a +itma' which is *se ?or the gra'hic o*t'*t. >his to'ic will +e co7ere
in more etail later in G3I o+5ects cha'ter.
GL)itma#,ont
Lo* can is'la) 2D te&t with TGLBitmapFont. >his com'onent is *se together with
TGL56DTe.t. Lo* ha7e to loa a +itma' that contains letters arrange in rows an col*mns. >he
letters m*st +e on +lac! +ac!gro*n ?or correct trans'arenc). /anes 'ro'ert) s'eci?ies which
regions o? the +itma' corres'on to which letter. :ach range has with an length in 'i&els o? the
letter together with starting an ening character in al'ha+et in 6S,II stanar. (itma' ?ont will
create arra) o? te&t*res each re'resenting one character. TGL56DTe.t can rea these te&t*res an
is'la) wors. Disa7antage o? TGLBitmapFont is that all the letters m*st ha7e same with. #I% is
same wie as #8%. >he a7antage is that )o* can ma!e a +itma' )o* li!e with colore characters
an i??erent trans'arenc).
GLWin"o!s)itma#,ont
I? )o* on%t want to +other with ma!ing the +itma' )o* can *se e&isting Winows ?ont.
Lo* 5*st select Font 'ro'ert) an TGL7indowsBitmapFont will create all te&t*res ?or
TGL56DTe.t. With this com'onent an) tr*e t)'e ?onts will +e is'la)e correctl) +*t )o* ha7e to
*se some common ?onts that will most li!el) +e installe on the target com'*ter.
GLStore")itma#,ont
>his is the thir an in m) o'inion the most *se?*l ?ont com'onent in GLScene. Lo*
can istri+*te )o*r ?ont with the a''lication sa7e in .gls? ?ile. >his ?ile is create with C>0D0D
7er) easil) ?rom an) Winows ?ont. >his wa) )o* can *se some more e&otic ?onts an )o* o not
ha7e to worr) i? the) are installe on other com'*ters or not. (oth TGL7indowsBitmapFont an
TGLStoredFont can%t ha7e characters with i??erent colors. Lo* can onl) change a color as a whole.
GLScri#tLibrary
C>0D0D
GLSo*n"Library
GLScene is not onl) great ?or gra'hics )o* can also a 3D so*n to )o*r a''lications.
GLScene beginner's guide, Jan Zizka, 2005
Page 13/36
So*n li+rar) is similarl) li!e material li+rar) a storage room ?or so*n trac!s. Loa i??erent so*n
?iles in Samples. Wa7 an m'3 ?ormats are s*''orte. (eware that longer m'3 so*ns li!e m*sic
ma) 'ro*ce errors when 'la)ing thro*gh so*n li+rar). So*n li+rar) has to +e *se together with
TGLS17a8e9ut: TGLS1BASS or TGLS1F19D. >o 'la) the so*n a so*n +eha7ior to scene
o+5ectA s'eci?) which so*n to 'la) +) ine& or name an the so*n will +e emitte +) the o+5ect in
3D s'ace.
GLS2Wa4e/*t
C>0D0D
GL/D52anager
0D: is #0'en D)namics :ngine%. It is 'h)sics sim*lation li+rar). Its home 'age is
www.oe.org . Lo* can ?in oc*mentation an hel' ?iles there. 0D: is istri+*te in single ll
?ile. oe.ll m*st +e in the same irector) as )o*r a''lication e&ec*ta+le ?ile or in Winows s)stem
irector). Sim'l) sai an) scene o+5ect with 0D: +eha7ior will nat*rall) react to gra7it)A collie
an +o*nce o?? other o+5ects. Lo* can create carsA rag oll e??ect sim'le machines. >o ma!e 0D:
o+5ect in the scene a 0D: +eha7ior to it. >here are two !ins o? 0D: +eha7iors=
1. Static M o+5ects are s*''ose to remain sta+le in the scene. >he) will not mo7e whate7er
ma) hit them. :&am'le wo*l +e gro*n ?loor or walls.
2. Dynamic M o+5ects ha7e their weight an can mo7e aro*n the scene interacting with other
o+5ects or 5oints. :&am'le is a +all.
6'art ?rom the !in o? +eha7ior )o* m*st select 'ro'er collier. It is a sha'e attache to the
o+5ect that stans ?or the mass o? the o+5ect. ,ollier can +e sim'le c*+eA s'hereA c)liner or can +e
e&tracte ?rom mesh geometr) or height?iel ata. 0ne o+5ect can ha7e m*lti'le colliers creating
com'le& sha'e.
0D: manager r*ns the sim*lation thro*gh oe.ll an *'ates each o+5ect%s 'osition an
rotation. Lo* m*st call Step 'roce*re e7er) ?rame ?or the s)stem to 'rogress. >his is *s*all) one
in caencer%s onProress e7ent.
GL/D5JointList
I? )o* want to *se 5oints in 0D: )o* m*st a them in the 5oint list. :ach item escri+es
the t)'e o? the 5ointA the two o+5ects it attaches an other 'arameters li!e 5oint restrictionsA anglesA
o??set 'ositions etc. -or more in?ormation a+o*t 5oints go to www.oe.org .
GLS2)6SS
(6SS is a so*n li+rar). 6gain +ass.ll m*st +e either in a''lication or Winows s)stem
irector). >GL(6SS is so*n manager that is *se together with TGLSoundLi(rar+ an o+5ect
so*n +eha7ior to 'la) so*ns.
GLS2,2/D
Same as (6SS onl) *ses ?mo.ll.
GLScene 0,1
GLScene beginner's guide, Jan Zizka, 2005
Page 14/36
In general all com'onents on this ta+ are managers ?or 'article e??ects. P-2 manager ta!es
care a+o*t the wa) 'articles loo! li!eA how the) mo7eA how ?ast the) are or how long the) li7e.
Some 'articles can e7en change a''earance *ring their li7e. :ach o+5ect can emit 'articles. Lo*
can a 'article e??ects to ;00ects 'ro'ert). :ach e??ect then has its own P-2 manager an P-2
renerer.
GLC*stom0,12anager
C>0D0D
GL0olygon0,12anager
Pol)gon 'articles are mae *' o? circ*lar arra) o? triang*lar 'ol)gons alwa)s ?acing
camera. Pol)gons *se 7erte& colors. Lo* can s'eci?) inner an o*ter color ?or the 'article. 0*ter
color is *s*all) trans'arent. :ach 'ol)gon is o'a@*e in the center o? the 'article an gra*all)
+ecomes trans'arent towars the ege.

GL0ointLight0,12anager
C>0D0D
GLC*stomS#rite0,12anager
C>0D0D
GL0erlin0,12anager
Particles create with 'erlin P-2 ha7e ranoml) generate te&t*re. Great ?or smo!e
e??ects.
GL,ire,12anager
>his is manager es'eciall) esigne ?or ?ire e??ect. It is +est to lea7e e?a*lt settings ?or
the most 'leasing 7is*al @*alit). 65*st onl) the 'article siGe as )o* nee.
GL3hor,12anager
,reate lightning or laser +eams with this e??ect. >his e??ect stretches ?rom one 'oint to
another. 6 s'ar!ling +eam glows +etween.
GLScene 7tils
6sync3imer
>his com'onent is similar to TTimer )o* !now ?rom Del'hi. 0nl) it is more s*ita+le ?or
GLScene beginner's guide, Jan Zizka, 2005
Page 1"/36
GLScene. >ime 4nter8al in millisecons triggers onTimer e7ent. >his e7ent is ine'enent o?
caencer 'rogress e7ent. 6s)nc timer is not recommene to re'lace the caencer. It is *se to
e&ec*te actions in ?i&e longer time inter7als rather than ta!e care a+o*t renering the scene.
GLStaticIm#oster)*il"er
Im'osters are cle7er wa) how to im'ro7e 'er?ormance ramaticall). >he +asic iea
+ehin im'osters is that +e?ore renering a set o? images loo!ing at an o+5ect ?rom all sies is
renere an store in memor). I? the o+5ect is to +e renere a s'rite J2D imageK is rawn instea
o? the mesh. >he most a''ro'riate image has to +e selecte accoring to the o+5ect%s orientation to
the camera. >his techni@*e is great ?or man) same o+5ects with high 'ol)gon co*nt scattere aro*n
the scene. 0n the other han it cons*mes a lot o? memor).
>he tas! o? im'oster +*iler is to generate all the images. Lo* can set the siGe o? the image
an n*m+er o? angles images are to +e renere ?rom. >his is one +) aing coronas. :ach corona
has minim*m an ma&im*m angles as well as n*m+er o? images in this range. -or e&am'le i? )o*
ma!e corona ranging ?rom <U to 1"U with 24 images the im'oster will co7er s'herical segments 1"U
wie an 1"U high aro*n #e@*ator% o? the o+5ect. Lo* m*st call /e<uest4mposterFor ?*nction to
generate the coronas.
-ollowing section escri+es ?i7e HDS com'onents. eight Data So*rce com'onents 'ro7ie
ata ?or TGLTerrain/enderer. >errain is *se ?or renering large o*toor sceneries. HDS
com'onents loa terrain ata ?rom i??erent ?ormats an s*''l) s*ita+le ata ?or terrain renerer.
GL)itma#DS
>his is the easiest ?ormat. (itma' HDS loas gra)scale image an con7erts the ata into
height ?iel. >he gra)scale image m*st +e 16 +it. 8ost 'aint 'rograms *se 4 +it gra)scale 'alette.
8a!e s*re )o* con7ert the image to 16 +it otherwise the terrain will loo! terrace. White 'arts o?
the image re'resent the highest altit*e an +lac! 'arts re'resent Gero altit*e.
3GLC*stomDS
C>0D0D
GLeight3ile,ileDS
>he so*rce ?or height ?iel HDS is .ht? ?ile. >hese ?iles are create in C>0D0D. >his
?ormat is most s*ita+le ?or reall) large terrains. Gro*n te&t*re coorinates together with TileSi=e
'ro'ert) are incl*e in .ht? ?ile. TileSi=e o? terrain renerer m*st +e the same as TileSi=e in .ht? ?ile.
GL)*m#ma#DS
C>0D0D
GL0erlinDS
C>0D0D
Collision2anager
C>0D0D
GL6nimationControler
6nimation controller is *se together with TGLActor o+5ect. 6nimation controller stores
animations that are *se +) actor. 6nimations can +e loae ?rom V*a!e m2 ?ormat or ?rom
Hal?li?e sm ?ormat. 6nimations are accesse +) ine& or name. >he) can loo'A 'la) once or
GLScene beginner's guide, Jan Zizka, 2005
Page 16/36
+ac!wars.
Joystick
C>0D0D
ScreenSa4er
I? )o* a this com'onent on the ?orm the a''lication will +e com'ile as Winows
screen sa7er.
6-I.ecor"er
Lo* can stream the renere se@*ence in 7ieo ?ile.
GL3ime54ents2G.
C>0D0D
GL-8s069
C>0D0D
GL:a4igator
C>0D0D
GL7serInter8ace
C>0D0D
GL,0S2o4ement2anager
C>0D0D
GL2aterialScri#ter
C>0D0D
GLDC52anager
C>0D0D
6##lication,ileI/
C>0D0D
GLScene Sha"ers
Shaers are material moi?iers. :ach material can ha7e a shaer. Shaer alters the a''earance
o? the material creating 7ario*s 7is*al e??ects.
GLScene beginner's guide, Jan Zizka, 2005
Page 11/36
GL3e(CombineSha"er
C>0D0D
GL2*lti2aterialSha"er
C>0D0D
GL7serSha"er
C>0D0D
GL/*tLineSha"er
C>0D0D
GLi""enLineSha"er
C>0D0D
GLCelSha"er
C>0D0D
GL)*m#Sha"er
C>0D0D
GL0hongSha"er
C>0D0D
GLScene beginner's guide, Jan Zizka, 2005
Page 14/36
/b$ects
6s escri+e in #How oes it wor!?% cha'ter I re?er to GLScene o+5ects as o+5ects not 'resent
in com'onents ta+s. GLScene o+5ects are createA eite an elete in GLScene eitor. 0+5ects are
arrange into categories. Some o+5ects on%t ?all into an) categor) an stan alone.
Let%s ha7e a closer loo! at GLScene eitor +e?ore we start escri+ing o+5ects one +) one.
GLScene eitor is o'ene +) o*+le clic!ing on GLScene in o+5ect eitor. 6 tree 7iew contains all
o+5ects in )o*r scene. 6t the +eginning there will +e onl) Scene root that contains Cameras an
Scene ob$ects. Scene root re?ers to GLScene!9()ects which is the to' element in scene hierarch).
Cameras ha7e s'ecial 'osition in the hierarch). /ight clic! on cameras then clic! on 6"" camera
a new camera is create. Later the camera can +e mo7e aro*n the hierarch) tree an +ecome a
chil o? an) other o+5ect. 6ll other o+5ects )o* create will +e arrange *ner scene ob$ects. >o
'lace an o+5ect in the scene right clic! scene ob$ects an select the o+5ect )o* want. I? )o* want the
new o+5ect to +ecome a chil o? alrea) e&isting o+5ect right clic! on the 'arent o+5ect. 6 new
o+5ect is alwa)s 'lace on the last 'osition within the c*rrent hierarch) tree le7el.
>he orer o? o+5ects in the tree hierarch) is im'ortant. >he to'most o+5ect gets renere ?irst.
I? it has an) chilren the) are renere ne&tA the one on the to' ?irst again. >he renering goes on
+ranch +) +ranch *ntil it reaches the +ottom o? the tree. >he renering orer is im'ortant ?or
trans'arent o+5ects. >rans'arent o+5ects m*st alwa)s +e renere last otherwise )o* can get 7is*al
arti?acts in the scene. Some o+5ects tho*gh Jli!e H3D o+5ects or 'articlesK ta!e care a+o*t renering
orer themsel7es an can +e 'lace an)where in the tree hierarch). Lo* can change o+5ect%s
'osition in the tree +) ragging it o7er to another o+5ect or +) right clic!ing on it an selecting
2o4e ob$ect *# or 2o4e ob$ect "o!n.
Common ob$ect #ro#erties
6ll o+5ects ha7e some 'ro'erties that )o* will *se ?re@*entl). Here is an itemiGe list o? some
'ro'erties common to all o+5ects=
Behaviors M I? )o* a +eha7ior to o+5ectA it will act accoring to that +eha7ior. 3s*all)
the) alter o+5ectBs mo7ementA so*n or collision etections. Lo* can a more than one
+eha7iors. >he) wor! together with GLScene 6tils com'onents.
List o? +eha7iors=
,ollision
Sim'le Inertia
Sim'le 6cceleration
So*n :mitter
8o7ement controls
-PS 8o7ement
D,: Static ,ollier
D,: D)namic ,ollier
0D: D)namic
0D: Static
0D: Height-iel ,ollier
GLScene beginner's guide, Jan Zizka, 2005
Page 1;/36
Children M Oot shown in o+5ect ins'ector. List o? all chilren this o+5ect has. ,hilren can
+e accesse +) ine& starting with Gero.
Count > Oot shown in o+5ect ins'ector. O*m+er o? chilren 'l*s one. >he arra) o? chilren
is Gero +ase ine&.
Direction > .ector 'ointing in #?ront% o? o+5ect. >his 7ector is normaliGe. It means that it%s
length is 1. De?a*lt 7al*e is C<A<A1D.
Effects > :ach o+5ect can emit 'article e??ects. I? )o* *se one o? P-2 managers )o* can a
e??ects here.
List o? a7aila+le e??ects=
P-2 So*rce
-ire-2
>hor-2
:&'losion-2
Objects Sorting >he orer in which o+5ects get renere.
Material > Descri+e in TGL1aterialLi(rar+ cha'ter.
Parent > Oot shown in o+5ect ins'ector. 0+5ect one le7el *' in scene hierarch) tree.
PitchAngle M 6ngle escri+ing o+5ect%s rotation aro*n L a&is in egrees. (e aware that
changing this 7al*e oes not alwa)s 'ro*ce the same e??ect. It is recommene to *se
Direction an 6p 7ectors instea.
Position > .ector escri+ing 'osition o? o+5ect in 3D s'ace. De?a*lt 7al*e is C<A<A<D.
RollAngle M 6ngle escri+ing o+5ect%s rotation aro*n 2 a&is in egrees. (e aware that
changing this 7al*e oes not alwa)s 'ro*ce the same e??ect. It is recommene to *se
Direction an 6p 7ectors instea.
Scale M >he siGe o? o+5ect is set +) this 7ector. Lo* can scale the o+5ect non9*ni?orml)A ?or
e&am'le onl) along 2 a&is. ,hilren o not inherit scale 7al*e. De?a*lt 7al*e is C1A1A1D.
ShowAes > (oolean 7al*e ena+les is'la)ing colore lines aligne to o+5ect irection a&es.
!ag"loat > Similar to well !nown Ta 7al*e onl) it stores single.
!urnAngle M 6ngle escri+ing o+5ect%s rotation aro*n F a&is in egrees. (e aware that
changing this 7al*e oes not alwa)s 'ro*ce the same e??ect. It is recommene to *se
Direction an 6p 7ectors instea.
#$ > >his 7ector together with Direction is *se to escri+e o+5ect%s rotation in s'ace. 6p
7ector is alwa)s 'er'enic*lar to Direction 7ector an is also normaliGe. De?a*lt 7al*e is
C<A1A<D.
%isibilit& culling M .isi+ilit) c*lling can +e *se to s'ee *' renering. 0+5ects that are not
in camera 7iew are @*ic!l) iscare. (*t this wor!s onl) in s'ecial cases. >his 7isi+ilit)
c*lling is onl) o+5ect +aseA not 'ol)gon +ase.
%isible M Lo* can hie or show o+5ect. 6n) coe in o+5ectBs 'rogress e7ent gets e&ec*te
e7en i? Visi(le is 0alse.
GLScene beginner's guide, Jan Zizka, 2005
Page 2</36
3GLCamera
Lo* can thin! o? a camera as a 'oint in s'ace where the scene is 7iewe ?rom. ,amera has
'ositionA irection an *' 7ectors same as other o+5ects. Lo* cam mo7e an rotate camera aro*n
the scene. Sim'ler an more *se?*l metho o? orienting camera is to ma!e it loo! at another o+5ect.
6ssign the o+5ect to Taret 'ro'ert). >he camera will alwa)s 'oint to that o+5ect where7er it
mo7es.
Field90View is a 7al*e that changes camera lenses. Lower 7al*es ma!e the angle
o7erloo!ing the scene wier an higher 7al*es Goom to more ?oc*se area. 8a!e s*re )o* on%t *se
an) craG) 7al*es as the twiste 'ers'ecti7e can +e 7er) ist*r+ing ?or the *ser.
Lo* sho*l also !now something a+o*t c*lling 'lanes. Pol)gons that are too close or too
?ar ?rom the camera are not renere at all. Planes that i7ie the scene in 7isi+le an in7isi+le 'arts
are calle near an ?ar c*lling 'lanes. Lo* can set the 'osition o? these 'lanes with
2earFrustrum/ane an FarFrustrum/ane. Oormall) onl) the ?ar c*lling 'lane is change. >his
creates one small 'ro+lem. 6s the camera mo7es ?orwar o+5ects s*enl) s'ring into the 7iew as
the) get 'ast the ?ar c*lling 'lane. >o re*ce this *nwante e??ect ?og is o?ten *se. Lo* can ena+le
?og in TGLSceneViewer!Bu00er together with ?og o'tions. -og has start an en range. 6n) 'ol)gons
+etween the two +orers will change trans'arenc) with ?*ll o'acit) at start range an ?*ll
trans'arenc) at en range. 8a!e the en range o? the ?og same as ?ar c*lling range an color o? the
?og same as color o? scene 7iewer +ac!gro*n.
3GLLightSo*rce
-irst we sho*l e&'lain what lights can o in GLScene. Witho*t lights the scene wo*l +e
ar!. Lights ill*minate the scene. We can ha7e ma&im*m n*m+er o? eight lights. :7er) light e&ce't
o? 'arallel lights has a range limit how ?ar it shines. (e)on that istance it has no e??ect. -rom the
GLScene beginner's guide, Jan Zizka, 2005
Page 21/36
'osition o? the light to the ma&im*m istance the light slowl) iminishes. >his is calle light
atten*ation.
Lights o not cast shaows. I? )o* ha7e a s'here in ?ront o? the 'lane there will +e no
shaow on the 'laneA the light ra)s will seem to 'ass thro*gh the s'here witho*t an) inter?erence.
Lo* ha7e to *se other techni@*es to o+tain shaows. Lightma'sA F9shaows or shaow 7ol*mes ?or
instance.
>here are three t)'es o? lights=
1. /mni light M this is a light locate in one 'oint raiating light ra)s e@*all) to all
irections. Lo* can thing o? omni light as o? an electric +*l+ hanging on a ca+le ?reel)
in the air.
2. S#ot light M s'ot light shines a +eam or a cone o? light in one irection. Lo* can change
the with or angle o? the cone. 6 36<U cone wo*l +ecome an omni light. :&am'le o?
s'ot light is a torch light.
3. 0arallel light M *ni?orm mass o? 'arallel light ra)s with same irection shining ?rom a
'lane in in?inite istance ?orm a 'arallel light. Lo* can change 'osition o? 'arallel light
+*t it has no e??ect whatsoe7er. Parallel light is *s*all) *se to sim*late s*nshine.
3GLD*mmyC*be
GLScene also has hel'er o+5ects. Hel'er o+5ect is an in7isi+le o+5ect that is *se ?or
organiGing other o+5ects in gro*'sA to show istancesA irections an 'ositions in s'ace. Lo* sho*l
learn how to *se *mm) c*+e as m*ch as 'ossi+le +eca*se it can sim'li?) a lot o? things. D*mm)
c*+e can +e *se to store o+5ects as its chilren. I? )o* want to ?or e&am'le mo7e all o? the o+5ects
5*st mo7e the *mm) c*+e. I? )o* want to elete the o+5ects 5*st call DeleteChildren ?*nction o? the
*mm) c*+e. D*mm) c*+e can sim'li?) rotations. Lo* can create 5oints with *mm) c*+es where
each *mm) c*+e will ha7e restricte rotation onl) in one a&is.
Lo* can ma!e *mm) c*+e 7isi+le r*n time with Visi(leAt/untime 'ro'ert). D*mm)
c*+e is re'resente +) c*+e o*tline with otte lines.
)asic geometry
(asic geometr) o+5ects are sim'le o+5ects with har coe geometr). >he geometr) can +e
escri+e with mathematical ?orm*las. Lo* can change ini7i*al 'arameters o? the o+5ect +*t the
+asic sha'e will alwa)s sta) the same.
3GLS#rite
S'rite is a 2D image ma''e on a 'lane that alwa)s ?aces the camera. 3nli!e H3D s'rite
TGLSprite is 'lace in 3D worl an can +e mo7e closer or ?*rther ?rom the camera. I? the s'rite
gets too close to the camera it can create *nwante 7is*al errors. 6 trans'arent te&t*re is *s*all)
*se with s'rites. >he image can t*rn aro*n its center +) changing /otation 'ro'ert).
3GL0oints
Lo* can create arra) o? 'oints or 5*st one 'oint with this o+5ect. Points are ots in s'ace.
>he) ha7e Si=e 'arameter which etermines how man) 'i&els in iameter the 'oint will ha7e on
screen. I? the 'oint has siGe 3 it will +e re'resente +) 3 'i&els on screen whether the 'oint ma) +e
close to the camera or ?ar awa) ?rom the camera. Pers'ecti7e oes not a''l) here. Points can +e
ro*ne or s@*are an antialiase.
GLScene beginner's guide, Jan Zizka, 2005
Page 22/36
3GLLines
Lines are +asicall) 'oints connecte +) lines. Points are calle noes here. Lines ha7e
7idth with same 'ers'ecti7e restrictions li!e 'oints. Ooes can +e 7isi+le or not an can +e
re'resente +) c*+esA stars or s'heres with changea+le siGe.
3GL0lane
Plane is a single @*a. V*a is a 'ol)gon com'ose o? ?o*r 7ertices an two triangles.
Plane has 7idth an 5eiht 7al*es. Direction o? the 'lane is im'ortant. It 'oints in the irection o?
normal o? the 'lane. Oormal is a 7ector that tells *s which sie i? ?ront an which sie is +ac!. I? we
loo! at the 'lane ?rom the ?ront sie we can see itA i? we loo! ?rom the +ac! sie we can%t see it. Lo*
will +e a+le to see the 'lane onl) i? it%s irection will 'oint towars the camera.
.erte& shaing can sometimes create 'ro+lems with large 'lanes. I? eges o? the 'lane are
stretche o*t too ?ar ?rom the reach o? lights the 'lane will +ecome ar! as a whole.
3GL0olygon
C>0D0D
3GLC*be
,*+e is com'ose o? si& 'lanesA each 'lane can +e isa+le. ,*+e has Cu(e7idthA
Cu(e5eiht an Cu(eDepth 'ro'erties.
3GL,r*str*m
-r*str*m is a twiste c*+e with 7aria+le siGe o? to' an +ottom sies.
3GLS#here
/adius is the siGe o? the c*+eA Sements s'eci?ies how man) 'ol)gons will +e *se to
raw the c*+e an how smooth the c*r7at*re will +e.
3GLDisk
C>0D0D
3GLCone
C>0D0D
3GLCylin"er
C>0D0D
3GLDo"ecahe"ron
C>0D0D
3GLIcosahe"ron
C>0D0D
6"4ance" geometry
8ore com'licate than +asic geometr) +*t the escri'tion is the same.
GLScene beginner's guide, Jan Zizka, 2005
Page 23/36
3GL6nimate"S#rite
6nimate s'rite is +ase on s'rite onl) it is'la)s animate se@*ence. >he animate
se@*ence is store in single +itma'. >he +itma' is i7ie in rows an col*mns. >he gri contains
ini7i*al ?rames ?or the animation. >his techni@*e is great ?or smo!e or e&'losion e??ects +*t )o*
ha7e to ma!e the +itma' )o*rsel?.
3GL6rro!Line
6rrow line is a com+ination o? c)liner an cone. Lo* can change the with an height o?
+oth. It 'oints in Direction 7ector.
3GL6nn*l*s
6 hollow t*+e.
3GL5(tr*sionSoli"
C>0D0D
3GL2*lti0olygon
C>0D0D
3GL0i#e
C>0D0D
3GL.e4ol*tionSoli"
C>0D0D
3GL3or*s
C>0D0D
2esh ob$ects
8esh is a 'ool o? 'ol)gons e?ine with 7erticesA te&t*re coorinates an connecti7it)
in?ormation. Gro*' o? mesh o+5ects in common has same ?eat*re= it%s geometr) has to +e loae
?rom a ?ile. S*ch ?ile is *s*all) create +) 3D moeling 'rograms li!e 3DS 862A 8a)a or
8il!sha'e. S*''orte ?ormats are 3sA o+5A C>0D0D.
3GL6ctor
>his is an o+5ect )o* will *se i? )o* want geometr) that will change sha'e in time. Li7ing
creat*res are goo e&am'le. 6ctor has same +ase as TGLFreeForm +*t it is o'timiGe ?or mo7ing.
6nimations ha7e to +e loae to Animations. 6ctor nees AnimationControler com'onent. Lo* can
*se V*a!e m2 ?ormat. >his ?ormat contains set o? meshes in !e) ?rame 'ositions. S*+se@*ent
?rames are then inter'olate +etween the !e) 'ositions. >his ?ormat is ?ast an s*ita+le ?or low 'ol)
moels. 6nother ?ormat is Hal?li?e sm. It *ses s!eletal moel animation. 6ctor has s!eletal
str*ct*re with 7ertices attache to +ones. >he animation is escri+e +) recore angle 7al*es
+etween ini7i*al +ones in time. Lo* can com+ine i??erent animations at one time. -ollowing
animations can ha7e inter'olate transitions.
GLScene beginner's guide, Jan Zizka, 2005
Page 24/36
3GL,ree,orm
>his o+5ect is *se 7er) o?ten. It is ca'a+le o? loaing 7ario*s mesh ?ormats. >o +e a+le to
*se some ?ormat )o* ha7e to a a''ro'riate loaer *nit. -or e&am'le i? )o* want to *se 3s ?ormat
)o* ha7e to a GL-ile3DS *nit to *ses cla*se. ,all LoadFromFile ?*nction to loa the geometr).
>e&t*re coorinates are *s*all) incl*e in the ?ile. Some ?ormats s*''ort *sing o? m*lti'le te&t*res
?or one o+5ect. Lo* 5*st ha7e to set the te&t*res to the 1esh list. >o s*ccess?*ll) loa the te&t*re the
geometr) has to +e loae +e?ore te&t*re.
3GL2esh
C>0D0D
3GL3ile0lane
C>0D0D
3GL0ortal
C>0D0D
3GL3errain.en"erer
>o rener o*toors lansca'e *se terrain renerer. >he a7antage o? terrain renerer is
L0D o'timiGation. L0D ta!es care o? Le7el /? Detail in the scene. >errain is com'ose o? @*as.
V*as closer to the camera are enser with high etail. V*as ?*rther ?rom camera stretch across
larger areas loosing the etail. >his res*lts in less 'ol)gons to +e renere witho*t loosing 7is*al
@*alit). Data ?or terrain renerer is 'ro7ie +) HDS com'onents escri+e in #com'onents%
section. De?a*lt 6p 7ector o? terrain renerer is F a&is.
Gra#h;#lotting ob$ects
0+5ect in this gro*' are o?ten *se ?or scienti?ic 7is*aliGations. >heir sha'e is escri+e
with mathematical e@*ations.
3GL,lat3e(t
C>0D0D
3GLeight,iel"
C>0D0D
3GL1<ZGri"
Dis'la)s s'ace gri along 2AL an F a&is. Ini7i*al a&is can +e t*rne on an o??. SiGe
o? gri tiles can +e change.
0article systems
Particles are small s'rites in large n*m+ers generate accoring to same r*les. Particles
create s'ecial e??ects li!e ?ireA smo!eA e&'losionsA rain or snow.
3GL0articles
GLScene beginner's guide, Jan Zizka, 2005
Page 2"/36
C>0D0D
3GL0,1.en"erer
P-2 renerer is a hel'er o+5ect which has to 'resent in the scene so an) o+5ect can ha7e
;00ects 'ro'erl) ?*nctioning. >he s)stem wor!s li!e this= P-2 manager escri+es settings ?or the
e??ectA scene o+5ect has the e??ect in ;00ects list an P-2 renerer ta!es care a+o*t renering
'articles. >his seems to +e too com'licate +*t it is 7er) ?le&i+le.
5n4ironment ob$ects
() e?a*lt +ac!gro*n color o? the scene is light gra). >he color is e?ine +)
SceneViewer!Bu00er!BackGroundColor 'ro'ert). I? )o* want other +ac!gro*n than *ni?orm color
*se en7ironment o+5ect.
3GL5arthSkyDome
C>0D0D
3GLSkyDome
S!) ome creates graients o? color stri'es along horiGontal 'lane. Lo* can ma!e as man)
stri'es as )o* want. Lo* can a small ots in Stars list. Stars can e7en glitter.
3GLSky)o(
S!) +o& is a large c*+e with in7erte normals an si& te&t*res co7ering whole s!)line.
>he te&t*res m*st align each to another an create 'anoramic ill*sion.
7D ob$ects
H3D is eas 7' Dis'la). >hese o+5ects are renere as +itma's on screen. >heir
'osition is e?ine onl) +) 2 an L 7al*es. 2 is horiGontal an L is 7ertical 'osition o? H3D
o+5ect. >he origin C<A<D 'oint is *''er le?t corner. Lo* o not ha7e to care a+o*t renering orer o?
H3D o+5ects Jonl) among each otherKA the) alwa)s get renere last.
3GL7DS#rite
3ni7ersal H3D o+5ect. Dis'la)s +itma' on the screen. 3se material li+rar) to store the
te&t*re. >rans'arent te&t*res are o?ten *se. >e&t*re sho*l ha7e 'ower o? two imensions. Lo*
can rescale the siGe o? the o+5ect with its 7idth an 5eiht 7al*es. H3D s'rite can t*rn aro*n
center with /otation 'ro'ert).
3GL7D3e(t
>his H3D o+5ect is'la)s characters in its Te.t 'ro'ert). How is the te&t is'la)e is
etermine +) GLScene ?ont com'onent.
G7I ob$ects
G3I o+5ects are escri+e in TGLG64La+out section.
GLScene beginner's guide, Jan Zizka, 2005
Page 26/36
C>0D0D M G3I o+5ects
3GL.ootControl
3GL0o#*#2en*
3GL,orm
3GL0anel
3GL)*tton
3GLCheck)o(
3GL5"it
3GLLabel
3GL6"4ance"Label
3GLScroll)ar
3GLStringGri"
3GL)itma#Control
S#ecial ob$ects
>hese o+5ects on%t ?all in an) other categor).
3GLLens,lare
Lens ?lare is arti?act that is ca*se +) camera lenses loo!ing in strong light in real worl. >his
as more realism in )o*r scene. Lens ?lare is normall) 'ositione in same location as light so*rce.
/ings an strea!s are create when loo!ing straight at lens ?lare. (oth can +e change in n*m+erA
siGe an @*alit). Lens ?lare nat*rall) ?aes awa) when hien +ehin other o+5ect or o*t o? 7iew.
3GL3e(t*reLens,lare
C>0D0D
3GL2irror
C>0D0D
3GLSha"o!0lane
Shaow 'lane is a ?ast techni@*e how o rener )namic shaows. Shaows are 'ro5ecte on
a ?lat 'lane onl). Lo* ha7e to ena+le stencil +*??er o? scene 7iewer. 6ssign light so*rce that will +e
*se to generate shaow an shaowing o+5ect. >he shaowing o+5ect an all o? its chilren will
GLScene beginner's guide, Jan Zizka, 2005
Page 21/36
cast shaows on F shaows 'lane.
3GLSha"o!-ol*me
C>0D0D
3GLZSha"o!s
C>0D0D
3GL3e(t*re5mitter
C>0D0D
3GL0ro$ecte"3e(t*res
C>0D0D
3GL)l*r
C>0D0D
3GL3rail
C>0D0D
Doo"a" ob$ects
S'ecial categor)A !in o? more a7ance geometr).
3GLS#ace3e(t
>his o+5ect is'la)s te&t as three imensional letters. /eg*lar Wiows ?onts are *se. >e&t
can ha7e 7aria+le e'th or ;.trusion.
3GL3ea#ot
>ea'ot is an o+5ect well !nown ?rom 3DS 862 st*io.
3GL3ree
/ealisticall) loo!ing trees can +e create +) this o+5ect. >here is a lot o? settings which can
ma!e the tree loo! li!e an) t)'e o? tree. >ree is com'ose o? one main tr*n! with i7erging
+ranches an lea7es. O*m+er o? +ranches Jan 'ol)gonsK is set +) Depth 'ro'ert). Lea7es are
re'resente +) 'lanes co7ere with ?ront an +ac! te&t*res.
3GLWater0lane
>his o+5ect creates goo loo!ing realistic water.
/ther ob$ects
3GLDirect/#enGL
:&ec*te )o*r own 0'enGL commans. Lo* ha7e to !now 0'enGL s)nta& to *se this.
3GL0ro(y/b$ect
GLScene beginner's guide, Jan Zizka, 2005
Page 24/36
In cases when )o* ha7e a lot o? same o+5ectsA es'eciall) TGLFreeFormsA it is goo 'ractice to
*se 'ro&) o+5ects. Lo* will gain a lot in 'er?ormance. Pro&) o+5ect re?ers to 1aster o+5ect.
Geometr) o? master o+5ect is renere in 'lace o? the 'ro&) o+5ect. Pro&) o+5ect has its own
'ositionA irection an scale. >he geometr) is altere accoringl).
3GL2*lti0ro(y
8*lti 'ro&) o+5ect is an a7ance 7ersion o? 'ro&) o+5ect. It has more masters that are chosen
accoring to istance ?rom camera. >his techni@*e is *se with set o? o+5ects with i??erent n*m+er
o? 'ol)gons +*t resem+ling each other. Low etail o+5ects are is'la)e in istance an high etail
o+5ects are is'la)e close to the camera.
3GL.en"er0oint
C>0D0D
3GLIm#osterS#rite
Im'osters are escri+e in TGLStatic4mposterBuilder section. Im'oster s'rite is the o+5ect
that is renere in the scene.
3GL/#enGL,ee"back
C>0D0D
GLScene beginner's guide, Jan Zizka, 2005
Page 2;/36
.*ntime ob$ect creation
3ntil now we s'o!e onl) a+o*t esign time ?*nctions an ?eat*res o? GLScene. 6s )o* will
learn more a+o*t GLScene )o* will ?in o*t that creating o+5ects r*ntime is ine7ita+le. ,om'onents
are create the *s*al Del'hi wa) with Create irecti7e. (*t scene o+5ects are create i??erentl).
>hose o+5ects ha7e to +e registere in the scene clearl) sa)ing where the o+5ects 'osition in the
scene hierarch) is.
I? we want ?or e&am'le create a s'here name 1+GLSphere as a chil o? GLCu(e1 the correct
coe is li!e this=
var
MyGLSphere: TGLSphere
begin
MyGLSphere := TGLSphere(GLCube1.AddNewChild(TGLSphere));
end;
>his wa) the new s'here will +e 'lace correctl) in the scene as a last chil o? GLCu(e1. I?
)o* want to ma!e it a ?irst chil o? GLCu(e1 call Add2ewChildFirst instea. 6n) o+5ect can +e
mo7e in the scene hierarch) with 1o8e6p an 1o8eDown ?*nctions or +) changing Parent
'ro'ert). >o estro) the o+5ect call 1+GLSphere!Free ?*nction.
Creating ne! class
Lo* will also ?in 7er) *se?*l to inherit )o*r own classes ?rom e&isting ones. >his 'rocess has
same r*les li!e an) other Del'hi o+5ect. Let%s ma!e a new class ?or o*r s'inning c*+e.
type
TGLSpinningCube = class(TGLCube)
private
FSpinSpeed: single;
published
property SpinSpeed read FSpinSpeed write FSpinSpeed;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure DoProgress(const progressTime : TProgressTimes); override;
end;
constructor TGLSpinningCube.Create(AOwner : TComponent);
begin
inherited;
FSpinSpeed := 1000;
end;
destructor TGLSpinningCube.Destroy;
begin
inherited;
end;
procedure TGLSpinningCube.DoProgress(const progressTime : TProgressTimes);
begin
GLScene beginner's guide, Jan Zizka, 2005
Page 3</36
inherited;
TurnAngle := TurnAngle + progressTime.DeltaTime * FSpinSpeed;
end;
>he on 'rogress e7ent is i??erent at this le7el. ProressTime is *se to access DeltaTime.
Lo* also ha7e to call inherited irecti7e otherwise the o+5ect wo*l not 'rogress at all. >o create
o+5ect e?ine +) this class )o* wo*l *se techni@*e escri+e earlier in this cha'ter or register the
class in GLScene an a it with hel' o? GLScene eitor.
GLScene beginner's guide, Jan Zizka, 2005
Page 31/36
Case st*"y= +D 3etris
In this cha'ter I am going to gi7e )o* m) ieas a+o*t ma!ing a sim'le >etris game with
GLScene. I am not going to write onl) some coeA I will mainl) ?oc*s on str*ct*re an esign o? the
game. I am going to !ee' it as sim'le as 'ossi+le. 6?ter all this is +eginner%s g*ie. I am s*re man)
'eo'le wo*l o m*ch +etter 3D >etris so on%t ta!e m) wor that this is the +est wa) how to ma!e
a 3D >etris game.
I on%t ha7e wor!ing coe ?or the game. >his is a !in o? mini game esign oc*ment. I
wo*l +e intereste i? an)one ma!es the game real. Please sen it o7er to me an I will '*+lish it
with this +oo!.
Design
>o ma!e it *ltra9sim'le we are going to create a clone o? ol >etris. >he thir imension here
is going to a onl) a little +it o? e)e can). It is act*all) going to +e #2."D >etris%. ,amera will
loo! at the scene ?rom an interesting angle an 'ers'ecti7e. >hat%s all. >he game will ta!e 'lace in
two imensional gri 5*st li!e ol >etris. 0nl) the +loc!s will +e mae *' o? c*+es instea o?
s@*ares.
>here will +e no men*s. >he game will start right a?ter the 'rogram is la*nche or it will wait
?or the *ser to 'ress a !e). D*ring game a la+el will show n*m+er o? achie7e 'oints. 6?ter the
game is ?inishe a message winow will show in?ormation that the game is o7er an 'la)er%s score.
>he 'rogram will then terminate.
In classical >etris the n*m+er o? t)'es an sha'e o? +loc!s is e?ine. We are going to
ranoml) generate sha'e o? the +loc! on its creation. >he +loc! will ha7e constant escening
s'ee. >he 'la)er can mo7e with them le?t an right an rotate them cloc!wise an co*nter9
cloc!wise. In'*t will +e hanle +) !e)+oar.
Str*ct*re
We are going to nee TGLSceneA TGLSceneViewer: TGLCadencer an
TGL7indowsBitmapFont com'onents. >he 'la)ing ?iel will +e 11 *nits wie on 2 a&is an 21
*nits high on F a&is. We will 'lace the camera on negati7e F a&is o7erloo!ing the whole scene ?rom
to' right sie. 0ne TGLPlane will ?orm the gro*n at 'osition C<A<A9<."D an two tall TGLCu(es
will +e staning on sies to set +orers. 6t 'ositions C96A<A1<D an C6A<A1<DA 1< *nits high. 6ll o?
these o+5ects together with nice camera 'osition can +e mae esign time. Don%t ?orget to a light
to the scene. Lo* can 'lace it where7er )o* li!e.
We are going to *se o*r game logic ?or etecting collisions o? the ?alling c*+es. >he 'la)ing
?iel will +e re'resente +) arra) o? singles=
var
FloodLevels: array[-5..5] of single;
:ach mem+er o? this ?iel re'resents how high the stac! o? +o&es reaches *ring the 'la).
:7er) time the +loc! will +e sec*rel) 'lace in ?inal 'osition corres'oning ?iel will +e set to new
height le7el. >his will ha''en onl) a8ter the +loc! will rest at the +ottomA not *ring his ?all. >here
are no c*+es at the +eginning o? the game so initial 7al*es are Gero. .al*es store in FloodLe8els
GLScene beginner's guide, Jan Zizka, 2005
Page 32/36
escri+e centers o? c*+es. 6ct*al eges o? c*+es will +e <." *nits higher +*t it will +e consiere in
collision etection.
>o etect *ser in'*t we will *se 4s?e+Down ?*nction containe in ?e+(oard *nit. >his is
sim'le metho how to ca't*re !e)+oar in'*t. We will e?ine ?i7e 'ossi+le *ser actions=
T3DTInput = (inpNone,inpMoveL,inpMoveR,inpRotateL,inpRotateR);
var
UserInput: T3DTInput;
Ie)+oar stat*s will +e ca't*re in caencer 'rogress e7ent an store in glo+al 7aria+le
6ser4nput.
UserInput:=inpNone;
if IsKeyDown(VK_LEFT) then UserInput:=inpMoveL;
...
I wo*l li!e to sa) a ?ew wors a+o*t ca't*ring !e)+oar an mo*se in'*t. 6lwa)s *se
necessar) minim*m o? coe to ca't*re the controller in'*t in glo+al 7aria+le. :s'eciall)
9n1ouse1o8e e7ent can ca*se +ig slowown i? )o* write too m*ch coe in it. Winows consier
mo*se mo7ements ?irst 'riorit) an tr) to e&ec*te its coe +e?ore other 'roce*res. I? )o* write
com'licate coe in this e7ent the s)stem +ecomes ?looe with this coe tr)ing to e&ec*te it with
the smallest mo*se mo7ements. Oot eno*gh com'*ting 'ower remains ?or caencer 'rogress. 6ll
)o* sho*l write in 9n1ouse1o8e is 1ouseX "# X% 1ouse& "# &%
In?ormation a+o*t c*rrent score is *'ate e7er) caencer ste' with TGL56DTe.t o+5ect
'lace in *''er le?t corner.
3+D3)lock class
>he core o? the 'rogram is going to +e o*r new class eri7e ?rom >GLD*mm),*+e. >his
class will re'resent ini7i*al +loc!s. >he *mm) c*+e will ta!e care o? mo7ements an rotations
o? the whole +loc!. It will ha7e TGLCu(e chilren as +o&es in the +loc!. :ach c*+e will com'are
its F 'osition with FloodLe8els to etect collisions. We are going to *se /ound ?*nction to sna' the
c*+es 'osition on 2 gri.
>he +loc! will +e initiall) create at 'osition C<A<A<D. 0ne central >GL,*+e will +e ae to
e7er) +loc! again at 'osition C<A<A<D. /anom n*m+er o? c*+es will +e ae in ?o*r irections. >he
+loc! will ?orm a crossA L9sha'e or line. -i7e c*+es in a row ma&im*m. ,*+es sho*l +e <.;" *nits
in siGe an 'ositione at C1A<A<DA C2A<A<DA C<A<A1DA C<A<A2DA C91A<A<D an so on. 6ll c*+es will ha7e L
'osition < at all times. 6?ter all c*+es are create the +loc! is re'ositione to starting 'osition well
a+o7e 'la)ing ?iel with ranom 2 'osition. (oolean 7al*e calle Acti8e will re'resent stat*s o? the
+loc!. 6t +eginning +loc! will +e acti7e JesceningKA once it will lan on gro*n or other +loc!s
we will set Acti8e to ?alse.
I? the c*+e is acti7e it is mo7e tin) +it own the F a&is *ring +loc!%s 'rogress e7ent=
Position!' "# Position!' > deltaTime - speed. >hen we chec! ?or collisions. We ha7e to 'rocess all
chilren an com'are their a+sol*te 'ositions with +oth sies J2P9" an 2Q"K an +ottom JFP<K o?
the 'la)ing ?iel. We also ha7e to chec! against other +loc!s alrea) in the 'la)ing ?iel=
var
absPos: TVector;
GLScene beginner's guide, Jan Zizka, 2005
Page 33/36
setVector(absPos, Children[i].AbsolutePosition);
if (absPos[2] 1) < FloodLevels[Round(absPos[0])] then
>his coe ?ragment etects i? the c*+e iterate +) Children@iA is lower then 7al*e store in
FloodLe8els ?iel. 6+sol*te 'osition o? the c*+e is store in a(sPos 7aria+le. >his is im'ortant
+eca*se a+sol*te 'osition is real 'osition in worl coorinate s)stem while Position is 'osition
relati7e to the 'arent. Which mem+er o? FloodLe8els ?iel is to +e com'are against is etermine
+) ro*ning a+sol*te 2 'osition o? the c*+e. I? the c*+e rests on gro*n or other c*+eA Acti8e
'ro'ert) is set to ?alseA we a 'oints to score an 'rogram is in?orme that another c*+e can +e
create.
>o res'on to *ser actions we chec! which TBDT4nput stat*s is acti7e an o the tas!=
case Form1.UserInput of
inpMoveL: Slide(-1);
inpMoveR: Slide(1);
inpRotateL: Pitch(-90);
inpRotateR: Pitch(90);
end;
Slide an Pitch ?*nctions are GLScene ?*nctions to mo7e an rotate o+5ects. Oow we sho*l
chec! ?or collisions again an *no the mo7ement or rotation i? the new 'osition o? +loc! is not
7ali.
>he last thing is to etect i? the game is o7er. >his can +e one in caencer 'rogress e7ent.
We can sim'l) chec! FloodLe8els i? an) 7al*e is o7er 2<. I? it is so isa+le caencer an is'la)
massage with n*m+er o? 'oints achie7e an game o7er in?ormation.
ome!ork
>his is it. With some twea!ing that is all )o* nee to ma!e >etris game. I chose this e&am'le
to show )o* how 'ower?*l GLScene is. Oot onl) that )o* can set *' all game en7ironment esign
time. Lo* ta!e a7antage o? ?*nctions that mo7e an rotate o+5ects together with their chilren. >he
coe to co') this +eha7io*r wo*l +e @*ite com'le&.
In the last 'aragra'h I will gi7e )o* more ieas to thin! a+o*t to ma!e the game +etter.
8a!e some inter?ace. >he 'rogram nees men*s es'eratel). 3se stanar Del'hi or G3I
com'onents.
Let the game +e restarta+le with le7els an increasing i??ic*lt) M game s'ee.
8a!e real collisions with collision manager an let the +loc!s rotate an slie smoothl).
>hat wo*l re@*ire more a7ance sol*tions= can the +loc! collie while rotating?
6 so*n an m*sic. Pla)er sho*l hear so*n ?ee+ac! ?or his actions.
8a!e it c*stomiGa+le M gra'hicsA so*nA !e)+oar o'tionsA siGe o? 'la)ing ?iel an +loc!s.
8a!e score ta+le with +est res*lts together with 'la)er%s name that is sa7e.
8a!e it loo! 'rettier. P*t i??erent te&t*res on +loc!s. 6 'article e??ectsA s!) +o&A lens
?lare. >he game can ta!e 'lace in a can)on with +rige a+o7e. Passing cars or trains wo*l
ro' +loc!s. 0r Iing9Iong on to' o? two s!)scra'ers can throw the +loc!s own. >he limit
is onl) )o*r imagination.
6 the thir imension to the game 'la). (*t +e care?*l$ 8an) 3D rema!es o? ol 2D
games were not s*ccess?*l +eca*se the) +ecame too com'licate an i??ic*lt to 'la). Lo*
sho*l thing care?*ll) a+o*t camera controls. >he game can 'a*se *ring camera
GLScene beginner's guide, Jan Zizka, 2005
Page 34/36
re'ositioning. 8a!e some +loc!s trans'arent. 6 TGLX&'Grid ?or easier orientation.
Write narrati7e stor) ?or >etris M no! that is a challenge&
Let me gi7e )o* one last a7ice. >here is more to 'rogramming than 5*st clean coe. Don%t loo!
onl) ?or technical oc*mentation li!e this one to ma!e )o*r 'rograms +etter. >here is a lot o?
articles a+o*t 'rogramming theor) other than technical on Internet. 3sers now are choosier. Lo*r
a''lication has to +e more *ser ?rienl) than other a''lications o? same !in. :7en i? )o* are
ma!ing ?reeware )o* still want *sers to +e ha'') a+o*t it. Lo* sho*l gi7e same time to esigning
an e+*gging as to 'rogramming itsel?. It 'a)s o?$
GLScene beginner's guide, Jan Zizka, 2005
Page 3"/36
Links
www.glscene.org GLScene home 'age
htt'=//glscenehel'.so*rce?orge.net WIII hel' 'age
www.ca'era7en.co.Ga Hel' oc*mentation an emo 'rograms
www.o'engl.org 0??icial 0'enGL we+ site
news=//?or*ms.tal!to.net/glscene.general GLScene ?or*m
news=//?or*ms.tal!to.net/glscene.s*''ort GLScene ?or*m Jnot too acti7eK
GLScene is so s*ccess?*l mainl) +eca*se o? its great comm*nit). 8an) 'eo'le ha7e
contri+*te to e7elo'ment an s*''ort. I? )o* ha7e an) reasona+le @*estionA go ahea an as! at
GLScene ?or*m. I? the @*estion is not st*'i )o* will get @*ali?ie answer in short time.
>his oc*ment was ownloae ?rom Jloo! ?or an) *'atesK=
www.rGiG!a.aslin!.cG/glsceneg*ie.html
Last *'ate=
E*l) 2<
th
A 2<<"
GLScene beginner's guide, Jan Zizka, 2005
Page 36/36
Concl*sion
I? )o*%7e rea this ?ar )o* sho*l ha7e +asic *nerstaning how is GLScene organiGeA what
it can +e *se ?orA what are its 'arts an some 'rogramming techni@*es s'eci?ic ?or GLScene. Oow I
s*ggest )o* go +ac! to GLScene emos. I? )o* ?aile to *nerstan what is going on +e?oreA )o*
sho*l ha7e the iea now. It is sometimes i??ic*lt to ?in the ?*nction or 'roce*re that )o* are
loo!ing ?or among the m)ria o? GLScene ?eat*res. (*t all ?*nctions ha7e reasona+le names an
soon )o* will ?in those )o* nee ?or )o*r '*r'ose. 6?ter )o* are s*re )o* can ?ollow the emos
)o* can start to create )o*r own a''lications.
Ha'') coingA
Ean FiG!a.
GLScene beginner's guide, Jan Zizka, 2005

Вам также может понравиться