資源簡介
1. 繪制帶有光照效果的場景;
2. 場景包含 3 個茶壺,通過鍵盤 123 可以分別選中三個茶壺,然后用鼠標對每個茶壺 進行分別的旋轉;
3. 使用點光源,點光源為白色,以白色的球體表示;
4. 使用 3 個不同的點光源
i. 光源 1 的坐標設置在世界坐標系中,并圍繞著三個茶壺的中心進行圓周運動;
ii. 光源 2 的坐標 設置在觀察坐標系,不發生變化;
iii. 光源 3 的坐標設置在茶壺 1 的物體坐標系中,當茶壺 1 被選中進行旋轉時,光 源 3 要跟隨茶壺 1 做相同的旋轉;

代碼片段和文件信息
//?OpenGL_App.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include?“gl\glew.h“
#include?
#include?
#pragma?comment(lib“glew32.lib“)
#pragma?comment(lib“glew32s.lib“)
#pragma?comment(lib“glut32.lib“)
using?namespace?std;
//?simple?Camera:
struct?simpleCamera
{
float?camera[3];
float?lookat[3];
float?cam[3];
};
enum?LightPositionCoord
{
EYE_SPACE=0
WORLD_SPACE
object_SPACE
};
int?g_renderObj;
bool?isRotatef[4];??//?控制要旋轉的茶壺或旋轉視圖
bool?gLightOpen[3];
float?gRotatefSpeed_1?=?0;?//第一個光源繞三個茶壺的中心旋轉的角度
GLfloat?g_LightPosition1[]?=?{0.0f?0.0f?0.0f?1.0f};?//第一個點光源的位置
GLfloat?g_LightPosition2[]?=?{0.0f?2.0f?5.0f?1.0f};?//第二個點光源的位置
GLfloat?g_LightPosition3[]?=?{-1.5f?0.0f?1.5f?1.0f};?//第三個點光源的位置
GLfloat?g_LightZero[]?=?{0.0f?0.0f?0.0f?1.0f};
static?int?g_mousePos_x?=?0?g_mousePos_y?=?0?g_tmpX?g_tmpY;?
bool?g_rotate=false;
int??g_Counter;
GLint?g_SphereComplexity?=?5;
GLfloat?g_Shininess?=?1;
LightPositionCoord?g_LightPosCoord=EYE_SPACE;
float?g_RotatefY?=?0;
simpleCamera????g_camera;
GLfloat?mat_specular[]?=?{1.0?1.0?1.0?1.0};?//材料的鏡面顏色
GLfloat?mat_emission[]?=?{0.5?0.5?0.5?1.0};?//材料的發射顏色
GLfloat?no_shininess[]?=?{0.0};?//鏡面指數
GLfloat?no_mat[]?=?{0.0?0.0?0.0?1.0};?
GLfloat?high_shininess[]?=?{100.0};
GLfloat?no_specular[]?=??{1.0?1.0?1.0?1.0};
GLfloat?Ambient_Teapot1[]???=?{0.1?0.1?0.1?1.0};??//1號茶壺的材質屬性
GLfloat?Diffuse_Teapot1[]???=?{0.9?0.8?0.0?1.0};
GLfloat?Specular_Teapot1[]??=?{0.9?0.8?0.1?1.0};
GLfloat?Shininess_Teapot1[]?=?{110.0};
GLfloat?Ambient_Teapot2[]???=?{0.5?0.0?0.1?1.0};??//2號茶壺的材質屬性
GLfloat?Diffuse_Teapot2[]???=?{0.1?0.5?0.99?1.0};
GLfloat?Specular_Teapot2[]??=?{0.2?0.1?0.4?1.0};
GLfloat?Shininess_Teapot2[]?=?{10.0};
GLfloat?Emission_Teapot2[]??=?{0.5?0.5?0.0?1.0};
GLfloat?Ambient_Teapot3[]???=?{0.0?0.0?0.99?1.0};??//3號茶壺的材質屬性
GLfloat?Diffuse_Teapot3[]???=?{0.5?0.99?0.5?1.0};
GLfloat?Specular_Teapot3[]??=?{0.0?0.0?0.99?1.0};
GLfloat?Shininess_Teapot3[]?=?{110.0};
void?animate(void);
void?CheckExtensions();
void?display();
void?init();
void?initGLEW();
void?keyboard(unsigned?char?key?int?x?int?y);
void?motion(int?x?int?z);
void?mouse(int?button?int?state?int?x?int?z);
void?reshape(int?w?int?h);
void?createLight();
void?cube();
void?init(void)
{
glClearColor(0.0f?0.0f?0.0f?0.0f);
glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
????gLightOpen[0]?=?gLightOpen[1]?=?gLightOpen[2]?=?true;??//三個光源都開啟
glEnable(GL_DEPTH_TEST);
initGLEW();
CheckExtensions();
createLight();
isRotatef[3]?=?true;?//默認移動鼠?標旋轉整個視圖
g_renderObj?=?0;
}
void?createLight()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat?LightAmbient1[]=?{?1.0f?1.0f?1.0f?1.0f?};
GLfloat?LightDiffuse1[]=?{?1.0f?1.0f?1.0f?1.0f?};
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????160256??2011-10-17?19:37??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\GLUT32.DLL
?????文件??????13495??2011-10-27?00:19??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App\OpenGL_App.cpp
?????文件???????4383??2011-10-17?11:29??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App\OpenGL_App.vcproj
?????文件???????1427??2011-10-27?00:19??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App\OpenGL_App.vcproj.LEI-EBC55AA8CD0.Administrator.user
?????文件????????297??2008-03-06?22:13??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App\stdafx.cpp
?????文件????????376??2008-03-06?22:13??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App\stdafx.h
?????文件????????896??2011-10-17?11:26??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App.sln
????..A..H.?????10752??2011-10-27?00:19??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App.suo
?????文件??????15360??2011-10-23?11:20??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\Teapot_Release.exe
?????文件????????404??2011-11-09?20:35??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\操作說明_ReadMe.txt
?????目錄??????????0??2011-11-09?20:32??OpenGL三茶壺三光源(光源繞著茶壺旋轉)\OpenGL_App
?????目錄??????????0??2011-11-09?20:33??OpenGL三茶壺三光源(光源繞著茶壺旋轉)
-----------?---------??----------?-----??----
???????????????207646????????????????????12
- 上一篇:微機原理與接口技術期末試題及答案
- 下一篇:ICP+NDT點云配準
評論
共有 條評論