CSCE 4813 – Computer Graphics Programming Project 4...

Preview:

Citation preview

CSCE4813–ComputerGraphicsProgrammingProject4

EXTENDEDtoDueFriday03/20/2020

1.ProblemStatement:ThegoalofthisprogrammingprojectistocreateanOpenGLprogramthatusesPhongshadingtodisplaygeometricmodelsofobjectsthathavebeenscannedwithanRGBDcamera.Colorinformation(RGB)willbestoredinoneJPEGimageanddepthinformation(D)willbestoredinasecondJPEGimage.WewillbestartingwiththeRGBDimagesofapennybelow.

Task1:ModelCreationWewanttocreateapolygonmodeltorepresentthepenny.Theeasiestwaytodothisistomodelthetopsurfaceofthepennywitha2DsurfaceD(x,y),wheretheDisthedepthand(x,y)arethesamplelocationsintheJPEGimage.YourfirsttaskistowriteanOpenGLprogramthatreadsinaJPEGdepthimageandstoresthisinformationinapolygonmesh.Inthecaseofthepennyabove,theDvaluesrangefrom[0..255]andthe(x,y)coordinatesgofrom[0..499,0..499].Thesevaluesdonotcorrespondtotherealdimensionsofapenny(thethicknessofapennyisnothalfthediameter)soyouwillhavetoscaletheDvaluesintoanappropriaterange.Thereareseveralwaystostorethe(x,y,z)locationsofpointsinyourpolygonmesh.Themostcommonchoicesare:(1)usingthree2Darraysoffloatvaluesx(u,v),y(u,v)andz(u,v),or(2)usingone2Darrayof3DpointvaluesP(u,v)whichstorex,y,zvalues.Youarewelcometochoosewhicheverrepresentationyouaremostcomfortablewith.

Task2:InteractiveModelDisplayOnceyouhavedefinedyoursurface,yournexttaskistoextendyourOpenGLprogramtodisplaythemodelsurface.Todothis,youshouldaddcodeinthedisplaycallbacktoloopoverthepolygons,anddisplaythemusingGL_LINE_LOOP.Thefirsttimeyourunthis,youwillprobablyseeablack/whitegridofparallellines.Thisisthetop-viewofthesurface,soyouwillnotseeanydepthinformation.Toviewthesurfacefromdifferentangles,youneedtoextendyourOpenGLprogramagaintorotateitaroundthreeaxes.Toimplementthis,youneedtoaddcodetothedisplaycallbacktocallglRotatef(x_angle,1,0,0),glRotatef(y_angle,0,1,0)andglRotatef(z_angle,0,0,1).Thenyouneedtoaddcodetothekeyboardcallbacktoincrease/decreasetheglobalvariablesstoringx_angle,y_angle,andz_anglewhencertainkeysarepressed.(Seeobject3.cppfordetails).Ifyourpennysurfacelookstoothickortoothin,youcanadjustyourscalefactorsuntilyougetsomethingthatlookssensible.Task3:SavingColorInformationThecolorimageofthepennyprovidesuswiththeRGBvaluesateach(u,v)locationonthepenny.YourthirdtaskistoextendyourOpenGLprogramtoreadthecolorimage,andstorethisinformationinthreearraysR(u,v),G(u,v)B(u,v)orinthe3Dpointdatastructure.IfyouprintouttheseRGBvaluesasyoureadthem,youwillseethatpixelsoutsidethepennywillbealmostpurewhite(255,255,255)andthepixelsinsidethepennywillbeacoppercolor(reddishbrown).Inordertodisplaythepennyascoloredpolygons,youneedtoextendyourprogramtocalculateandsavetheaverageRGBcolorofthepennypixels.Task4:DisplayingthePennywithStoredRGBValuesNowthatweknowtheoriginalRGBcolorforeverypointonthepennysurface,wecanusethisinformationtogenerateamorerealisticrenderingofthepenny.Createaseconddisplaycallbackcalled“color_display”thatdisplayspolygonsusingGL_POLYGONinsteadofGL_LINE_LOOP.ThenaddcodetospecifytheRGBcolorvaluesofeachpolygonvertexusingtheglColor3f()function.Sincethisfunctionexpectscolorsinthe[0..1]range,youwillhavetoscaletheoriginalRGBvalues.Asyouinteractivelyrotateyournewpennyimage,itshouldlookmorerealisticbecausedepthinformationisalsobeingdisplayed(seebelow).

Task5:DisplayingthePennyusingPhongShadingYournexttaskistocreateathirddisplaycallbackmethodcalled“phong_display”thatdisplaysyourpennysurfaceusingPhongshading.Beforeyoucandothis,youneedtoaddcodetoyourprogramtocalculateandsavethesurfacenormalateach(u,v)locationonthesurface.Thiscanbedonerightafteryoureadandstorethe(x,y,z)surfaceinformationusingthecross-productapproachdiscussedinclass.TocalltheOpenGLfunctionsforPhongshading,youshould#include“shading.cpp”inyourprogram.Thenyouneedtomodifyinit()todefineyourlightpositionsandcolors.TodisplaythepolygonsusingPhongshading,youneedtospecifymaterialpropertiesusingtheaverageRGBcolorofthepennybeforethepolygondisplayloop.Finally,youneedtoremovecallstoglColor3f()andaddcallstoglNormal3f()tospecifythesurfacenormalateachpolygonpoint.WhenyoulookattheresultingPhongshadedsurface,itshouldlooklikeitisallonematerial,butthereshouldbecolorvariationsthatletyouseetheshapeofthepennysurface.YoumayneedtoplaywiththePhongshadingparametersKa,Kd,Ks,Kptogetsomethingthatlooksrealistic.Ifyousetyourlightsintherightlocations,youmaygetaresultthatisclosetotheoriginalRGBimageofthepenny(seeabove).Task6:CompletetheUserInterfaceYourfinaltaskistoextendthe“keyboard”callbacktoallowuserstoswitchbetweenthethreedisplaycallbackfunctionsyoucreated.Forexample,youcoulduse“1”forthewireframedisplay,“2”fortheRGBsurfacedisplay,and“3”forthePhongshadeddisplay.Thiswilllettheuserlookatthepennyfromthesamepointofviewwithdifferentdisplaymethodstocompareresults.

2.Design:Thereareseveraldesigntasksyoumustcompleteforthisproject.Themostimportantdecisionistoselectdatastructuresforthe(x,y,z)coordinates,thecorrespondingsurfacenormalvalues(Nx,Ny,Nz),andRGBthecolorsofeverypoint.TherearealsoanumberofscalefactorsandPhongshadingparametersthatyouwillneedtoselecttogetrealisticlookingimages.Youmaywanttodothisbyextendingtheprogram’suserinterface,orbyaseriesofedit,compile,runexperiments.3.Implementation:ThissemesterwewillbeusingC++andOpenGLtoimplementallofourprogrammingprojects.IfyouareusingaMacwithXcodeinstalled,thenyoucandownloadthesrc.tarfileandcompilethesamplegraphicscodeusingtheenclosedMakefile.IfyouareusingaPC,thenyourbestoptionwouldbetodownloadandinstallaLinuxVMfromthedepartment’swebsite.TheinstructionsfordoingthisarepostedinREADMEfilethe“SourceCode”pageoftheclasswebsite.OnceyouhaveLinuxandOpenGLinstalled,youcancompileyourgraphicsprogramusing“g++-Wallproject2.cpp-oproject2-lGL-lGLU-lglut”.Remembertouseincrementaldevelopmentandgoodprogrammingstylewhencreatingyourprogram.Choosegoodnamesforvariablesandconstants,useproperindentingforloopsandconditionals,andincludeclearcommentsinyourcode.Also,besuretosavebackupcopiesofyourprogramsomewheresafe.Otherwise,youmayendupretypingyourwholeprogramifsomethinggoeswrong.4.Testing:Testyourprogramtocheckthatitoperatescorrectlyforalloftherequirementslistedabove.Alsocheckfortheerrorhandlingcapabilitiesofthecode.Tryyourprogramwithseveralinputvalues,andsavescreenshotsofyouroutputinjpegimagesforinclusioninyourprojectreport.5.Documentation:WhenyouhavecompletedyourC++program,writeashortreportusingtheprojectreporttemplatedescribingwhattheobjectiveswere,whatyoudid,andthestatusoftheprogram.Doesitworkproperlyforalltestcases?Arethereanyknownproblems?Savethisreporttobesubmittedelectronically.6.ProjectSubmission:Inthisclass,wewillbeusingelectronicprojectsubmissiontomakesurethatallstudentshandtheirprogrammingprojectsandlabsontime,andtoperformautomaticplagiarismanalysisofallprogramsthataresubmitted.

WhenyouhavecompletedthetasksabovegotoBlackboardtouploadyourdocumentation(asingledocxorpdffile),andallofyourC++programfiles.DoNOTuploadanexecutableversionofyourprogram.Thedatesonyourelectronicsubmissionwillbeusedtoverifythatyoumettheduedateabove.Alllateprojectswillreceivereducedcredit:• 10%offiflessthan1daylate,• 20%offiflessthan2dayslate,• 30%offiflessthan3dayslate,• nocreditifmorethan3dayslate.Youwillreceivepartialcreditforallprogramsthatcompileeveniftheydonotmeetallprogramrequirements,sohandingprojectsinontimeishighlyrecommended.7.AcademicHonestyStatement:Studentsareexpectedtosubmittheirownworkonallprogrammingprojects,unlessgroupprojectshavebeenexplicitlyassigned.StudentsareNOTallowedtodistributecodetoeachother,orcopycodefromanotherindividualorwebsite.StudentsAREallowedtouseanymaterialsontheclasswebsite,orinthetextbook,orasktheinstructorand/orGTAsforassistance.Thiscoursewillbeusinghighlyeffectiveprogramcomparisonsoftwaretocalculatethesimilarityofallprogramstoeachother,andtohomeworkassignmentsfromprevioussemesters.Pleasedonotbetemptedtoplagiarizefromanotherstudent.ViolationsofthepoliciesabovewillbereportedtotheProvost'sofficeandmayresultinaZEROontheprogrammingproject,anFintheclass,orsuspensionfromtheuniversity,dependingontheseverityoftheviolationandanyhistoryofpriorviolations.

Recommended