5
CSCE 4813 – Computer Graphics Programming Project 4 EXTENDED to Due Friday 03/20/2020 1. Problem Statement: The goal of this programming project is to create an OpenGL program that uses Phong shading to display geometric models of objects that have been scanned with an RGBD camera. Color information (RGB) will be stored in one JPEG image and depth information (D) will be stored in a second JPEG image. We will be starting with the RGBD images of a penny below. Task 1: Model Creation We want to create a polygon model to represent the penny. The easiest way to do this is to model the top surface of the penny with a 2D surface D(x,y), where the D is the depth and (x,y) are the sample locations in the JPEG image. Your first task is to write an OpenGL program that reads in a JPEG depth image and stores this information in a polygon mesh. In the case of the penny above, the D values range from [0..255] and the (x,y) coordinates go from [0..499, 0..499]. These values do not correspond to the real dimensions of a penny (the thickness of a penny is not half the diameter) so you will have to scale the D values into an appropriate range. There are several ways to store the (x,y,z) locations of points in your polygon mesh. The most common choices are: (1) using three 2D arrays of float values x(u,v), y(u,v) and z(u,v), or (2) using one 2D array of 3D point values P(u,v) which store x,y,z values. You are welcome to choose whichever representation you are most comfortable with.

CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

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.

Page 2: CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

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).

Page 3: CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

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.

Page 4: CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

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.

Page 5: CSCE 4813 – Computer Graphics Programming Project 4 ...jgauch/4813/S20/projects/project4/project4.pdfThis semester we will be using C++ and OpenGL to implement all of our programming

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.