首页 开发技术 C++     /    3D迷宫(源代码+演示程序)

3D迷宫(源代码+演示程序)

上传者: jiangcaiyang123 | 上传时间:2023/9/28 16:29:52 | 文件大小:737KB | 文件类型:7z
3D迷宫(源代码+演示程序)
前面几日我重新实现了迷宫的自动生成方法,并且添加了迷宫自动寻路方法。
有了一个独立于GUI的迷宫库,我开始迫不及待地实现三维迷宫了!下面是我在开发迷宫程序中遇到的问题。
1、怎样将迷宫类的行和列映射到真实的三维坐标中?迷宫应该用哪个参考系来描述?其实我在制作的时候为了简化,将二维迷宫的左上角与三维的原点重合,二维迷宫的右对应三维的X轴正方向,迷宫的下对应Z轴的正方向。
2、迷宫的“上、下、左、右”在三维中应该叫做什么?在确定好迷宫的位置后,我们将迷宫的上对应Z轴的负半轴,下对应Z轴的正半轴,左对应X轴的负半轴,右对应Y轴的正半轴。
3、三维点绘制顺序以及OpenGL裁剪模式造成的一些面不可见问题。
这个问题是我在编写二维迷宫没有想到的。
主要是因为二维迷宫中描述墙是用一条直线,而到了三维则是一个面。
由于在OpenGL中有裁剪模式可以选择,我使用了glFrontFace(GL_CW);//顺时针的绘制为正面glEnable(GL_CULL_FACE);//剔除不是正面的面进行设定,也就是说,所有在摄像机看来是逆时针绘制的图形都无法显示。
因此我不得不用同样的顶点绘制两个面。
下面是相关的函数:voidDrawInnerWall(Point3F&p1,Point3F&p2,Point3F&p3,Point3F&p4){glTexCoord2f(0.0f,1.0f);glVertex3fv(p1);glTexCoord2f(1.0f,1.0f);glVertex3fv(p2);glTexCoord2f(1.0f,0.0f);glVertex3fv(p3);glTexCoord2f(0.0f,0.0f);glVertex3fv(p4);}voidDrawOuterWall(Point3F&p1,Point3F&p2,Point3F&p3,Point3F&p4){glTexCoord2f(1.0f,1.0f);glVertex3fv(p1);glTexCoord2f(0.0f,1.0f);glVertex3fv(p2);glTexCoord2f(0.0f,0.0f);glVertex3fv(p3);glTexCoord2f(1.0f,0.0f);glVertex3fv(p4);}在编写这些函数的时候尤其注意纹理坐标的绘制顺序。
可以在纸上绘制一个草图。
下面是我调用的代码:if(Cell_UpWall(cell)){DrawInnerWall(p8,p7,p3,p4);DrawOuterWall(p7,p8,p4,p3);}4、怎样设置阻挡?设置阻挡的基本原则还是先检测后执行。
首先我先尝试着执行走一步,再判断这一步是不是出现了越界问题。
如果出现了越界问题,那么不执行这一步,否则执行这一步。
为了不让我们无限地靠近墙,我设定了一个gap,即摄像机必须与墙保持gap的距离。
下面是我相关的代码:boolView3D::CanGo(Maze&maze,floatstep){staticfloatgap=m_CellSize.w/8.0f;//摄像机与墙最近不能超过的间隔constPoint3F&pos=m_Camera.Pos();Point3FtryPos;if(pos.y>0&&pos.y(row-1)*m_CellSize.w);if(

文件下载

资源详情

[{"title":"(43个子文件737KB)3D迷宫(源代码+演示程序)","children":[{"title":"project","children":[{"title":"LuaInclude.cpp <span style='color:#111;'>578B</span>","children":null,"spread":false},{"title":"Maze.h <span style='color:#111;'>2.10KB</span>","children":null,"spread":false},{"title":"libLogo_X11.a <span style='color:#111;'>15.65KB</span>","children":null,"spread":false},{"title":"Lua","children":[{"title":"lualib.h <span style='color:#111;'>1.07KB</span>","children":null,"spread":false},{"title":"lua.h <span style='color:#111;'>13.22KB</span>","children":null,"spread":false},{"title":"lauxlib.h <span style='color:#111;'>7.17KB</span>","children":null,"spread":false},{"title":"luaconf.h <span style='color:#111;'>14.97KB</span>","children":null,"spread":false}],"spread":true},{"title":"View3D.h <span style='color:#111;'>904B</span>","children":null,"spread":false},{"title":"libLua_win32.a <span style='color:#111;'>241.49KB</span>","children":null,"spread":false},{"title":"TGAFile.h <span style='color:#111;'>1.73KB</span>","children":null,"spread":false},{"title":"GLWidget.h <span style='color:#111;'>1.52KB</span>","children":null,"spread":false},{"title":"libLua_X11.a <span style='color:#111;'>337.26KB</span>","children":null,"spread":false},{"title":"View2D.h <span style='color:#111;'>826B</span>","children":null,"spread":false},{"title":"Logo.h <span style='color:#111;'>428B</span>","children":null,"spread":false},{"title":"libTGA_win32.a <span style='color:#111;'>6.18KB</span>","children":null,"spread":false},{"title":"Camera.h <span style='color:#111;'>838B</span>","children":null,"spread":false},{"title":"libMaze_win32.a <span style='color:#111;'>15.28KB</span>","children":null,"spread":false},{"title":"libMaze_X11.a <span style='color:#111;'>21.91KB</span>","children":null,"spread":false},{"title":"libLogo_win32.a <span style='color:#111;'>10.93KB</span>","children":null,"spread":false},{"title":"Math3D.h <span style='color:#111;'>4.08KB</span>","children":null,"spread":false},{"title":"libTGA_X11.a <span style='color:#111;'>9.34KB</span>","children":null,"spread":false},{"title":"Math3D.cpp <span style='color:#111;'>2.58KB</span>","children":null,"spread":false},{"title":"LuaInclude.h <span style='color:#111;'>342B</span>","children":null,"spread":false},{"title":"Maze3DProject.pro <span style='color:#111;'>975B</span>","children":null,"spread":false},{"title":"KeyEvent.cpp <span style='color:#111;'>486B</span>","children":null,"spread":false},{"title":"View3D.cpp <span style='color:#111;'>6.28KB</span>","children":null,"spread":false},{"title":"libCamera_X11.a <span style='color:#111;'>6.65KB</span>","children":null,"spread":false},{"title":"main.cpp <span style='color:#111;'>2.29KB</span>","children":null,"spread":false},{"title":"TextureUtil.h <span style='color:#111;'>2.12KB</span>","children":null,"spread":false},{"title":"GLWidget.cpp <span style='color:#111;'>6.36KB</span>","children":null,"spread":false},{"title":"KeyEvent.h <span style='color:#111;'>230B</span>","children":null,"spread":false},{"title":"libCamera_win32.a <span style='color:#111;'>3.92KB</span>","children":null,"spread":false},{"title":"View2D.cpp <span style='color:#111;'>5.54KB</span>","children":null,"spread":false}],"spread":false},{"title":"bin","children":[{"title":"Resource","children":[{"title":"WallPaper.tga <span style='color:#111;'>188.58KB</span>","children":null,"spread":false},{"title":"ExitHint.tga <span style='color:#111;'>42.29KB</span>","children":null,"spread":false},{"title":"Luo_Tianyi.tga <span style='color:#111;'>389.70KB</span>","children":null,"spread":false}],"spread":true},{"title":"Config.lua <span style='color:#111;'>497B</span>","children":null,"spread":false},{"title":"Windows","children":[{"title":"glut32.dll <span style='color:#111;'>166.00KB</span>","children":null,"spread":false},{"title":"Maze3D.exe <span style='color:#111;'>564.00KB</span>","children":null,"spread":false}],"spread":true},{"title":"Linux","children":[{"title":"Maze3D <span style='color:#111;'>187.53KB</span>","children":null,"spread":false},{"title":"libglut.so.3 <span style='color:#111;'>207.50KB</span>","children":null,"spread":false},{"title":"加完权限后请运行我!.sh <span style='color:#111;'>235B</span>","children":null,"spread":false}],"spread":true},{"title":"Manual(操作手册).txt <span style='color:#111;'>1.34KB</span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

  • historyme:
    要评价才能重新下载2018-01-13
  • gerard_qiu:
    不能运行...只能看看代码2016-10-22
  • ccccchhhhh_____:
    对我自己编程还是没有直接的帮助。2016-09-23
  • 永远的魔术1号:
    用了6分,却下载失败,这是什么鬼啊2016-07-12
  • u011015122:
    代码比较乱,许多类只有头文件,没有对应的实现。很多地方缺少必要的注释,也没有整个工程的说明文件。如果要0分,尚可给中评,要高达6分,只能给差评。另外,这个工程是qt的工程,用qtcreator打开,2016-03-16

免责申明

【好快吧下载】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【好快吧下载】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【好快吧下载】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,8686821#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明