Des|gn and Imp|ementat|on of Graph|cs
App||cat|ons us|ng Cb[ectŴCr|ented
1echn|ques |n C++
ZC?AŦ AŦ 8lZvl
8oll noŦ 130
Introduct|on to C++
We use C++ Lo creaLe graphlcal and numerlcal
bulldlng blocks whlch can Lhen be assembled
Lo form porLableţ flexlble and cosLŴeffecLlve
soluLlons Lo a number of realŴllfe problems
where graphlcs plays an essenLlal roleŦ
W C++ ls becomlng Lhe language of cholce for many appllcaLlonsŦ
W Cne of Lhe reasons for lLs success ls LhaL lL ls compaLlble wlLh CŦ
W 1hls means LhaL new appllcaLlons whlch need Lo be wrlLLen ln C++
can use oldŴsLyle C llbrarles and sofLware wlLhouL havlng Lo do a
W ln facLţ C++ can be used as a ƌbeLLer Cƌ by uslng Lhe lmproved synLax
sLyle and Lype checklng feaLuresŦ 8uL C++ can also be used Lo wrlLe
ob[ecLŴorlenLed appllcaLlonsţ Lhus offerlng programmers and
organlsaLlons many advanLagesţ such asť
lmproved sofLware quallLyŦ
ShorLer lead LlmesŦ
More reusable sofLwareŦ
SaLlsfled cusLomersŦ
C++ AppllcaLlon
W MosL graphlcs appllcaLlons aL Lhe presenL Llme
are wrlLLen ln C (see for exampleţ Lhe serles of
books ln Lhe Craphlcs Cems serles from
Academlc Þress) whlle C++ ls slowly beglnnlng
Lo make lnroads ln cerLaln placesŦ
W We shall see a gradual LranslLlon Lo C++ ln Lhe
comlng years as Lhe developer communlLy
becomes acqualnLed wlLh Lhe ob[ecLŴorlenLed
W Many of Lhe successful graphlcs and CAu packages ln Lhe
markeLplace daLe from Lhe 1970ƌs and 1980ƌsŦ
W MosL of Lhese were developed ln procedural languages
such as Cţ Þascal or lorLranŦ
W 1he resulLlng producLs were dlfflculL Lo exLend and Lo
malnLalnŤ furLhermoreţ lL Look a loL of efforL Lo exLracL and
reuse parLs of such sysLemsţ malnly due Lo Lhe facL LhaL
poLenLlally reusable deslgns and code were lnLerwoven
wlLh Lhe conLexLs ln whlch Lhe sofLware was Lo operaLeŦ
W 1he only alLernaLlve Lo copylng Lhe code and edlLlng lL Lo
sulL Lhe new slLuaLlon was Lo do a compleLe rewrlLeŦ
W 1hls resulLed ln much code dupllcaLlonţ longer lead Llmes
and mlssed opporLunlLlesŦ
AdvenL of C++
W We can creaLe appllcaLlons whlch can be easlly
cusLomlzedţ exLended and reused ln changlng worldŦ
W CusLomers are demandlng appllcaLlons whlch be easlly
plugged lnLo oLher appllcaLlonsŦ
W ln oLher wordsţ no longer wlll we have Lo deal wlLh
large and lnflexlble programs buL lnsLead we shall be
able Lo buy sofLware componenLs from dlfferenL
vendors and where we can comblne Lhese componenLs
Lo creaLe appllcaLlons whlch sulL our own needsŦ(due
Lo Lhe reusablllLy of C++ classes)
Þrepare for LranslLlon
W CrganlsaLlons wlshlng Lo Lake advanLage of
Lhe beneflLs of ob[ecLŴorlenLed Lechnology
should be warned howeverţ LhaL Lhey musL
prepare Lhemselves well for Lhe LranslLlon
from a procedural frame of mlnd Lo one where
concepLs and domaln knowledge are Lhe mosL
lmporLanL parLs of Lhe sofLware llfecycleŦ
Þroblems faced by CAu
Cost ţ neutra| f||e formatţ D|rect trans|ators
W A Lyplcal slngleŴuser sLaLlon could cosL anyLhlng from 0Ŧ3 mllllon dollars Lo 4 mllllon
dollarsŦ lnLerfaces beLween Lhe CAu sofLware and oLher appllcaLlons (such as Lhose
for manufacLurlng (CAM) and flnlLe elemenL sLress programs (lLM)) were wrlLLen on a
oneŴoff baslsŦ
W 1hls meanL LhaL proprleLary producL daLa exchange LranslaLors needed
Lo be wrlLLen beLween each palr of appllcaLlonsŦ 1he maln problem wlLh Lhls Lype of
LranslaLor ls LhaL ln a sysLem of n appllcaLlons n(nŴ1) lnLerface programs are neededŦ
W lurLhermoreţ changes ln Lhe daLa formaL of one appllcaLlon (new daLa Lypes
addedţ new sLrucLure eLc) lmplled LhaL all Lhe lnLerfaces uslng LhaL appllcaLlon needed
Lo be modlfled and reLesLedŦ
W 1he alLernaLlve Lo Lhls adŴhoc sLraLegy ls Lo creaLe a publlc domaln neuLral
lnLermedlaLe formaLŦ
LgŦ lCLSţ vuAţ SL1
Þroblem 2 Ŷ vlrLual Memory m/c
WlLh Lhe advenL of vlrLual memory machlnes (such
as Þrlme and vAx sysLems) Lhe slLuaLlon dld noL
lmprove very much and englneerlng operaLlons sLlll
had Lo wrlLe and malnLaln Lhese lnLerfacesŦ 1he
advenL of sulLable neLwork proLocols such as
uLCneL and 1CÞ/lÞ only meanL LhaL daLa could be
copled from one machlne Lo anoLher one buL Lhe
problem of lnLeroperablllLy beLween appllcaLlons
sLlll remalnedŦ
W Many companles are beglnnlng Lo reallze LhaL CCÞ offers many
advanLages for sofLware developmenL for CAuŦ ConLrary Lo popular
bellefţ wrlLlng sofLware for CAu ls dlfflculL because aLLenLlon needs
Lo be pald Lo a number of areas such as Lhe consLrucLlon and
manlpulaLlon of geomeLrlc and nonŴgeomeLrlc ob[ecLsţ Lhelr
represenLaLlon and user lnLeracLlons wlLh Lhe sysLemŦ lurLhermoreţ
complex maLhemaLlcal algorlLhms need Lo be deslgned and
lnLegraLed lnLo Lhe appllcaLlonŦ lL ls lmporLanL Lo separaLe Lhe
appllcaLlon from lLs envlronmenL (whlch ls volaLlle)Ŧ 1he maln
volaLlle elemenLs ln an appllcaLlon are Lyplcallyť
1he user lnLerfaces (Wlndowsţ uCSţ MoLlf)
1he underlylng daLabase (8u8MSţ Cu8MSţ proprleLary)
1he algorlLhms and daLa sLrucLures belng used ln Lhe appllcaLlonŦ
W 1he reason LhaL we wlsh Lo have Lhls separaLlon of concerns ls LhaL
appllcaLlons need Lo work under dlfferenL Lypes of hardware and
sofLware envlronmenLsŦ
W ln order Lo achleve Lhese endsţ we apply Lhe MvC paradlgm or one
of lLs varlaLlonsŦ
W 1hls can be done ln C++ by uslng Lhe soŴcalled mulLlple
polymorphlsm prlnclple or by Lhe creaLlon of absLracL daLa vlews
and absLracL daLa ob[ecLsŦ
W A number of ma[or CAu vendors are already worklng on ob[ecLŴ
orlenLed verslons of Lhelr producLsŦ lor exampleţ AuLouesk has
released lLs ob[ecLŴorlenLed verslon of Lhe popular CAu sysLem
AuLoCAu and lL ls be posslble Lo creaLe drawlng wlLh lnŴbullL
ƌlnLelllgenceƌ whlch ls made posslble by Lhe facL LhaL lLs CAu
drawlngs conLaln embedded ob[ecLsŦ
W 1he maln advanLages of uslng C++ as opposed Lo C or AuLoLlsp lle ln
Lhe supporL lL offers for wrlLlng classesŦ Cnce a class ls wrlLLen lL can
be used ln many dlfferenL appllcaLlons wlLhouL changeŦ ln oLher
wordsţ we do noL have Lo relnvenL Lhe wheel by copylng chunks of
codeţ modlfylng lL and Lhen reLesLlngŦ 1he classes can be used
wlLhouL any change whaLsoever! lurLhermoreţ code wrlLLen ln C++
Lends Lo be more easlly malnLalned Lhan code whlch ls wrlLLen ln
nonŴob[ecL orlenLed languagesŦ
C++ ls fasL becomlng Lhe de facLo sLandard programmlng languageŦ
1he compller runs on many dlfferenL hardware plaLforms and hlghŴ
schools and unlverslLles are Lralnlng sLudenLs ln lLs useŦ ln Lhls sense
we can expecL a good supply of wellŴLralned sofLware englneers and
programmers who are able Lo wrlLe C++ appllcaLlons for AuLoCAuŦ
MlgraLlng Lo C++
W C++ offers many advanLages over C and AuLoLlspŦ
Powever all Lhese advanLages come aL a prlceŦ
W lL Lakes a long Llme (2years) Lo geL a hang of C++Ŧ
W 1hls ls becauseţ ln splLe of slmllar synLaxţ programmlng
ln C++ lnvolves a dlfferenL way of Lhlnklng abouL
problem solvlngŦ
W ln order Lo use C++ effecLlvelyţ Lhe followlng mlgraLlon
plan ls proposedť
Learn ob[ecL orlenLed concepLs
Learn Lhe synLax of C or C++
Choose a nonŴcrlLlcal plloL pro[ecL Lo be developed ln C++
use ouLslde help ln Lhe early sLages of Lhe pro[ecLŦ
W C++ ls becomlng Lhe language of cholce for
graphlcs appllcaLlons and we dlscussed some of
Lhe Lrends Laklng place ln Lhls fleldŦ We shall see
Lhe emergence of graphlcs appllcaLlons whlch
conslsL of pluggable componenLs and whlch can
easlly be cusLomlsed Lo sulL speclflc slLuaLlonsŦ ln
Lhls way we hope Lo see Lhe lndusLry maLurlng
from one ln whlch monollLhlc and lnflexlble
sysLems wlll gradually be replaced by
lnLeroperable componenL LechnologyŦ
1nANk ¥CU

++    I -  . .


. .

° n°.

++ J ¾ .

++n f –f½nff° °¯ nf  °– n¾nnf° ° f¾¾ ¯   €¯½f  €   f° n¾ €€ n  ¾°¾f°¯ € f € ½  ¯¾   –f½n¾½f¾f° ¾¾ °f W – .



@I W .

++¾ n¯°– f°–f– €nn €¯f°f½½nf°¾  W ° €  f¾°¾€¾¾nn ¾¾¾f¾n¯½f  .

 W @¾¯ f°¾f° f½½nf°¾n°   °°.

++ nf°¾  ¾ .

 f ¾f° ¾€f f°– f    W °€fn .

++nf° ¾ f¾f  .

 ¾°– ¯½ ¾°f ¾ f° ½ n n°–€ f ¾  .

++nf°f¾ ¾    © n  ° f½½nf°¾ ¾€€ °–½–f¯¯ ¾f°  –f°¾f°¾¯f°f f°f– ¾ ¾nf¾ ¯½ ¾€f f   f ¯ ¾ .  ¾f  ¾€f f¾€ n¾¯ ¾ .


++½½nf° W .¾–f½n¾f½½nf°¾f ½ ¾ °¯  f  °°.

%¾ € f¯½  ¾  ¾€ ¾° f½n¾ ¯¾¾  ¾€¯ nf ¯n9 ¾¾% .

++¾¾ –°°°– ¯f °f ¾°n f°½fn ¾  W J ¾f¾ f–f ff°¾°.

++°  n¯°– f¾f¾   ½ n¯¯° n¯ ¾fnf°   © n  °  ½ff –¯ .


f°€ ¾nn ¾¾€–f½n¾f° .°° W .

¾€ ¾     ½ °½n ff°–f– ¾ ¾nf¾.½fnf– ¾°  ¯f ½fn  f €¯  ¾f°  ¾  W .

9f¾nff°  W @  ¾°–½ n¾   €€n  ° f°  ¯f°f° € ¯ f€ €€ fnf°   ¾ ½f¾€¾n¾¾ ¯¾ ¯f°   €fnf ½ °f ¾f   ¾–°¾f° n   °  °  n° ¾°n ¾€f f¾½ f  W @ °f °f n½°– n f°  °– ¾ ° ¾f°f¾ fn¯½     W @¾ ¾ °¯nn  ½nf° °–  f ¯ ¾ f° ¯¾¾ ½½° ¾ .


++ W J nf°n f f½½nf°¾nnf°  f¾ n¾¯   ° f°  ¾ °nf°–°– W .

¾¯ ¾f  ¯f° °–f½½nf°¾n  f¾ ½–– ° f½½nf°¾ W °  ¾ °°–  f  f f– f° °€   ½–f¯¾ °¾ f  ¾f  f   ¾€f n¯½° °¾€¯ €€  °  ° ¾f°    nf°n¯ °  ¾ n¯½° °¾ n f f½½nf°¾n¾°° ¾ %     ¾f €.

++nf¾¾ ¾% .

9 ½f €f°¾° W –f°¾f°¾¾°–f f f°f– €   ° €¾€ © n  °  n°– ¾  f°    f ¯¾ ½ ½f  ¯¾  ¾ € f°¾° €¯f½n f€f¯ €¯° °    n°n ½¾f°  ¯f°° – f  ¯¾ ¯½f°½f¾€ ¾€f € nn .

9  ¯¾€fn  .


¾ ° f€ €¯f  nf°¾f¾ W ½nf¾°– ¾ ¾f°n n¾f°°–€¯ ¯° f¾¯° f¾ ° €fn ¾  ° .

¾€f f°  f½½nf°¾%¾nf¾¾  €¯f°€fn°–%.

.%f° €°   ¯ °¾ ¾¾½–f¯¾%.%%   °°f ° €€ f¾¾ W @¾¯ f°f½½ f½ n ff nf°– f°¾f¾°    °  ° fn½f€f½½nf°¾ @ ¯f°½  ¯¾½ € f°¾f¾f°f¾¾ ¯€°f½½nf°¾°%° %° €fn ½–f¯¾f °  W  ¯ nf°– ¾°  ff€¯f€° f½½nf°%°  ff½ ¾ f ° ¾n  n%¯½ ff ° €fn ¾¾°–ff½½nf°°  ¯ € f°   ¾  W @ f °f ¾f n¾f –¾n f f½ n ¯f°° f ° ¯ f €¯f –  I @ .


°° 9  ¯ If. ¯¯$n J f  °€f¯ ¯¯fn° ¾%¾n f¾9¯ f° IO¾¾ ¯¾% ¾f°  ° ¯½  ¯nf°  °–° °–½ f°¾¾ f  f° ¯f°f° ¾ ° €fn ¾ @  f  °€¾f  ° ½n¾¾nf¾ .

°  f° @.

9$9°¯ f°f ffn   n½ €¯° ¯fn° f° °    ½  ¯€° ½ f   °f½½nf°¾ ¾ ¯f° .


f°n¯½f° ¾f  –°°°– f f9€€ ¾¯f° f f°f– ¾€¾€f   ½¯ °€.°° W .


°f½½f  € °–¾€f €.

 ½½ f% @ f–¯¾f°  ff¾n ¾ °–¾ ° f½½nf° .€% @ ° °– ff f¾ % .¾ €€n nf¾ f °°° ¾  ½f f°¯ €f f¾¾nf¾ n°¾n°f°  ¯f°½f°€– ¯ nf° °° – ¯ n © n¾    ½ ¾ °f°f° ¾ ° fn°¾ ¾¾ ¯  ¯  n¯½ ¯f ¯fnff–¯¾°   ¾–° f°  ° –f ° f½½nf° ¾¯½f°¾ ½ff   f½½nf°€¯¾ °°¯ °%n¾f % @ ¯f° f   ¯ °¾°f°f½½nf°f ½nf @ ¾ ° €fn ¾%J° ¾  .  .


°° W @  f¾°f ¾f ¾¾ ½ff°€n°n °¾¾f f½½nf°¾° °  €€  °½ ¾€f f f°  ¾€f  °°¯ °¾ W ° fn   ¾  ° ¾  f½½ .I.

½ff –¯°  €¾ff°¾  W @¾nf°  ° °.

++ ¾°– ¾ nf ¯½  ½¯½¾¯½°n½   n f°€f ¾fn ff ¾ f° f ¾fn ff © n¾  W °¯ €¯f©.

 ° ¾f f f °–° © n  °  ¾°¾€ ½ n¾  f¯½  ¾ f¾   f¾ ¾ © n  °  ¾°€ ½½f.

¾¾ ¯ .

f° ¾ ½¾¾  n f  f°–°  ° – °n n¾¯f ½¾¾    €fnf¾.

 f°–¾n°f° ¯  © n¾ .


++ W @ ¯f°f f°f– ¾€¾°–.

++f¾½½¾ .

¾½  °  ¾½½€€ ¾€°–nf¾¾ ¾ °n fnf¾¾¾ °nf° ¾ °¯f° €€  °f½½nf°¾nf°– °   ¾   °f  ° °   n½°–n°¾€ n ¯ €°–f°  °  ¾°– @ nf¾¾ ¾nf° ¾  f°nf°– f¾  " ¯ n  °°.

++  ° ¾ ¯  f¾¯f°f° f°n n¾ °° °°  © n ° f°–f– ¾ .

++¾€f¾ n¯°–  €fn¾f° f ½–f¯¯°–f°–f–  @ n¯½ °¾°¯f° €€  °f f ½f€¯¾f° – ¾n¾f° ° ¾ ¾f f°°–¾ °¾°¾¾ °¾¾ °¾   nf° ½ nf– ¾½½€  f° ¾€f  °–° ¾f°  ½–f¯¯ ¾f f   .




++ W .

++€€ ¾¯f°f f°f– ¾ .

f° ¾½    f ¾ f f°f– ¾n¯ ff½n W f ¾f°–¯ % f¾%– ff°–€.

++ W @¾¾ nf¾ °¾½ €¾¯f¾°f ½–f¯¯°– °.

++° ¾f €€  °f€°°–f  ½  ¯¾°–  W ° ¾ .

++ €€ n   €°–¯–f° ½f°¾½½¾  f° © n ° n°n ½¾  f° ¾°f€.


++ .

¾ f°° nnf½½© n   ½ °.

++ D¾ ¾  ½°  f¾f– ¾€ ½© n .


°n¾° W .

++¾ n¯°– f°–f– €nn € –f½n¾f½½nf°¾f°   ¾n¾¾ ¾¯ €   ° ¾f°–½fn °¾€  J ¾f¾    ¯ – °n €–f½n¾f½½nf°¾n n°¾¾€½––f  n¯½° °¾f° nnf° f¾ n¾¯¾ ¾¾½ n€n¾f°¾ ° ¾f ½ ¾  ° ¾¯f°– €¯° °n¯°nf° °€    ¾¾ ¯¾–f f  ½fn   ° ½ f  n¯½° ° n°– .

@-D .

Sign up to vote on this title
UsefulNot useful