Main.cpp
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:17k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. //************************************************************************************************
  2. //                     2007年春《计算机图形学》课程大作业                                       **
  3. //      课题:海洋模拟系统
  4. // 课题描述:此系统充分考虑了海洋环境中各个因素,包括实现海面的起伏,物体在海面上的倒影    **
  5. // 水下物体的折射,太阳在海面上产生的粼粼波光,大气中雾气的影响,丰富变化的天气效果    **
  6. //          诸如降雪,日出日落,阴晴转换,海上明月的美丽景色,天空盒实现了云彩的漂移,此外系    **
  7. //          统中还载入了舰船模型,并可以让用户进行控制,而其中最有价值的是我们通过对二维偏微    **
  8. //          波方程的离散数值求解,实现了船在行进时在水面生成的尾迹。                            **
  9. // 使用技术:多重Perlin噪声场的叠加,投影网格无限平面绘制技术,菲涅尔效应,数值求解二维    **
  10. // 偏微波方程。 // 小组成员    徐潇然、杨阳、房路 **
  11. //
  12. //************************************************************************************************
  13. #include <Windows.h>
  14. #include <mmsystem.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <DShow.h>
  20. //-----------------------------------------
  21. #include "comman.h"
  22. #include "dxmouse.h"
  23. #include "camera.h"
  24. #include "Sea.h"
  25. #include "Configuration.h"
  26. #include "NoiseGenerator.h"
  27. #include "MeshObj.h"
  28. #include "ParticleSystem.h"
  29. #include "BoatWave.h"
  30. #include "skydome.h"
  31. #include "weather.h"
  32. #include "weathercontrol.h"
  33. #include "trailfrag.h"
  34. #include "ddutil.h"
  35. //-----------------------------------------
  36. // *****主场景*****
  37. CSea *sea;
  38. CSkyDome *skydome;
  39. CSnow *snow;
  40. CWeatherControl *weatherctrl;
  41. int gridsize_x = 128, gridsize_y = 256;
  42. long int ssss,tttt;
  43. // *****输入控制*****
  44. // 1 鼠标
  45. dxmouse *mouse;
  46. // 2 键盘
  47. bool keys[256];
  48. // *****3D模型*****
  49. enum objName_3d
  50. {
  51. island_3d,
  52. boat_3d,
  53. underwater_island_3d,
  54. beacon_3d,
  55. island2_3d,
  56. ship_3d,
  57. carrier_3d
  58. };
  59. #define num_3d 7
  60. CMeshObj *g_ppMeshObj[num_3d];
  61. // *****参量集*****
  62. CConfiguration *config;
  63. // *****视角*****
  64. #define n_cameras 3
  65. CCamera *cameras[n_cameras];
  66. int current_camera = 0;
  67. bool camera_boat = false;
  68. // *****粒子系统*****
  69. CParticleSystem *g_pParticleSystem;
  70. // *****船尾迹*****
  71. CBoatWave *pWave;
  72. // D3D全局变量
  73. LPDIRECT3D9             g_pD3D = NULL; 
  74. LPDIRECT3DDEVICE9       g_pd3dDevice = NULL; 
  75. LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; 
  76. LPDIRECT3DVERTEXBUFFER9 g_pVBproj = NULL; 
  77. LPDIRECT3DVERTEXBUFFER9 g_referencePlaneVB = NULL;
  78. LPD3DXFONT g_pd3dxFont = NULL;
  79. LPDIRECT3DSURFACE9 g_depthstencil = NULL;
  80. LPDIRECT3DTEXTURE9 terrain_texture = NULL;
  81. LPD3DXEFFECT terrain_effect = NULL;
  82. D3DLIGHT9 sun;
  83. // 背景音乐部分
  84. long int currentT, lastT;
  85. /* 指向Filter Graph的指针,用于控制声音的播放 */
  86. IGraphBuilder *pGraph;  
  87. IMediaControl *pMediaControl; 
  88. void TestMP3(LPCWSTR  xxx)
  89. {  
  90. CoInitialize(NULL); 
  91. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGraph);
  92. pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); 
  93. pGraph->RenderFile(xxx, NULL); 
  94. pMediaControl->Run();   
  95. //pMediaControl->Stop();  //Pause();
  96. /* 停止播放 */  
  97. //pMediaControl->Release(); 
  98. /* 释放对象 */ 
  99. //pGraph->Release();  
  100. /* 程序结束时调用 */  
  101. //CoUninitialize();
  102. }
  103. //-----------------------------------------------------------------------------
  104. // 初始化D3D的有关设置
  105. // 说明:g_pD3D,g_pd3dDevice,g_depthstencil被赋值
  106. //-----------------------------------------------------------------------------
  107. HRESULT InitD3D( HWND hWnd )
  108. {
  109. HRESULT hr;
  110. // 创建D3D对象
  111. if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
  112. return E_FAIL;
  113. // 创建D3D设备
  114. D3DPRESENT_PARAMETERS d3dpp;
  115. ZeroMemory( &d3dpp, sizeof(d3dpp) );
  116. d3dpp.Windowed = TRUE;
  117. d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  118. d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  119. d3dpp.EnableAutoDepthStencil = TRUE;
  120. d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
  121. d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  122. if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  123. D3DCREATE_HARDWARE_VERTEXPROCESSING,
  124. &d3dpp, &g_pd3dDevice ) ) )
  125. {
  126. return E_FAIL;
  127. }
  128. g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW  );
  129. g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
  130. g_pd3dDevice->GetDepthStencilSurface(&g_depthstencil);
  131. return S_OK;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // 总初始化函数
  135. // 说明: 初始化所有的类
  136. //-----------------------------------------------------------------------------
  137. HRESULT InitGeometry(HWND hWnd, HINSTANCE hInst)
  138. {
  139. // 初始化视角类
  140. cameras[0] = new CCamera(D3DXVECTOR3(0,45,-150),0,0,0,45,1.33,0.3,5000.0);
  141. // 初始化参量集
  142. config = new CConfiguration();
  143. config->set_float( p_bReflRefrStrength,0.1f );
  144. config->set_float( p_bNight_Day, 1);
  145. config->set_float( p_fWaterColourR, 0.12f );
  146. config->set_float( p_fWaterColourG, 0.22f );
  147. config->set_float( p_fWaterColourB, 0.29f );
  148. config->set_float( p_fLODbias, 10.0f);
  149. config->set_bool( p_bDiffuseRefl, true );
  150. config->set_float( p_fSunPosAlpha, 0.0f );
  151. config->set_float( p_fSunPosTheta, 0.5f);
  152. config->set_float( p_fSunShininess, 1263.0f );
  153. config->set_float( p_fSunStrength, 208.0f );
  154. config->set_bool(p_bisSnowing, false);
  155. config->set_bool(p_bFogActive, true);
  156. // 初始话鼠标控制
  157. mouse = new dxmouse(hWnd,hInst);
  158. mouse->Init();
  159. // 初始化各种模型对象
  160. cmeshobjconfig cm_config[num_3d];
  161. cm_config[island_3d].draw_mtrls_state = have_mtrls;
  162. cm_config[island_3d].draw_texs_state = load_texs;
  163. cm_config[island_3d].movement_mode = is_land;
  164. cm_config[island_3d].rotate = D3DXVECTOR3(0, 0, 0);
  165. cm_config[island_3d].translate  = D3DXVECTOR3(1000, 100, 2000);
  166. cm_config[island_3d].scale = D3DXVECTOR3(5, 2, 10);
  167. g_ppMeshObj[island_3d] = new CMeshObj(g_pd3dDevice, "models\island.x", &cm_config[island_3d]);
  168. g_ppMeshObj[island_3d]->Init();
  169. g_ppMeshObj[island_3d]->LoadTexture("textures\hill_tex3.png", -1);
  170. g_ppMeshObj[island_3d]->LoadEffect("fx\Underwater.fx");
  171. cm_config[island2_3d].draw_mtrls_state = have_mtrls;
  172. cm_config[island2_3d].draw_texs_state = load_texs;
  173. cm_config[island2_3d].movement_mode = is_land;
  174. cm_config[island2_3d].rotate = D3DXVECTOR3(0, 0, 0);
  175. cm_config[island2_3d].translate  = D3DXVECTOR3(80, 30, 00);
  176. cm_config[island2_3d].scale = D3DXVECTOR3(1, 5, 1);
  177. g_ppMeshObj[island2_3d] = new CMeshObj(g_pd3dDevice, "models\island.x", &cm_config[island2_3d]);
  178. g_ppMeshObj[island2_3d]->Init();
  179. g_ppMeshObj[island2_3d]->LoadTexture("textures\hill_tex3.png", -1);
  180. g_ppMeshObj[island2_3d]->LoadEffect("fx\Underwater.fx");
  181. cm_config[underwater_island_3d].draw_mtrls_state = have_mtrls;
  182. cm_config[underwater_island_3d].draw_texs_state = load_texs;
  183. cm_config[underwater_island_3d].movement_mode = is_land;
  184. cm_config[underwater_island_3d].rotate = D3DXVECTOR3(0, 0, 0);
  185. cm_config[underwater_island_3d].translate  = D3DXVECTOR3(1000, -5, 1900);
  186. cm_config[underwater_island_3d].scale = D3DXVECTOR3(15, 1, 15);
  187. g_ppMeshObj[underwater_island_3d] = new CMeshObj(g_pd3dDevice, "models\island.x", &cm_config[underwater_island_3d]);
  188. g_ppMeshObj[underwater_island_3d]->Init();
  189. g_ppMeshObj[underwater_island_3d]->LoadTexture("textures\hill_tex3.png", -1);
  190. g_ppMeshObj[underwater_island_3d]->LoadEffect("fx\Underwater.fx");
  191. cm_config[beacon_3d].draw_mtrls_state = have_mtrls;
  192. cm_config[beacon_3d].draw_texs_state = load_texs;
  193. cm_config[beacon_3d].movement_mode = fixed_up_sea;
  194. cm_config[beacon_3d].rotate = D3DXVECTOR3(0, 0, 0);
  195. cm_config[beacon_3d].translate = D3DXVECTOR3(1000, 100, 2000);
  196. cm_config[beacon_3d].scale = D3DXVECTOR3(0.1, 0.1, 0.1);
  197. g_ppMeshObj[beacon_3d] = new CMeshObj(g_pd3dDevice, "models\beacon_3d.x", &cm_config[beacon_3d]);
  198. g_ppMeshObj[beacon_3d]->Init();
  199. g_ppMeshObj[underwater_island_3d]->LoadTexture("textures\hill_tex3.png", -1);
  200. cm_config[boat_3d].draw_mtrls_state = have_mtrls;
  201. cm_config[boat_3d].draw_texs_state = have_texs;
  202. cm_config[boat_3d].movement_mode = moving_on_sea;
  203. cm_config[boat_3d].rotate = D3DXVECTOR3(0, D3DX_PI/2, 0);
  204. cm_config[boat_3d].translate = D3DXVECTOR3(10, -1, -40);
  205. cm_config[boat_3d].scale = D3DXVECTOR3(5, 5, 5);
  206. g_ppMeshObj[boat_3d] = new CMeshObj(g_pd3dDevice, "models\warship4.x", &cm_config[boat_3d]);
  207. g_ppMeshObj[boat_3d]->Init();
  208. g_ppMeshObj[boat_3d]->gpu_tex = 1;
  209. g_ppMeshObj[boat_3d]->LoadEffect("fx\Underwater.fx");
  210. cm_config[ship_3d].draw_mtrls_state = have_mtrls;
  211. cm_config[ship_3d].draw_texs_state = have_texs;
  212. cm_config[ship_3d].movement_mode = is_land;
  213. cm_config[ship_3d].rotate = D3DXVECTOR3(0, D3DX_PI/5, 0);
  214. cm_config[ship_3d].translate = D3DXVECTOR3(-600, -5, 50);
  215. cm_config[ship_3d].scale = D3DXVECTOR3(8, 8, 8);
  216. g_ppMeshObj[ship_3d] = new CMeshObj(g_pd3dDevice, "models\warship2.x", &cm_config[ship_3d]);
  217. g_ppMeshObj[ship_3d]->Init();
  218. g_ppMeshObj[ship_3d]->gpu_tex = 1;
  219. g_ppMeshObj[ship_3d]->LoadEffect("fx\Underwater.fx");
  220. cm_config[carrier_3d].draw_mtrls_state = have_mtrls;
  221. cm_config[carrier_3d].draw_texs_state = have_texs;
  222. cm_config[carrier_3d].movement_mode = is_land;
  223. cm_config[carrier_3d].rotate = D3DXVECTOR3(0, D3DX_PI/5, 0);
  224. cm_config[carrier_3d].translate = D3DXVECTOR3(-500, -8, 500);
  225. cm_config[carrier_3d].scale = D3DXVECTOR3(15, 15, 15);
  226. g_ppMeshObj[carrier_3d] = new CMeshObj(g_pd3dDevice, "models\carrier.x", &cm_config[carrier_3d]);
  227. g_ppMeshObj[carrier_3d]->Init();
  228. g_ppMeshObj[carrier_3d]->gpu_tex = 1;
  229. g_ppMeshObj[carrier_3d]->LoadEffect("fx\Underwater.fx");
  230. // 粒子对象
  231. cparticleconfig cp_config[3];
  232. cp_config[0].dwDiscard = 2048*4;
  233. cp_config[0].dwFlush = 512*2;
  234. cp_config[0].fRadius = -0.4f;
  235. strcpy(cp_config[0].tex_file_name , "textures\Particle.bmp");
  236. D3DXVec3Normalize( &(cp_config[0].src_dir), &(D3DXVECTOR3(-1,-1,0)) );
  237. cp_config[0].src_pos1 = D3DXVECTOR3(1,0,-3);
  238. cp_config[0].src_pos2 = D3DXVECTOR3(-1,0,-3);
  239. cp_config[0].src_vec = 9;
  240. cp_config[1].dwDiscard = 2048*4;
  241. cp_config[1].dwFlush = 512*2;
  242. cp_config[1].fRadius = 0.0f;
  243. strcpy(cp_config[1].tex_file_name , "textures\Particle.bmp");
  244. D3DXVec3Normalize( &(cp_config[1].src_dir), &(D3DXVECTOR3(1,1,0)) );
  245. cp_config[1].src_pos1 = D3DXVECTOR3(1,0,1);
  246. cp_config[1].src_pos2 = D3DXVECTOR3(1,0,-1);
  247. cp_config[1].src_vec = 9;
  248. cp_config[2].dwDiscard = 2048*4;
  249. cp_config[2].dwFlush = 512*2;
  250. cp_config[2].fRadius = 0.0f;
  251. strcpy(cp_config[2].tex_file_name , "textures\Particle.bmp");
  252. D3DXVec3Normalize( &(cp_config[2].src_dir), &(D3DXVECTOR3(0,1,1)) );
  253. cp_config[2].src_pos1 = D3DXVECTOR3(-4,0,1);
  254. cp_config[2].src_pos2 = D3DXVECTOR3(4,0,1);
  255. cp_config[2].src_vec = 9;
  256. g_ppMeshObj[boat_3d]->InitParSys(cp_config);
  257. // 初始化船尾迹对象
  258. pWave = new CBoatWave( g_ppMeshObj[boat_3d]->position.x, g_ppMeshObj[boat_3d]->position.y);
  259. // 初始化海洋对象
  260. sea = new CSea(g_pd3dDevice,cameras[current_camera], config, g_ppMeshObj, num_3d, pWave);
  261. // 初始化天气控制对象
  262. weatherctrl = new CWeatherControl(g_pd3dDevice, config);
  263. weatherctrl->Init();
  264. // 初始化雪对象
  265. snow = new CSnow(g_pd3dDevice, config, 3000, D3DXVECTOR3(0, 10, 0), 15);
  266. snow->cam = &sea->pCamera;
  267. snow->Init();
  268. // 初始化天空盒对象
  269. skydome = new CSkyDome(g_pd3dDevice, config, 10, 0.001, 0.01);
  270. skydome->cam = &sea->pCamera;
  271. skydome->Init();
  272. g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0xffffffff);
  273. g_pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_EXP2);
  274. float fogStart = 0.000235;
  275. g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD*)&fogStart);
  276. g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);
  277. return S_OK;
  278. }
  279. VOID Cleanup()
  280. {
  281. if( g_pVB != NULL )
  282. g_pVB->Release();
  283. if( g_pd3dDevice != NULL )
  284. g_pd3dDevice->Release();
  285. if( g_pD3D != NULL )
  286. g_pD3D->Release();
  287. }
  288. //-----------------------------------------------------------------------------
  289. // 渲染函数
  290. // 说明: 所有的数据更新和场景绘制在这里完成
  291. //-----------------------------------------------------------------------------
  292. void Render()
  293. {
  294. // *****背景音乐刷新部分*****
  295. currentT = timeGetTime();
  296. if (currentT-lastT>3500)
  297. {
  298. pMediaControl->Stop();  //Pause();
  299. /* 停止播放 */  
  300. pMediaControl->Release(); 
  301. /* 释放对象 */ 
  302. pGraph->Release();  
  303. /* 程序结束时调用 */  
  304. CoUninitialize();
  305. TestMP3(L"media\water.wav");
  306. lastT=currentT;
  307. }
  308. // *****数据更新部分*****
  309. // 视角更新
  310. mouse->Update();
  311. if(current_camera == 0)
  312. {
  313. cameras[current_camera]->UpdataKey();
  314. cameras[current_camera]->UpdataMouse(mouse);
  315. }
  316. else
  317. {
  318. if(current_camera == 1)
  319. cameras[current_camera]->UpdateBoat(mouse, g_ppMeshObj[boat_3d]);
  320. }
  321. // 其他类更新
  322. pWave->Update(g_ppMeshObj[boat_3d]->position.x,g_ppMeshObj[boat_3d]->position.z, g_ppMeshObj[boat_3d]->velosity);
  323. sea->pCamera = cameras[current_camera];
  324. sea->Update();
  325. skydome->Update();
  326. snow->Update();
  327. weatherctrl->Update();
  328. // *****场景绘制部分*****
  329. if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
  330. {
  331. sea->Render();
  332. skydome->Render();
  333. snow->Render();
  334. g_pd3dDevice->SetDepthStencilSurface(g_depthstencil);
  335. g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, true);
  336. g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00909090 );
  337. g_ppMeshObj[0]->Render();
  338. g_ppMeshObj[1]->seaHeight = sea->get_height_at(g_ppMeshObj[1]->position.x, g_ppMeshObj[1]->position.z);
  339. g_ppMeshObj[1]->Render();
  340. g_ppMeshObj[2]->Render();
  341. g_ppMeshObj[3]->Render();
  342. g_ppMeshObj[4]->Render();
  343. g_ppMeshObj[5]->seaHeight = sea->get_height_at(g_ppMeshObj[5]->position.x, g_ppMeshObj[5]->position.z);
  344. g_ppMeshObj[5]->Render();
  345. g_ppMeshObj[6]->seaHeight = sea->get_height_at(g_ppMeshObj[6]->position.x, g_ppMeshObj[6]->position.z);
  346. g_ppMeshObj[6]->Render();
  347. g_pd3dDevice->EndScene();
  348. }
  349. g_pd3dDevice->Present(NULL, NULL, NULL, NULL );
  350. }
  351. //-----------------------------------------------------------------------------
  352. // 消息处理函数
  353. // 说明: 处理与用户交互的信息
  354. //-----------------------------------------------------------------------------
  355. LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  356. {
  357. switch( msg )
  358. {
  359. case WM_DESTROY:
  360. Cleanup();
  361. PostQuitMessage( 0 );
  362. return 0;
  363. case WM_KEYDOWN:
  364. keys[wParam] = TRUE;
  365. if(current_camera==1)
  366. g_ppMeshObj[1]->GetKey(wParam);
  367. g_ppMeshObj[3]->GetKey(wParam);
  368. cameras[0]->GetKey(wParam);
  369. if( keys[27])
  370. {
  371. Cleanup();
  372. exit(0);
  373. }
  374. if (keys['C'])
  375. {
  376. weatherctrl->set(CLOUDY);
  377. return 0;
  378. if(keys['M'])
  379. {
  380. weatherctrl->set(SNOWING);
  381. return 0;
  382. }
  383. if(keys['F'])
  384. {
  385. weatherctrl->set(FINE);
  386. return 0;
  387. }
  388. if(keys['O'])
  389. {
  390. if(!config->get_bool(p_bFogActive))
  391. {
  392. g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);
  393. config->set_bool(p_bFogActive, true);
  394. }
  395. else
  396. {
  397. config->set_bool(p_bFogActive, false);
  398. g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
  399. }
  400. }
  401. if(keys['N'])
  402. {
  403. if(!config->get_bool(p_bisNight))
  404. weatherctrl->set(NIGHT);
  405. else
  406. weatherctrl->set(DAY);
  407. return 0;
  408. }
  409. if(keys['B'])
  410. {
  411. if(current_camera == 1)
  412. {
  413. current_camera = 0;
  414. }
  415. else if(current_camera == 0)
  416. {
  417. current_camera = 1;
  418. if(camera_boat == false)
  419.   cameras[1] = new CCamera( D3DXVECTOR3(g_ppMeshObj[boat_3d]->position.x,10,g_ppMeshObj[boat_3d]->position.z), 0,0,0,45,1.33,0.3,5000.0);
  420. camera_boat = true;
  421. }
  422. }
  423. if(keys['P'])
  424. {
  425. float *p_A = &(sea->pNoiseGenerator->A);
  426. if( *p_A < 1.0f)
  427. *p_A +=0.05;
  428. }
  429. if(keys['L'])
  430. {
  431. float *p_A = &(sea->pNoiseGenerator->A);
  432. if( *p_A >0.1f)
  433. *p_A -=0.05;
  434. }
  435. return 0;
  436. case WM_KEYUP:
  437. keys[wParam] = FALSE;
  438. g_ppMeshObj[1]->LostKey(wParam);
  439. g_ppMeshObj[3]->LostKey(wParam);
  440. cameras[0]->LostKey(wParam);
  441. return 0;
  442. }
  443. return DefWindowProc( hWnd, msg, wParam, lParam );
  444. }
  445. //-----------------------------------------------------------------------------
  446. // 主函数
  447. // 说明: DirectX图形程序开发的基本流程
  448. //-----------------------------------------------------------------------------
  449. INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
  450. {
  451. // 注册窗口类
  452. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
  453. GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
  454. "OceanFlame", NULL };
  455. RegisterClassEx( &wc );
  456. // 创建应用程序窗口
  457. HWND hWnd = CreateWindow( "OceanFlame", "OceanFlame——徐潇然、杨阳、房路",
  458. WS_OVERLAPPEDWINDOW, 100, 100, 1024, 768,
  459. GetDesktopWindow(), NULL, wc.hInstance, NULL );
  460. currentT=lastT = timeGetTime();
  461. TestMP3(L"media\water.wav");
  462. // 初始化D3D
  463. if( SUCCEEDED( InitD3D( hWnd ) ) )
  464. {
  465. // 初始化场景数据
  466. if( SUCCEEDED( InitGeometry( hWnd, hInst) ) )
  467. {
  468. // 显示窗口
  469. ShowWindow( hWnd, SW_SHOWDEFAULT );
  470. UpdateWindow( hWnd );
  471. // 进入消息循环
  472. MSG msg;
  473. ZeroMemory( &msg, sizeof(msg) );
  474. while( msg.message!=WM_QUIT )
  475. {
  476. if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
  477. {
  478. TranslateMessage( &msg );
  479. DispatchMessage( &msg );
  480. }
  481. else
  482. Render();
  483. }
  484. }
  485. }
  486. UnregisterClass( "OceanFlame", wc.hInstance );
  487. return 0;
  488. }