資源簡介
此程序使用Opengl繪制了帶6個紋理的立方體(立方體的每個面用bezier曲面表示),實現了鍵盤和鼠標控制,其中鍵盤控制如下:
L :控制光照光照
←:向左旋轉速度增加
→:向右旋轉速度增加
↑:向上旋轉速度增加
↓:向下旋轉速度增加
PgUp:立方體向屏幕里移動(離觀察者越來越遠)
PgUp: 立方體向屏幕外移動(離觀察者越來越近)
鼠標控制如下:
右鍵:控制光照
左鍵:按下左鍵時可以進行立方體的拖拽使之旋轉
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
HWND hWnd;
HDC hDC;
HGLRC hRC=NULL; //定義渲染環境
HINSTANCE hInstance; //得到程序的例子
RECT rect;
int sw?=?640;
int sh?=?480;
bool fullscreen??=?1;
GLfloat aspect;
GLfloat xrot; //?X軸旋轉
GLfloat yrot; //?Y軸旋轉
GLfloat?xspeed; //?X軸旋轉速度
GLfloat?yspeed; //?Y軸旋轉速度
GLfloat z=-5.0f; //?移入屏幕的深度
int?????LastXPosLastYPos;
bool?IsLBDown;
bool light; //光源-開/關
bool lp; //L鍵是否按下??
GLfloat?LightAmbient[]= {?0.5f?0.5f?0.5f?1.0f?}; //環境光的值
GLfloat?LightDiffuse[]= {?1.0f?1.0f?1.0f?1.0f?}; //散射光的值
GLfloat?LightPosition[]= {?0.0f?0.0f?2.0f?1.0f?}; //光照位置
GLuint texture[6]; //紋理的存儲空間
float?array[1000][3];
int?c_i=0;
#pragma?comment(?lib?“opengl32.lib“?) //?鏈接時使用OpenGL32.lib
#pragma?comment(?lib?“glu32.lib“?) //?鏈接時使用GLu32.lib?
#pragma?comment(?lib?“glaux.lib“?) //?鏈接時使用GLaux.lib
AUX_RGBImageRec?*TextureImage[6]; //為紋理創建存儲空間
GLUnurbsObj?*?theNurb;
GLUnurbsObj?*theNurb1;
GLUnurbsObj?*theNurb2;
GLfloat?ctrlpoints[5][5][3]?=?{{{-30.50}{-11.50}{-220}{1-10}{-500}}
{{-30.5-1}{-11.5-1}{-22-1}{1-1-1}{-50-1}}
{{-30.5-2}{-11.5-2}{-22-2}{1-1-2}{-50-2}}
{{-30.5-3}{-11.5-3}{-22-3}{1-1-3}{-50-3}}
{{-30.5-4}{-11.5-4}{-22-4}{1-1-4}{-50-4}}};//控制點
void?__stdcall?CALLBACK?beginCallback(GLenum?Type)
{
?glBegin(Type);
}
void?__stdcall?CALLBACK?endCallback()
{
?glEnd();
}
void?__stdcall?CALLBACK?vertexCallback(GLfloat?*vertex)
{
?glVertex3fv(vertex);
?array[c_i][?0?]=vertex[?0?];
?array[c_i][?1?]=vertex[?1?];
?array[c_i][?2?]=vertex[?2?];
?c_i++;
}
typedef??struct??point_3D{
GLdouble??xyz;
}POINT_3D;
typedef?struct?bpatch?{?//?Structure?For?A?3rd?Degree?Bezier?Patch?(?NEW?)
POINT_3D?anchors[4][4];?//?4x4?Grid?Of?Anchor?Points
GLuint?dlBPatch;?//?Display?List?For?Bezier?Patch
GLuint?texture;?//?Texture?For?The?Patch
}?BEZIER_PATCH;
POINT_3D?pointAdd(POINT_3D?p?POINT_3D?q)?{
p.x?+=?q.x;??p.y?+=?q.y;??p.z?+=?q.z;
return?p;
}
//?Multiplies?A?Point?And?A?Constant.?Don‘t?Just?Use?‘*‘
POINT_3D?pointTimes(double?c?POINT_3D?p)?{
p.x?*=?c;?p.y?*=?c;?p.z?*=?c;
return?p;
}
//?Function?For?Quick?Point?Creation
POINT_3D?makePoint(double?a?double?b?double?c)?{
POINT_3D?p;
p.x?=?a;?p.y?=?b;?p.z?=?c;
return?p;
}
POINT_3D?Bernstein(float?u?POINT_3D?*p)?{
POINT_3D?a?b?c?d?r;
a?=?pointTimes(pow(u3)?p[0]);
b?=?pointTimes(3*pow(u2)*(1-u)?p[1]);
c?=?pointTimes(3*u*pow((1-u)2)?p[2]);
d?=?pointTimes(pow((1-u)3)?p[3]);
r?=?pointAdd(pointAdd(a?b)?pointAdd(c?d));
return?r;
}
BEZIER_PATCH??mybezier;
void?initBezier(void)?{
mybezier.anchors[0][0]?=?makePoint(-0.75?-0.75?-0.50);?//?Set?The?Bezier?Vertices
mybezier.anchors[0][1]?=?m
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-07-16?21:54??bezier曲面的紋理貼圖、鼠標交互與光照\
?????目錄???????????0??2012-07-16?21:56??bezier曲面的紋理貼圖、鼠標交互與光照\Backup\
?????文件?????????203??2010-05-31?20:47??bezier曲面的紋理貼圖、鼠標交互與光照\Backup\MouseAndLight.sln
?????文件????????7168??2010-05-31?20:47??bezier曲面的紋理貼圖、鼠標交互與光照\Backup\MouseAndLight.suo
?????目錄???????????0??2012-07-16?21:56??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\
?????文件???????10632??2008-05-27?15:14??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\BuildLog.htm
?????文件???????40900??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\CL.read.1.tlog
?????文件????????1076??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\CL.write.1.tlog
?????文件????????2873??2012-05-31?21:54??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.Build.CppClean.log
?????文件??????524800??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.exe
?????文件?????????406??2012-05-31?21:54??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.exe.em
?????文件?????????472??2012-06-19?17:03??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.exe.em
?????文件?????????381??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.exe.intermediate.manifest
?????文件?????1368492??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.ilk
?????文件??????????87??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.lastbuildstate
?????文件????????2733??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.log
?????文件???????71353??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.obj
?????文件?????2509824??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight.pdb
?????文件?????????222??2012-05-31?21:54??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\MouseAndLight_manifest.rc
?????文件????????2144??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\cl.command.1.tlog
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
?????文件???????????2??2012-07-16?20:42??bezier曲面的紋理貼圖、鼠標交互與光照\Debug\li
............此處省略190個文件信息
評論
共有 條評論