ebook img

Introduction to Computer Graphics: Using Java 2D and 3D PDF

265 Pages·2012·3.493 MB·English
by  KlawonnFrank
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introduction to Computer Graphics: Using Java 2D and 3D

Undergraduate Topics in Computer Science UndergraduateTopicsinComputerScience(UTiCS)delivershigh-qualityinstructionalcontentforun- dergraduatesstudyinginallareasofcomputingandinformationscience.Fromcorefoundationaland theoreticalmaterialtofinal-yeartopicsandapplications,UTiCSbookstakeafresh,concise,andmod- ernapproachandareidealforself-studyorforaone-ortwo-semestercourse.Thetextsareallauthored byestablishedexpertsintheirfields,reviewedbyaninternationaladvisoryboard,andcontainnumer- ousexamplesandproblems.Manyincludefullyworkedsolutions. Forfurthervolumes: http://www.springer.com/series/7592 Frank Klawonn Introduction to Computer Graphics Using Java 2D and 3D Second Edition Prof.Dr.FrankKlawonn DepartmentofComputerScience OstfaliaUniversityofAppliedSciences Wolfenbüttel,Germany Serieseditor IanMackie Advisoryboard SamsonAbramsky,UniversityofOxford,Oxford,UK KarinBreitman,PontificalCatholicUniversityofRiodeJaneiro,RiodeJaneiro,Brazil ChrisHankin,ImperialCollegeLondon,London,UK DexterKozen,CornellUniversity,Ithaca,USA AndrewPitts,UniversityofCambridge,Cambridge,UK HanneRiisNielson,TechnicalUniversityofDenmark,KongensLyngby,Denmark StevenSkiena,StonyBrookUniversity,StonyBrook,USA IainStewart,UniversityofDurham,Durham,UK ISSN1863-7310 UndergraduateTopicsinComputerScience ISBN978-1-4471-2732-1 e-ISBN978-1-4471-2733-8 DOI10.1007/978-1-4471-2733-8 SpringerLondonDordrechtHeidelbergNewYork BritishLibraryCataloguinginPublicationData AcataloguerecordforthisbookisavailablefromtheBritishLibrary LibraryofCongressControlNumber:2012930826 ©Springer-VerlagLondonLimited2008,2012 OriginallypublishedintheGermanlanguagebyVieweg+Teubner,65189Wiesbaden,Germany,as“Kla- wonn: Grundkurs Computergrafik mit Java. 3rd edition” © Vieweg+Teubner | Springer Fachmedien WiesbadenGmbH2010SpringerFachmedienispartofSpringerScience+BusinessMedia Apartfromanyfairdealingforthepurposesofresearchorprivatestudy,orcriticismorreview,asper- mittedundertheCopyright,DesignsandPatentsAct1988,thispublicationmayonlybereproduced, storedortransmitted,inanyformorbyanymeans,withthepriorpermissioninwritingofthepublish- ers,orinthecaseofreprographicreproductioninaccordancewiththetermsoflicensesissuedbythe CopyrightLicensingAgency.Enquiriesconcerningreproductionoutsidethosetermsshouldbesentto thepublishers. Theuseofregisterednames,trademarks,etc.,inthispublicationdoesnotimply,evenintheabsenceofa specificstatement,thatsuchnamesareexemptfromtherelevantlawsandregulationsandthereforefree forgeneraluse. Thepublishermakesnorepresentation,expressorimplied,withregardtotheaccuracyoftheinformation containedinthisbookandcannotacceptanylegalresponsibilityorliabilityforanyerrorsoromissions thatmaybemade. Printedonacid-freepaper SpringerispartofSpringerScience+BusinessMedia(www.springer.com) Preface to the Second Edition The positive feedback to the first edition of the book and various encouraging re- quests to extend the list of topics contained in the book have led to this second edition.Thenewtopicsthatareincludedinthissecondeditionhavebeenselected inawaytokeepthecharacterofthebookasatextbookforundergraduatestudents explainingthebasicconceptsofcomputergraphicsandenablingthestudentsatthe same time to implement and use these concepts in Java 2D and 3D without going intosophisticateddetailsofprogramming. Apart from minor changes in the text, the following new topics are included in thissecondeditionofthebook. Using functions of two variables for surface modelling is explained, especially • forthepurposeofrepresentinghillylandscapes. Theintegrationoftextin3Dscenes. • Particle systems are treated in more detail and an implementation of a simple • particle system with a number of different control parameters in Java 3D is de- scribed. Billboardbehavioursareexplainedforenforcingthatobjectsarealwaysoriented • to the viewer that are of specific interest for text in 3D scenes and for particle systems. Dynamicsurfacesaretreatedinmoredetail. • Theconceptoflevelofdetail(LOD)forrenderingobjectsindifferentresolutions • dependingonthedistanceoftheobjecttotheviewerisexplained. Asinthefirstedition,forallthesenewconcepts,exampleprogramsinJavaare providedanddescribed. Ihopethatthissecondeditionwillencourageevenmorereaderstobecomein- terested in computer graphics, to understand the basic principles and to apply the conceptsintheirownprograms. Wolfenbüttel,Germany FrankKlawonn v Preface Earlycomputergraphicsstartedasaresearchandapplicationfieldthatwasthedo- mainofonlyafewexperts,forinstanceintheareaofcomputeraideddesign(CAD). Nowadays, any person using a personal computer benefits from the developments in computer graphics. Operating systems and application programs with graphical userinterfaces(GUIs)belongtothesimplestapplicationsofcomputergraphics.Vi- sualisationtechniques,rangingfromsimplehistogramstodynamic3Danimations showingchangesofwindsorcurrentsovertime,usecomputergraphicsinthesame manner as popular computer games. Even those who do not use a personal com- putermightseetheresultsofcomputergraphicsonTVorincinemaswherepartsof scenesorevenawholemoviemightbeproducedbycomputergraphicstechniques. Without powerful hardware in the form of fast processors, sufficiently large memoryandspecialgraphicscards,mostoftheseapplicationswouldnothavebeen possible.Inadditiontothesehardwarerequirementsefficientalgorithmsaswellas programmingtoolsthatareeasytouseandflexibleatthetimearerequired.Nowa- days,astandardpersonalcomputerissufficienttogenerateimpressivegraphicsand animationsusingfreelyavailableprogrammingplatformslikeOpenGLorJava3D. Inadditiontoatleastanelementaryunderstandingofprogramming,theuseofsuch platformsalsorequiresbasicknowledgeabouttheunderlyingbackground,concepts andmethodsofcomputergraphics. AimsoftheBook Theaimofthisbookistoexplainthenecessarybackgroundandprinciplesofcom- putergraphicscombinedwithdirectapplicationsinconcreteandsimpleexamples. Coupling the theory with the practical examples enables the reader to apply the technicalconceptsdirectlyandtovisuallyunderstandwhattheymean. Java 2D and Java 3D build the basis for the practical examples. Wherever pos- sible, the introduced concepts and theory of computer graphics are immediately followed by their counterparts in Java 2D and Java 3D. However, the intention of this book is not to provide complete introductions to Java 2D or Java 3D, which wouldneedamultivolumeeditionthemselveswithouteventouchingtheunderlying theoreticalconceptsofcomputergraphics. vii viii Preface In order to directly apply computer graphics concepts introduced in this book, thebookfocussesonthepartsofJava2DandJava3Dthatareabsolutelyrelevant fortheseconcepts.Sometimesasimplesolutionispreferredoverthemostgeneral onesothatnotallpossibleoptionsandadditionalparametersforanimplementation will be discussed. The example programs are kept as simple as possible in order toconcentrateontheimportantconceptsandnottodisguisethemincomplex,but moreimpressivescenes. Therearesomeselectedadditionaltopics—forinstancethecomputationofshad- owswithincomputergraphics—thatareintroducedinthebook,althoughJava3D doesnotprovidesuchtechniquesyet. WhyJava? TherearevariousreasonsforusingJava2DandJava3Dasapplicationplatforms. The programming language Java becomes more and more popular in applications andteachingsothatextensionslikeJava2D/3Dseemtobethemostobviouschoice. ManyuniversitiesuseJavaastheintroductoryprogramminglanguage,notonlyin computerscience,butalsoinotherareassothatstudentswithabasicknowledgein Java can immediately start to work with Java 2D/3D. Specifically, for multimedia applicationsJavaisveryoftenthelanguageoffirstchoice. Overview Thefirstchaptersofthebookfocusonaspectsoftwo-dimensionalcomputergraph- ics like how to create and draw lines, curves and geometric shapes, handling of coloursandtechniquesforanimatedgraphics. Chapter5andallfollowingchapterscovertopicsofthree-dimensionalcomputer graphics.Thisincludesmodellingof3Dobjectsandscenes,producingimagesfrom virtual3Dscenes,animation,interaction,illuminationandshading.Thelastchapter introducesselectedspecialtopics,forexamplespecialeffectslikefog,soundeffects andstereoscopicviewing. GuidelinesfortheReader Inordertobeabletoapplythecomputergraphicsconceptsintroducedinthisbook, thereaderwillneedonlyveryelementaryknowledgeoftheprogramminglanguage Java.TheexampleprogramsinthisbookuseJava3DbutalsoJava2Dinthefirst chapters,sincetwo-dimensionalrepresentationsareessentialforcomputergraphics and the geometrical concepts are easier to understand in two dimensions than in three.ThenecessarybackgroundofJava2DandJava3Disincludedasapplication sectionsinthisbook. Preface ix Although the coupling of theory and practice was a main guideline for writing this book, the book can also be used as an introduction to the general concepts of computer graphics without focussing on specific platforms or learning how to useJava2DorJava3D.Skippingallsectionsandsubsectionscontainingtheword “Java” in their headlines, the book will remain completely self-contained in the senseofamoretheoreticalbasicintroductiontocomputergraphics.Forsomeofthe computergraphicsconceptsintroducedinthisbookitisassumedthatthereaderhas basicknowledgeaboutvectors,matricesandelementarycalculus. SupplementalResources Includingthecompletesourcecodeofallmentionedexampleprogramswouldhave led to a thicker, but less readable book. In addition, no one would like to take the burdenoftypingthesourcecodeagaininordertoruntheexamples.Therefore,the bookitselfonlycontainsthoserelevantexcerptsofthesourcecodethatarereferred to in the text. The complete source code of all example programs and additional programscanbedownloadedfromthebookwebsiteat http://public.ostfalia.de/~klawonn/computergraphics Thisonlineservicealsoprovidesadditionalexercisesconcerningthetheoretical background as well programming tasks including sketches of solutions, teaching material in the form of slides and some files that are needed for the example pro- grams. The links mentioned in the appendix and further links to some interesting websitescanalsobefoundattheonlineserviceofthisbook. Acknowledgements Over the years, the questions, remarks and proposals of my students had a great influenceonhowthisbookwaswritten.Icannotlistallofthembyname,butIwould liketomentionatleastDanielBeier,ThomasWeber,JanaVolkmerandespecially DaveBahrforreadingthemanuscriptandtheirextremelyhelpfulcomments.Ialso would like to thank Katharina Tschumitschew and Gerry Gehrmann for designing the online service of the book and for some 3D models that I could use in my programs.ThebookwasfirstpublishedinGermanandwithouttheencouragement andsupportofCatherineBrettfromSpringerVerlaginLondonthisEnglishversion wouldhavebeenimpossible.ThanksalsotoFrankGanzfromSpringer,whoseems toknoweverythingaboutLATEX.Myverypersonalthanksgotomyparentsandmy wifeKeikofortheirloveandforalwaysacceptingmysometimesextremelyheavy overloadofwork. Wolfenbüttel,Germany FrankKlawonn Contents 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 ApplicationFields . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 FromaRealScenetoanImage . . . . . . . . . . . . . . . . . . . 3 1.3 OrganisationoftheBook . . . . . . . . . . . . . . . . . . . . . . 4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 BasicPrinciplesofTwo-DimensionalGraphics . . . . . . . . . . . . 7 2.1 RasterVersusVectorGraphics . . . . . . . . . . . . . . . . . . . . 7 2.2 TheFirstJava2DProgram . . . . . . . . . . . . . . . . . . . . . 9 2.3 BasicGeometricObjects. . . . . . . . . . . . . . . . . . . . . . . 13 2.4 BasicGeometricObjectsinJava2D. . . . . . . . . . . . . . . . . 15 2.5 GeometricTransformations . . . . . . . . . . . . . . . . . . . . . 20 2.6 HomogeneousCoordinates . . . . . . . . . . . . . . . . . . . . . 24 2.7 ApplicationsofTransformations . . . . . . . . . . . . . . . . . . 27 2.8 GeometricTransformationsinJava2D . . . . . . . . . . . . . . . 29 2.9 AnimationandMovementsBasedonTransformations . . . . . . . 32 2.10 MovementsviaTransformationsinJava2D. . . . . . . . . . . . . 34 2.11 InterpolatorsforContinuousChanges . . . . . . . . . . . . . . . . 35 2.12 ImplementationofInterpolatorsinJava2D . . . . . . . . . . . . . 38 2.13 SingleorDoublePrecision . . . . . . . . . . . . . . . . . . . . . 39 2.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 3 DrawingLinesandCurves. . . . . . . . . . . . . . . . . . . . . . . . 43 3.1 LinesandPixelGraphics . . . . . . . . . . . . . . . . . . . . . . 43 3.2 TheMidpointAlgorithmforLines . . . . . . . . . . . . . . . . . 45 3.3 StructuralAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . 53 3.4 PixelDensitiesandLineStyles . . . . . . . . . . . . . . . . . . . 55 3.4.1 DifferentLineStyleswithJava2D . . . . . . . . . . . . . 58 3.5 LineClipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.6 TheMidpointAlgorithmforCircles . . . . . . . . . . . . . . . . . 65 3.7 DrawingArbitraryCurves . . . . . . . . . . . . . . . . . . . . . . 69 3.8 Antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.8.1 AntialiasingwithJava2D . . . . . . . . . . . . . . . . . . 72 xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.