《OpenGl构建基本的房子word精品文档16页.doc》由会员分享,可在线阅读,更多相关《OpenGl构建基本的房子word精品文档16页.doc(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流OpenGl构建基本的房子ItemsMark allocatedGradeDemo(10 marks)(H) house - A house should be created and displayed.2(T) tree- At least one tree should be created and displayed2(S) Sun the sun is a must object.2(E) extra environment object(s) - you can create any other extra object on the pie
2、ce of land you have. 2(V) viewpoints - your program should enable viewer to view your home with different angles. 2Sub-total: 10Final Report(20 marks)(C) clarity - Does your report explain everything that you did?2(D) design - Did you design your implementation well? Did you use any CG technique(s)
3、where appropriate? 2(E) English - Are there any spelling or grammatical errors? Is your writing clear and succinct?2(N) neatness - Are the text, code and figures laid out well? Is your writing/printing legible?2(T) thoroughness - Is the report complete? Did you leave important things out? Did you fo
4、rget to describe important cases, rules, or program behaviour? Did you make errors in your project that arent listed in the shortcomings?2Sub-total: 10Total: out of 20 General Comments:Introduction and Motivation: 我们的实验包括房子、栅栏、小狗住的房子、树木、机器人、太阳、草地等几个简单的事物,保证了能够从各个角度观看到,完成了对项目的基本要求。 在实验创建中,我们首先按照要求构思出
5、整体的框架,需要做哪些事物,以及每个事物的大体位置,接着计算各个点的坐标,之后分工进行,每个人做一到两个事物,最后将所有事物整合在一起。 还遇到的一个问题是,保证所有物体能够合理的展现出来,不出现掩盖或不能显示效果的现象,这首先是对物体的创建和坐标的把握,然后是对基本变换功能的掌握,对于这方面的设计,不仅需要严谨计算还要学习功能的设计。Design and Implementations: 一开始大体的想法是设计一个带有烟囱的尖顶房子,后来在做房顶的时候遇到了困难,房顶的两侧无法显示,后来找到的改进方法是将房顶做成一个长方体,并将长方体上的两个点合并,并缩短X轴上的距离,加上深度测试,最终出现
6、了想要的效果;之后用类似的方法做出了树和小狗住的房子;太阳一开始想用实验三的方法通过圆去做,后来效果不理想,我们组在网上找到了glutSolidSphere();画球的方法。由此也学会了glutSolidCube();画立方体的方法,利用这种方法做出了栅栏,然后两者综合做出了机器人Shortcomings: 设计完实验作业,我们存在着很多的不足,首先,构图坐标有些繁杂冗长,导致代码的篇幅有些长。第二,因为功底是在太差,没有做出贴图和光源,导致整体不是很漂亮。第三,实验思路有些混乱,经常是想起来什么就做什么,导致效率变低。 Conclusions: 总体来说,能够把项目做到这样的效果,我们还是很
7、满意的,但是还是对没有将四面的背景分别设定表达感到遗憾。 如果要重新做一遍,我会选择学习并使用纹理的表现,这个功能的优点是能够使事物表现更为逼真。 这门课程让我对CG这门学科有了最基本的认识和学习,希望以后有机会可以多加接触。Appendix: #include#include#include#include using std:cout;#define _USE_MATH_DEFINES #include double rotate_y = -15; /定义键盘控制旋转X轴,默认-5度double rotate_x = -15; /定义键盘控制旋转Y轴,默认0度GLfloat w = 800
8、;GLfloat h = 600;GLfloat anglePyramid = 0.0f;GLfloat angleCube = 0.0f;void display(void)glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f, -100.0f, 0.0f);/ (左,上,前)glScalef(100, 100, 100); / 放大图像(也可以更改点的数据来达到此效果)/Rotate语句:(旋转度数,X,Y,Z)/ 延X
9、,Y,Z轴旋转/太阳(不能动)glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-5.0, 5.0, 5.0);glutSolidSphere(1.5, 20, 20);glPopMatrix();glRotatef(rotate_x, 1.0, 0.0, 0.0);glRotatef(rotate_y, 0.0, 1.0, 0.0);/*/太阳(可以动)glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-5.0, 5.0, 5.0);glutSolidSphere(1.5, 20,
10、 20);glPopMatrix();/房子的两部分公用一个坐标系,屏幕远向近为Z轴,由下向上是Y轴,由左向右是X轴/*房顶*/顶glBegin(GL_QUADS);glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(2.05f, 3.5f, 0.0f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(2.05f, 3.5f, 0.0f);/ 底glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(3.5f, 1.5f, 2.5f);glV
11、ertex3f(-3.5f, 1.5f, 2.5f);glVertex3f(-3.5f, 1.5f, -2.5f);glVertex3f(3.5f, 1.5f, -2.5f);/ 前glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(2.05f, 3.5f, 0.0f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(-3.5f, 1.5f, 2.5f);glVertex3f(3.5f, 1.5f, 2.5f);/ 后glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(3.5f, 1.5f, -2.
12、5f);glVertex3f(-3.5f, 1.5f, -2.5f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(2.05f, 3.5f, 0.0f);/ 左glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(-2.05f, 3.5f, 0.0f);glVertex3f(-3.5f, 1.5f, -2.5f);glVertex3f(-3.5f, 1.5f, 2.5f);/ 右glColor3f(0.0f, 0.0f, 0.502f);glVertex3f(2.05
13、f, 3.5f, 0.0f);glVertex3f(2.05f, 3.5f, 0.0f);glVertex3f(3.5f, 1.5f, 2.5f);glVertex3f(3.5f, 1.5f, -2.5f);glEnd();/*烟囱*/顶glBegin(GL_QUADS);glColor3f(0.502f, 0.0f, 0.0f);glVertex3f(3.0f, 4.0f, -1.0f);glVertex3f(2.0f, 4.0f, -1.0f);glVertex3f(2.0f, 4.0f, 1.0f);glVertex3f(3.0f, 4.0f, 1.0f);/ 底glColor3f(0.
14、502f, 0.0f, 0.0f);glVertex3f(3.0f, 2.0f, 1.0f);glVertex3f(2.0f, 2.0f, 1.0f);glVertex3f(2.0f, 2.0f, -1.0f);glVertex3f(3.0f, 2.0f, -1.0f);/ 前glColor3f(0.502f, 0.0f, 0.0f);glVertex3f(3.0f, 4.0f, 1.0f);glVertex3f(2.0f, 4.0f, 1.0f);glVertex3f(2.0f, 2.0f, 1.0f);glVertex3f(3.0f, 2.0f, 1.0f);/ 后glColor3f(0.
15、502f, 0.0f, 0.0f);glVertex3f(3.0f, 2.0f, -1.0f);glVertex3f(2.0f, 2.0f, -1.0f);glVertex3f(2.0f, 4.0f, -1.0f);glVertex3f(3.0f, 4.0f, -1.0f);/ 左glColor3f(0.502f, 0.0f, 0.0f);glVertex3f(2.0f, 4.0f, 1.0f);glVertex3f(2.0f, 4.0f, -1.0f);glVertex3f(2.0f, 2.0f, -1.0f);glVertex3f(2.0f, 2.0f, 1.0f);/ 右glColor3
16、f(0.502f, 0.0f, 0.0f);glVertex3f(3.0f, 4.0f, -1.0f);glVertex3f(3.0f, 4.0f, 1.0f);glVertex3f(3.0f, 2.0f, 1.0f);glVertex3f(3.0f, 2.0f, -1.0f);glEnd();/*屋子*/顶glBegin(GL_QUADS);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(2.0f, 1.5f, -1.5f);glVertex3f(-2.0f, 1.5f, -1.5f);glVertex3f(-2.0f, 1.5f, 1.5f);glVertex
17、3f(2.0f, 1.5f, 1.5f);/ 底glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(2.0f, -0.5f, 1.5f);glVertex3f(-2.0f, -0.5f, 1.5f);glVertex3f(-2.0f, -0.5f, -1.5f);glVertex3f(2.0f, -0.5f, -1.5f);/门glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(0.5, 1.0, -1.51);glVertex3f(-0.5, 1.0, -1.51);glVertex3f(-0.5, -0.5, -1.51);glVerte
18、x3f(0.5, -0.5, -1.51);/窗户glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(1.25, 1.25, -1.51);glVertex3f(0.75, 1.25, -1.51);glVertex3f(0.75, 0.75, -1.51);glVertex3f(1.25, 0.75, -1.51);/ 前glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(2.0f, 1.5f, 1.5f);glVertex3f(-2.0f, 1.5f, 1.5f);glVertex3f(-2.0f, -0.5f, 1.5f);gl
19、Vertex3f(2.0f, -0.5f, 1.5f);/ 后glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(2.0f, -0.5f, -1.5f);glVertex3f(-2.0f, -0.5f, -1.5f);glVertex3f(-2.0f, 1.5f, -1.5f);glVertex3f(2.0f, 1.5f, -1.5f);/窗户glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(-2.01, 1.05, 0.4);glVertex3f(-2.01, 1.05, -0.4);glVertex3f(-2.01, 0.25,
20、 -0.4);glVertex3f(-2.01, 0.25, 0.4);/ 左glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(-2.0f, 1.5f, 1.5f);glVertex3f(-2.0f, 1.5f, -1.5f);glVertex3f(-2.0f, -0.5f, -1.5f);glVertex3f(-2.0f, -0.5f, 1.5f);/窗户glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(2.01, 1.05, 0.4);glVertex3f(2.01, 1.05, -0.4);glVertex3f(2.01,
21、0.25, -0.4);glVertex3f(2.01, 0.25, 0.4);/ 右glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(2.0f, 1.5f, -1.5f);glVertex3f(2.0f, 1.5f, 1.5f);glVertex3f(2.0f, -0.5f, 1.5f);glVertex3f(2.0f, -0.5f, -1.5f);glEnd();/*基座*/顶glBegin(GL_QUADS);glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(5.0, -0.5, -3.5);glVertex3f(-5.
22、0, -0.5, -3.5);glVertex3f(-5.0, -0.5, 3.5);glVertex3f(5.0, -0.5, 3.5);/ 底glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(5.0, -1.0, 3.5);glVertex3f(-5.0, -1.0, 3.5);glVertex3f(-5.0, -1.0, -3.5);glVertex3f(5.0, -1.0, -3.5);/ 前glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(5.0, -0.5, 3.5);glVertex3f(-5.0,
23、-0.5, 3.5);glVertex3f(-5.0, -1.0, 3.5);glVertex3f(5.0, -1.0, 3.5);/ 后glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(5.0, -1.0, -3.5);glVertex3f(-5.0, -1.0, -3.5);glVertex3f(-5.0, -0.5, -3.5);glVertex3f(5.0, -0.5, -3.5);/ 左glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(-5.0, -0.5, 3.5);glVertex3f(-5.0, -
24、0.5, -3.5);glVertex3f(-5.0, -1.0, -3.5);glVertex3f(-5.0, -1.0, 3.5);/ 右glColor3f(0.502f, 0.502f, 0.502f);glVertex3f(5.0, -0.5, -3.5);glVertex3f(5.0, -0.5, 3.5);glVertex3f(5.0, -1.0, 3.5);glVertex3f(5.0, -1.0, -3.5);glEnd();/*地板*/glBegin(GL_QUADS);glColor3f(0.0f, 0.502f, 0.0f);glVertex3f(100.0, -1.0,
25、 -100.0);glVertex3f(-100.0, -1.0, -100.0);glVertex3f(-100.0, -1.0, 100.0);glVertex3f(100.0, -1.0, 100.0);glEnd();/*狗窝*/glBegin(GL_TRIANGLE_FAN);glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(9.0f, 1.5f, -5.0f);glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(10.0f, 0.5f, -5.5f);glColor3f(0.502f, 0.0f, 0.502f)
26、;glVertex3f(8.0f, 0.5f, -5.5f);glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(8.0f, 0.5f, -4.5f);glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(10.0f, 0.5f, -4.5f);glColor3f(0.502f, 0.0f, 0.502f);glVertex3f(10.0f, 0.5f, -5.5f);glEnd();glBegin(GL_QUADS);glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(9.5f, 0.5f,
27、-4.5f);glVertex3f(8.5f, 0.5f, -4.5f);glVertex3f(8.5f, 0.5f, -5.5f);glVertex3f(9.5f, 0.5f, -5.5f);/ 底glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(9.5f, -1.0f, -5.5f);glVertex3f(8.5f, -1.0f, -5.5f);glVertex3f(8.5f, -1.0f, -4.5f);glVertex3f(9.5f, -1.0f, -4.5f);/ 前glColor3f(0.0f, 0.502f, 0.502f);glVertex3
28、f(9.5f, 0.5f, -5.5f);glVertex3f(8.5f, 0.5f, -5.5f);glVertex3f(8.5f, -1.0f, -5.5f);glVertex3f(9.5f, -1.0f, -5.5f);/ 后glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(9.5f, -1.0f, -4.5f);glVertex3f(8.5f, -1.0f, -4.5f);glVertex3f(8.5f, 0.5f, -4.5f);glVertex3f(9.5f, 0.5f, -4.5f);/小门glColor3f(0.502f, 0.0f, 0.5
29、02f);glVertex3f(8.49, 0.0, -5.0);glVertex3f(8.49, 0.0, -5.5);glVertex3f(8.49, -1.0, -5.5);glVertex3f(8.49, -1.0, -5.0);/ 左glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(8.5f, 0.5f, -5.5f);glVertex3f(8.5f, 0.5f, -5.0f);glVertex3f(8.5f, -1.0f, -5.0f);glVertex3f(8.5f, -1.0f, -5.5f);/ 右glColor3f(0.0f, 0.502
30、f, 0.502f);glVertex3f(9.50f, 0.5f, -5.0f);glVertex3f(9.50f, 0.5f, -5.5f);glVertex3f(9.50f, -1.0f, -5.5f);glVertex3f(9.50f, -1.0f, -5.0f);glEnd();/*树*/glBegin(GL_TRIANGLE_FAN);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-9.0f, 4.0f, 5.0f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 2.5f, 6.5f);glColor3
31、f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 2.5f, 6.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 2.5f, 3.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 2.5f, 3.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 2.5f, 6.5f);glEnd();glBegin(GL_TRIANGLE_FAN);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-9
32、.0f, 5.5f, 5.0f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 4.0f, 6.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 4.0f, 6.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 4.0f, 3.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 4.0f, 3.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 4.
33、0f, 6.5f);glEnd();glBegin(GL_TRIANGLE_FAN);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-9.0f, 2.5f, 5.0f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 1.0f, 6.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 1.0f, 6.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-7.5f, 1.0f, 3.5f);glColor3f(0.0f, 1.0f, 0.
34、0f);glVertex3f(-10.5f, 1.0f, 3.5f);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(-10.5f, 1.0f, 6.5f);glEnd();/顶glBegin(GL_QUADS);glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(-9.25f, 1.5f, 4.75f);glVertex3f(-8.75f, 1.5f, 4.75f);glVertex3f(-8.0f, 1.5f, 5.25f);glVertex3f(-9.25f, 1.5f, 5.25f);/ 底glColor3f(0.0f,
35、0.502f, 0.502f);glVertex3f(-9.25f, -1.0f, 5.25f);glVertex3f(-8.75f, -1.0f, 5.25f);glVertex3f(-8.75f, -1.0f, 4.75f);glVertex3f(-9.25f, -1.0f, 4.75f);/ 前glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(-9.25f, 1.5f, 5.25f);glVertex3f(-8.75f, 1.5f, 5.25f);glVertex3f(-8.75f, -1.0f, 5.25f);glVertex3f(-9.25f, -
36、1.0f, 5.25f);/ 后glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(-9.25f, -1.0f, 4.75f);glVertex3f(-8.75f, -1.0f, 4.75f);glVertex3f(-8.75f, 1.5f, 4.75f);glVertex3f(-9.25f, 1.5f, 4.75f);/ 左glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(-8.75f, 1.5f, 5.25f);glVertex3f(-8.75f, 1.5f, 4.75f);glVertex3f(-8.75f, -1.0
37、f, 4.75f);glVertex3f(-8.75f, -1.0f, 5.25f);/ 右glColor3f(0.0f, 0.502f, 0.502f);glVertex3f(-9.25f, 1.5f, 4.75f);glVertex3f(-9.25f, 1.5f, 5.25f);glVertex3f(-9.25f, -1.0f, 5.25f);glVertex3f(-9.25f, -1.0f, 4.75f);glEnd();/后方栅栏glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(0, 0.1, 3.0);glScalef(100,
38、 1, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(0, -0.3, 3.0);glScalef(100, 1, 1);glutSolidCube(0.1);glPopMatrix();/右面栅栏glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(4.5, 0.1, 0);glScalef(1, 1, 60);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.
39、0, 0.0);glPushMatrix();glTranslatef(4.5, -0.3, 0);glScalef(1, 1, 60);glutSolidCube(0.1);glPopMatrix();/左边栅栏glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-4.5, 0.1, 0);glScalef(1, 1, 60);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-4.5, -0.3, 0);glScal
40、ef(1, 1, 60);glutSolidCube(0.1);glPopMatrix();/后方竖栅栏glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(0, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-0.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor
41、3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-1.0, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-1.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-2.0, -0.5
42、, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-2.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-3.0, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix
43、();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-3.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(-4.0, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(
44、-4.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(0.5, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTranslatef(1.0, -0.5, 3.0);glScalef(1, 15, 1);glutSolidCube(0.1);glPopMatrix();glColor3f(1.0, 0.0, 0.0);glPushMatrix();glTr