Cs408, Lab 3: Opengl For 3D Objects: Setting Up An Opengl Project
Cs408, Lab 3: Opengl For 3D Objects: Setting Up An Opengl Project
Cs408, Lab 3: Opengl For 3D Objects: Setting Up An Opengl Project
1<. $#an)e t#e color of t#e cu-e to -lue /0" 0" 11 -y addin) at )l$olor' line after its )lPus#Matri6 line. glColor3f(0.0, 0.0, 1.0); 13. (dd a wireDfra*e s #ere at /0" 0" D21. 9i.e it a radius of 0.G wit# 20 slices /lines of lon)itude1 and <0 stac,s /lines of latitude1: glutWireS !ere(0.", 20, #0); Note: To do so" you s#ould co y all t#e code for one cu-e fro* gl$us!%atri& to gl$o %atri& inclusi.e" and re lace crucial line wit# t#e glutWireS !ere line. 1B. (dd a wireDfra*e cone at t#e ori)in. 9i.e it a radius of 0.G wit# 20 slices /lines of lon)itude1 and <0 stac,s /lines of latitude1:
glutWireCone(1.0, 1.', 20, 1); (( radius is 1, !eig!t is 1.'
()ain" you s#ould co y all t#e code for one cu-e fro* gl$us!%atri& to gl$o %atri& inclusi.e" and re lace t#e crucial line wit# t#e glutWireCone line.
"a)ing a *oc)et
21. 2ou s#ould -e a-le to see t#at t#e wireDfra*e cone is oriented alon) t#e F a6is. T#e s*all end oints towards ositi.e F. ?n t#e dis la1 function" to *o.e t#e ca*era fart#er away fro* t#e scene" c#an)e t#e first line of nu*-ers for t#e glu+oo23t function fro* 1.0" 2.0" 2.0" to 1.0" 20.0" 20.0" 22. ?n t#e dis la1 function" rotate t#e cone -y 2C0 de)rees around t#e E a6is so t#at it is ointin) u alon) t#e 2 a6is. glRotatef(240, 1, 0, 0); 2'. +aise t#e cone u -y < units" -y translatin) -y < alon) t#e 2 a6is: glTranslatef(0.0, #.0, 0.0);
2<. Ma,e a -ody for t#e roc,et -y usin) a )lu cylinder /no to or -otto*1 and a )lu dis, for t#e -otto*. 5ind of co* licated" sorry:
*+56uadric7b89 ,6uadric : glu.e;<uadric(); gl$us!%atri&(); glColor3f(0.', 0.', 0.0); glRotatef(240, 1, 0, 0); gluC1linder( ,6uadric, 1.0, 1.0, #.0, 20, 1); glColor3f(0.', 0.', 0.'); glu=is2( ,6uadric, 0.0, 1.0, 20, #); gl$o %atri&(); glu=elete<uadric( ,6uadric);
23. 4 tional: a. $ut/ aste t#e code for drawin) t#e roc,et" includin) t#e outer )lPus#Matri6 and )lPo Matri6 calls" to a new .oid function called roc2et,dis la1 and in t#e dis la1 function just ut a call to roc2et,dis la1( ); -. To *a,e t#e roc,et red in color" in t#e roc,et dis lay function" ut a call to glColorH -efore t#e gl$us!%atri& and re*o.e t#e ot#er )l$olorH lines. c. To rotate or scale t#e roc,et as a w#ole" ut glRotatef and glScalef lines after t#e glTranslatef line t#at is just after t#e gl$us!%atri&() line.
'
()ain" all lines -etween gl$us!%atri& and gl$o %atri& s#ould -e indented for reada-ility reasons. 2G. $o* ile and run t#e ro)ra*. T#e roc,et s#ould fly out of si)#t" rea ear at t#e ori)in" and t#en re eat. ?t s#ould #a en so fast t#at you can #ardly see it. '0. &e will slow t#e ani*ation down -y *a,in) 4 en9> wait 1/100 of a second -etween t#e dis la1 of eac# fra*e. 9o to Project / (dd 86istin) ?te*@ and add Slee .! and Slee .c to your roject. (t t#e to of your Dain2.c file" add Einclude FSlee .!F ?n your idle function" i**ediately -efore glut$ostRedis la1" add t#e line slee (0.01); (( ;ait for 0.01 seconds $o* ile and run t#e ro)ra*. T#e roc,et s#ould fly at a sensi-le s eed and t#e E -utton in t#e corner s#ould wor, a)ain.
<