资源描述:
《最简单的迷宫.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、最简单的迷宫程序的效果Corridor.xRoom.x步骤搭建基本框架创建Win32项目删除不必要的代码,只保留_tWinMain(){}包含框架文件创建自己的应用程序类添加cApp类,并修改WinMain中的代码。按照设计,添加网格对象和三维对象添加其他成员变量完成Init实现初始化的操作完成Frame实现对每一帧的操作完成Shutdown实现退出时的清理工作1.1创建Win32项目添加对应的库文件d3d9.libd3dx9.libd3dxof.libdxguid.libdinput8.libwinmm.lib1.2删除不必要的代码1.3包含框
2、架文件(1)1.3包含框架文件(2)1.3包含框架文件(3)有什么作用?1.3包含框架文件(4)2.1创建自己的应用程序类(1)2.1修改WinMain函数(2)添加网格和三维对象cMesh表示网格对象cObject表示三维对象cMeshm_RoomMeshes[2];//两个网格cObjectm_RoomObjects[8];//八个对象添加其他成员变量cGraphicsm_Graphics;//GraphicsobjectcCameram_Camera;//CameracInputm_Input;//InputobjectcInputDevi
3、cem_Keyboard;//KeyboarddeviceobjectcInputDevicem_Mouse;//Mouesdeviceobjectfloatm_XPos,m_ZPos;//Viewpointposition完成构造函数cApp::cApp()cApp::cApp(void){m_Width=640;m_Height=480;m_Style=WS_BORDER
4、WS_CAPTION
5、WS_MINIMIZEBOX
6、WS_SYSMENU;strcpy(m_Class,"MeshLvlClass");strcpy(m_Caption,"
7、MeshLvlDemobyCCNIIT");}覆盖cApplication中的关键函数boolInit()boolFrame()boolShutdown()Init()初始化Frame()帧计算Shutdown()清理在Init中进行初始化的操作//Initializethegraphicsdeviceandsetdisplaymodem_Graphics.Init();m_Graphics.SetMode(GethWnd(),TRUE,TRUE);m_Graphics.SetPerspective(D3DX_PI/4,1.3333f,1.0f
8、,10000.0f);ShowMouse(TRUE);//Initializeinputandinputdevicesm_Input.Init(GethWnd(),GethInst());m_Keyboard.Create(&m_Input,KEYBOARD);m_Mouse.Create(&m_Input,MOUSE,TRUE);加载网格模型//Loadtheroommeshesm_RoomMeshes[0].Load(&m_Graphics,"..\Data\Corridor.x","..\Data\");m_RoomMeshes[
9、1].Load(&m_Graphics,"..\Data\Room.x","..\Data\");创建三维物体//Setuptheroomobjectsm_RoomObjects[0].Create(&m_Graphics,&m_RoomMeshes[1]);//房间m_RoomObjects[1].Create(&m_Graphics,&m_RoomMeshes[0]);//走廊m_RoomObjects[2].Create(&m_Graphics,&m_RoomMeshes[1]);m_RoomObjects[3].Create(&
10、m_Graphics,&m_RoomMeshes[0]);m_RoomObjects[4].Create(&m_Graphics,&m_RoomMeshes[0]);m_RoomObjects[5].Create(&m_Graphics,&m_RoomMeshes[1]);m_RoomObjects[6].Create(&m_Graphics,&m_RoomMeshes[0]);m_RoomObjects[7].Create(&m_Graphics,&m_RoomMeshes[1]);放好位置//Moveroomobjectsintopositi
11、onm_RoomObjects[0].Move(-2000.0f,0.0f,2000.0f);m_RoomObjects[1].Move