資源簡介
本系統繪制了一個真實感的三維場景,并實現場景漫游。使用按鍵↑、↓、←、→或W、S、A、D控制運動方向,PgDn和PgUp可以改變觀察者的高度,鼠標控制轉向,按鍵‘F’可以打開和關閉“霧氣”,Esc退出程序。
本場景中繪制了墻壁與地面、天空、石柱、箱子、玻璃球、雪人、霧等對象。

代碼片段和文件信息
#include?
#include
#include
#include?
#include?
#pragma?comment(?lib?“opengl32.lib“) ?
#pragma?comment(?lib?“glu32.lib“) ?
#pragma?comment(?lib?“glaux.lib“) ?
#define?KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)?&?0x8000)???1?:?0)
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;
int?SCREEN_WIDTH?=800;//屏幕寬???????
int?SCREEN_HEIGHT?=600;//屏幕高
GLfloat?theta?=?0.0f;?//左右旋轉角度
GLfloat?viewUp?=?0.0f;//向上和向下程度
GLfloat?speed?=?0.23f;//運動速度
GLfloat?dis=10;//碰撞檢測保留距離
GLfloat?viewAtPosition[3];//觀察目標位置
GLfloat?eyePosition[3]?=?{0.0f?40.0f?0.0f};?//視點初始位置?
GLfloat?Matblack[]=?????{0.0f?0.0f?0.0f?1.0f};
GLfloat?Matwhite[]=?????{0.7f?0.7f?0.7f?1.0f};
GLfloat?Matred[]=???????{0.6f?0.0f?0.0f?1.0f};
GLfloat?LightAmbient[]=?{0.8f?0.8f?0.8f?1.0f};?
GLfloat?LightDiffuse[]=?{1.0f?1.0f?1.0f?1.0f};
GLfloat?LightPosition[]={1.0f?1.0f?1.0f?0.0f};
GLfloat?mat_specular[]?={1.0f?1.0f?1.0f?1.0f};
GLfloat?mat_shininess?=?100;?//高光度
GLfloat?fogColor[4]=?{0.5f?0.5f?0.5f?0.5f};//霧氣顏色
GLuint texture[10];//紋理標識
GLUquadricObj?*quadratic=gluNewQuadric();;//二次幾何體
GLfloat?rotate=0.0f;//石柱旋轉角度
GLfloat?roll=0;//云層移動量
GLfloat?lightning=0;
bool?thunder=true;//是否打雷
GLboolean?fog=false;//是否開啟霧化
bool?fp;//F鍵是否按下
GLuint EnvTexture;//環境紋理
//*********************************************************************//
//接口集
void?CollDetec(GLfloat?&xGLfloat?&z);
void?SetViewByMouse();
void?Camera();
AUX_RGBImageRec?*LoadBMP(char?*Filename);
int?LoadGLTextures();
GLuint?EmptyTexture();
int?InitGL(GLvoid);
void?DrawCave();
void?DrawBox();
void?DrawSnowMan();
void?Drawcylinder();
void?DrawGlassBall();
void?DrawSky();
int?DrawGLScene(GLvoid);
GLvoid?ReSizeGLScene(GLsizei?width?GLsizei?height);
GLvoid?KillGLWindow(GLvoid);
BOOL?CreateGLWindow(char*?title?int?width?int?height?int?bits?bool?fullscreenflag);
LRESULT CALLBACK?WndProc(HWND?UINT?WPARAM?LPARAM);
//*********************************************************************//
//改變寬口大小
GLvoid?ReSizeGLScene(GLsizei?width?GLsizei?height)
{
if?(height==0)
{
height=1;
}
glViewport(00widthheight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f(GLfloat)width/(GLfloat)height0.1f1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
?
//碰撞檢測防止視點穿過物體
void??CollDetec(GLfloat?&xGLfloat?&z)
{
if?(x<-(50-dis))x=?-(50-dis);//房間
if?(x>?(50-dis))x=?50-dis;
if?(z<-(300-dis))z=?-(300-dis);
if?(z>?(300-dis))z=?300-dis;
if?(z>=-170&&z<=-150&&x>(30-dis)&&eyePosition[1]<=60)x=30-dis;//箱子與玻璃球
if?(x>=30&&z>=-170&&z<-(150-dis)&&eyePosition[1]<=60)z=-(150-dis);
if?(x>=30&&z<=-150&&z>-(170+dis)&&eyePosition[1]<=60)z=-(170+dis);
if?(z>=150&&z<=170&&x<-(30-dis)&&eyePosition[1]<=55)?x=-(30-dis);//雪人
if?(x<=-30&&z<=170&&z>(150-dis)&&eyePosition[1]<=55)z=(150-dis);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????120056??2016-01-17?20:32??Scene\Scene\Data\Box.bmp
?????文件?????196664??2016-01-17?22:54??Scene\Scene\Data\Cylinder.bmp
?????文件?????196664??2016-01-16?12:06??Scene\Scene\Data\Door.bmp
?????文件?????196664??2016-01-16?12:56??Scene\Scene\Data\Floor.bmp
?????文件???????9272??2016-01-17?19:33??Scene\Scene\Data\Hat.bmp
?????文件?????800312??2016-01-18?19:13??Scene\Scene\Data\Lightning.bmp
?????文件?????132152??2016-01-18?16:18??Scene\Scene\Data\Mask.bmp
?????文件?????393272??2016-01-18?16:15??Scene\Scene\Data\Sky.bmp
?????文件?????393272??2016-01-18?11:23??Scene\Scene\Data\Star.bmp
?????文件?????327184??2016-01-18?20:26??Scene\Scene\Data\Thunder.wav
?????文件?????196664??2016-01-16?12:58??Scene\Scene\Data\Wall.bmp
?????文件????????606??2016-01-21?00:08??Scene\Scene\Debug\cl.command.1.tlog
?????文件??????13270??2016-01-21?00:08??Scene\Scene\Debug\CL.read.1.tlog
?????文件????????312??2016-01-21?00:08??Scene\Scene\Debug\CL.write.1.tlog
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件??????????2??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件???????2298??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件???????5716??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件????????694??2016-01-21?00:08??Scene\Scene\Debug\li
?????文件?????100871??2016-01-21?00:08??Scene\Scene\Debug\main.obj
?????文件????????364??2016-01-21?00:08??Scene\Scene\Debug\mt.command.1.tlog
?????文件????????398??2016-01-21?00:08??Scene\Scene\Debug\mt.read.1.tlog
?????文件????????294??2016-01-21?00:08??Scene\Scene\Debug\mt.write.1.tlog
?????文件????????492??2016-01-21?00:08??Scene\Scene\Debug\rc.command.1.tlog
?????文件????????370??2016-01-21?00:08??Scene\Scene\Debug\rc.read.1.tlog
?????文件????????274??2016-01-21?00:08??Scene\Scene\Debug\rc.write.1.tlog
............此處省略21個文件信息
- 上一篇:上興遠控2012
- 下一篇:會議管理系統的分析與設計
評論
共有 條評論