資源簡介
在OpenGL觀察實驗的基礎上,通過實現實驗內容,掌握OpenGL中消隱和光照的設置,并驗證課程中消隱和光照的內容。
模型尺寸不做具體要求。要求修改代碼達到以下要求:
1. 通過設置材料使得桌面和四條腿的顏色各不相同,分別為:(1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 1, 1), (0, 0, 1);
2. 通過設置材料使得茶壺為金黃色;
3. 添加按鍵處理,移動場景中的光源,并能改變光源的顏色(在兩種顏色間切換,顏色自己定義);
4. 修改茶壺的鏡面反射系數,使之對光源呈現高光;
5. 在場景中添加一個聚光光源,其照射區域正好覆蓋茶壺,并能調整改聚光光源的照射角度和朝向。

代碼片段和文件信息
//?glutEx1.cpp?:?定義控制臺應用程序的入口點。
//
#include?
#include?“glut.h“
float?fTranslate;
float?fRotate;
float?fScale?????=?1.0f; //?set?inital?scale?value?to?1.0f
bool?bPersp?=?false;
bool?bAnim?=?false;
bool?bWire?=?false;
bool?lightcolor?=?false;
float?lx=5ly=5lz=5;???//光源初始位置
bool?bjuguang?=?false;
float?spl=45;??//裁剪角度參數
float?spx=0spy=0;??//光源朝向參數
int?wHeight?=?0;
int?wWidth?=?0;
void?Draw_Leg();
void?Draw_Triangle()?//?This?function?draws?a?triangle?with?RGB?colors
{
glPushMatrix();
float?mat_diffuse[]?=?{0.85f?0.65f?0.2f?1.0f};
float?mat_specular[]?=?{0.6f?0.6f?0.6f?1.0f};
????glMaterialfv(GL_FRONT?GL_DIFFUSE?mat_diffuse);
????glMaterialfv(GL_FRONT?GL_SPECULAR?mat_specular);
glMateriali(GL_FRONT_AND_BACKGL_SHININESS50);?
glTranslatef(0?0?4+1);
glRotatef(90?1?0?0);
glutSolidTeapot(1);
glPopMatrix();
glPushMatrix();
??float?specular1[]?=?{0?0?0?1.0f};
??float?color1[]={1001};
??glMaterialfv(GL_FRONT?GL_SPECULAR?specular1);
??????glMaterialfv(GL_FRONT?GL_DIFFUSE?color1);
glTranslatef(0?0?3.5);
glScalef(5?4?1);
glColor3f(1.00.00.0);?
glutSolidCube(1.0);
glPopMatrix();
glPushMatrix();
??float?color2[]={0101};
??????glMaterialfv(GL_FRONT?GL_DIFFUSE?color2);
glTranslatef(1.5?1?1.5);
glColor3f(0.01.00.0);?
Draw_Leg();
glPopMatrix();
glPushMatrix();
??float?color3[]={1101};
??????glMaterialfv(GL_FRONT?GL_DIFFUSE?color3);
glTranslatef(-1.5?1?1.5);
glColor3f(1.01.00.0);?
Draw_Leg();
glPopMatrix();
glPushMatrix();
???float?color4[]={0111};
??????glMaterialfv(GL_FRONT?GL_DIFFUSE?color4);
glTranslatef(1.5?-1?1.5);
glColor3f(0.01.01.0);?
Draw_Leg();
glPopMatrix();
glPushMatrix();
??float?color5[]={0011};
??????glMaterialfv(GL_FRONT?GL_DIFFUSE?color5);
glTranslatef(-1.5?-1?1.5);
glColor3f(0.00.01.0);?
Draw_Leg();
glPopMatrix();
glDisable(GL_COLOR_MATERIAL);
}
void?Draw_Leg()
{
glScalef(1?1?3);
glutSolidCube(1.0);
}
void?updateView(int?width?int?height)
{
glViewport(00widthheight); //?Reset?The?Current?Viewport
glMatrixMode(GL_PROJECTION); //?Select?The?Projection?Matrix
glLoadIdentity(); //?Reset?The?Projection?Matrix
float?whRatio?=?(GLfloat)width/(GLfloat)height;
if?(bPersp)?{
gluPerspective(45.0f?whRatio0.1f100.0f);
//glFrustum(-3?3?-3?3?3100);
}?else?{
glOrtho(-3?3?-3?3-100100);
}
glMatrixMode(GL_MODELVIEW); //?Select?The?Modelview?Matrix
}
void?reshape(int?width?int?height)
{
if?(height==0) //?Prevent?A?Divide?By?Zero?By
{
height=1; //?Making?Height?Equal?One
}
wHeight?=?height;
wWidth?=?width;
updateView(wHeight?wWidth);
}
void?idle()
{
glutPostRedisplay();
}
float?eye[]?=?{0?0?8};
float?center[]?=?{0?0?0};
void?key(unsigned?char?k?int?x?int?y)
{
switch(k)
{
case?27:
c
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-05-12?09:05??Ex5\Debug\
?????文件???????36352??2016-05-20?14:58??Ex5\Debug\Ex5.exe
?????文件??????468924??2016-05-20?14:58??Ex5\Debug\Ex5.ilk
?????文件??????470016??2016-05-20?14:58??Ex5\Debug\Ex5.pdb
?????文件??????237568??2008-09-16?14:54??Ex5\Debug\glut32.dll
?????文件????24379392??2016-05-20?15:13??Ex5\Ex5.sdf
?????文件?????????876??2015-05-08?11:49??Ex5\Ex5.sln
?????文件???????12800??2015-05-08?12:58??Ex5\Ex5.suo
?????文件???????26624??2016-05-20?15:13??Ex5\Ex5.v11.suo
?????目錄???????????0??2016-05-10?19:44??Ex5\Ex5\
?????目錄???????????0??2016-05-20?14:58??Ex5\Ex5\Debug\
?????文件?????????704??2016-05-20?14:58??Ex5\Ex5\Debug\cl.command.1.tlog
?????文件????????1174??2016-05-20?14:58??Ex5\Ex5\Debug\CL.read.1.tlog
?????文件?????????288??2016-05-20?14:58??Ex5\Ex5\Debug\CL.write.1.tlog
?????文件?????????406??2016-05-10?19:44??Ex5\Ex5\Debug\Ex5.exe.em
?????文件?????????472??2016-05-10?19:44??Ex5\Ex5\Debug\Ex5.exe.em
?????文件?????????381??2016-05-20?14:58??Ex5\Ex5\Debug\Ex5.exe.intermediate.manifest
?????文件??????????66??2016-05-20?14:58??Ex5\Ex5\Debug\Ex5.lastbuildstate
?????文件????????1702??2016-05-20?14:58??Ex5\Ex5\Debug\Ex5.log
?????文件?????????196??2016-05-10?19:44??Ex5\Ex5\Debug\Ex5_manifest.rc
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件???????????2??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件????????1492??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件????????3156??2016-05-20?14:58??Ex5\Ex5\Debug\li
?????文件?????????638??2016-05-20?14:58??Ex5\Ex5\Debug\li
............此處省略18個文件信息
- 上一篇:0.96寸OLED+原子STM32F4+IIC通信
- 下一篇:立體匹配圖片集數量不多
評論
共有 條評論