此程序使用Opengl绘制了带6个纹理的立方体(立方体的每个面用bezier曲面表示),实现了键盘和鼠标控制,其中键盘控制如下:
L :控制光照光照
←:向左旋转速度增加
→:向右旋转速度增加
↑:向上旋转速度增加
↓:向下旋转速度增加
PgUp:立方体向屏幕里移动(离观察者越来越远)
PgUp: 立方体向屏幕外移动(离观察者越来越近)
鼠标控制如下:
右键:控制光照
左键:按下左键时可以进行立方体的拖拽使之旋转
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-07-16 21:54 bezier曲面的纹理贴图、鼠标交互与光照
目录 0 2012-07-16 21:56 bezier曲面的纹理贴图、鼠标交互与光照Backup
文件 203 2010-05-31 20:47 bezier曲面的纹理贴图、鼠标交互与光照BackupMouseAndLight.sln
文件 7168 2010-05-31 20:47 bezier曲面的纹理贴图、鼠标交互与光照BackupMouseAndLight.suo
目录 0 2012-07-16 21:56 bezier曲面的纹理贴图、鼠标交互与光照Debug
文件 10632 2008-05-27 15:14 bezier曲面的纹理贴图、鼠标交互与光照DebugBuildLog.htm
文件 40900 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugCL.read.1.tlog
文件 1076 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugCL.write.1.tlog
文件 2873 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.Build.CppClean.log
文件 524800 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe
文件 406 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.embed.manifest
文件 472 2012-06-19 17:03 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.embed.manifest.res
文件 381 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.intermediate.manifest
文件 1368492 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.ilk
文件 87 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.lastbuildstate
文件 2733 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.log
文件 71353 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.obj
文件 2509824 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.pdb
文件 222 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight_manifest.rc
文件 2144 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugcl.command.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink-cvtres.read.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink-cvtres.write.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1036-cvtres.read.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1036-cvtres.write.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1036.read.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1036.write.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1048-cvtres.read.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1048-cvtres.write.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1048.read.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1048.write.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debuglink.1352-cvtres.read.1.tlog
............此处省略190个文件信息
#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曲面的纹理贴图、鼠标交互与光照BackupMouseAndLight.sln
文件 7168 2010-05-31 20:47 bezier曲面的纹理贴图、鼠标交互与光照BackupMouseAndLight.suo
目录 0 2012-07-16 21:56 bezier曲面的纹理贴图、鼠标交互与光照Debug
文件 10632 2008-05-27 15:14 bezier曲面的纹理贴图、鼠标交互与光照DebugBuildLog.htm
文件 40900 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugCL.read.1.tlog
文件 1076 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugCL.write.1.tlog
文件 2873 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.Build.CppClean.log
文件 524800 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe
文件 406 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.em
文件 472 2012-06-19 17:03 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.em
文件 381 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.exe.intermediate.manifest
文件 1368492 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.ilk
文件 87 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.lastbuildstate
文件 2733 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.log
文件 71353 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.obj
文件 2509824 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight.pdb
文件 222 2012-05-31 21:54 bezier曲面的纹理贴图、鼠标交互与光照DebugMouseAndLight_manifest.rc
文件 2144 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugcl.command.1.tlog
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
文件 2 2012-07-16 20:42 bezier曲面的纹理贴图、鼠标交互与光照Debugli
............此处省略190个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)