HeightmapScene.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:4k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // HeightmapScene.cpp: implementation of the CHeightmapScene class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "HeightmapScene.h"
  6. #include "Text.h"
  7. #include <stdio.h>
  8. #include "texture.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CHeightmapScene::CHeightmapScene()
  13. {
  14. m_pInput=NULL; /////only quote, need't release memory
  15. m_gamma=0.2f;
  16. m_brightness=0;
  17. }
  18. CHeightmapScene::~CHeightmapScene()
  19. {
  20. }
  21. bool  CHeightmapScene::InitHeightmapScene(INPUT *pInput)
  22. {
  23. m_pInput=pInput;   //指向3dExplorer.cpp中的全局变量Input
  24. if(!m_cText.InitRasterText())
  25. {
  26. MessageBox(0, "cText error", "Error", MB_OK | MB_ICONERROR);
  27. return FALSE;
  28. }
  29. if(!m_cSkyBox.InitSkyBox(10000,7000,10000,0,-1200,0))
  30. {
  31. MessageBox(0, "cSkyBox error", "Error", MB_OK | MB_ICONERROR);
  32. return FALSE;
  33. }    
  34. if(!m_3dExplorer.Init3dExplorer(VERTEX(700,200,1340),300,true))//450,200,66),157,
  35. {
  36. MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  37. return FALSE;
  38. }
  39. if(!m_cTerrain.InitTerrain())
  40. {
  41. MessageBox(0, "Init Terrain failed heightmapscene.cpp", "Error", MB_OK | MB_ICONERROR);
  42. return FALSE;
  43. }
  44. if(!m_cLensFlare.InitLensFlare())
  45. {
  46. MessageBox(0, "Init LensFlare failed", "Error", MB_OK | MB_ICONERROR);
  47. return FALSE;
  48. }
  49. if(!m_cSprites.InitSpriteManager())
  50. {
  51. MessageBox(0, "Init Terrain failed", "Error", MB_OK | MB_ICONERROR);
  52. return FALSE;
  53. }
  54. if(!m_cHouse.InitHouse(VERTEX(820,m_cHmap.GetHeight(820,1250)-1 ,1250)))
  55. {
  56. MessageBox(0, "Init house failed", "Error", MB_OK | MB_ICONERROR);
  57. return FALSE;
  58. }
  59. return true;
  60. }
  61. void  CHeightmapScene::RenderHeightmapScene()
  62. {
  63. glColor3f(1,1,1);
  64. m_3dExplorer.ProcessInput(m_pInput);
  65.     glDisable(GL_LIGHTING);
  66.     glDisable(GL_LIGHT0);
  67. m_3dExplorer.TransformWorld(0);
  68.     m_cSkyBox.DrawSkyBox(); 
  69.     m_3dExplorer.TransformWorld(1);
  70.     m_3dExplorer.Update3dEAmmo();
  71.     glEnable(GL_LIGHTING);
  72.     glEnable(GL_LIGHT0);
  73. GLfloat light0_position[]={1.0f,0.5f,-0.8f,0.0f};
  74. glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
  75.     glEnable(GL_FOG);
  76. //画地形
  77. m_cTerrain.UpdateTerrainmap();
  78.     ///////////////now render scene
  79.     m_cTerrain.RendTerrain();
  80.     //////////////////////////
  81. m_cTerrain.RestoreDrawMap();
  82.     glDisable(GL_FOG);
  83. ///////////////////house
  84.     m_cHouse.DrawHouse();
  85.     
  86.     //////////////////////////////////
  87.     glDisable(GL_LIGHTING);
  88.     glDisable(GL_LIGHT0);
  89. m_cSprites.UpdateSpriteManager();
  90. m_cLensFlare.UpdateLensFlare();
  91. m_3dExplorer.m_cAmmoManager.DrawAmmoManager();
  92. m_3dExplorer.m_cAmmoManager.UpdateAmmoManager();
  93.     //////////////////////////////////////////
  94. glColor3f(1,1,1);
  95. glLoadIdentity();
  96.     // 显示文字信息
  97. char infoStr[64];
  98. m_cText.ShowInformation();
  99. sprintf(infoStr,"%.2f %d %d %d %d %d",m_gamma,m_cTerrain.GetNumTriangles() ,
  100.                        int(m_3dExplorer.m_RotY) ,
  101.    int(m_3dExplorer.m_eyePos.xpos),
  102.    int(m_3dExplorer.m_eyePos.ypos),
  103.    int(m_3dExplorer.m_eyePos.zpos));
  104. glRasterPos3f(0.1f,0.6f,-1.2f);
  105. m_cText.PrintString(infoStr);
  106.     
  107. /*
  108. ///////////// 伪Gamma调节
  109. if(m_pInput->keys['A'])m_gamma+=0.01f;
  110. if(m_pInput->keys['S'])m_gamma-=0.01f;
  111. if(m_pInput->keys['Q'])return;
  112. if(m_gamma<0)m_gamma=0;
  113. if(m_gamma>1)m_gamma=1;
  114. glColor3f(m_gamma,m_gamma,m_gamma);
  115. glDisable(GL_TEXTURE_2D);
  116.   glBlendFunc(GL_SRC_COLOR,GL_ONE);
  117. glEnable(GL_BLEND);
  118. float size=1.45f;
  119. glBegin(GL_QUADS);
  120.     glVertex3f(-size,-size, -1.1f);
  121.     glVertex3f( size,-size, -1.1f);
  122.     glVertex3f( size, size, -1.1f);
  123.     glVertex3f(-size, size, -1.1f);
  124.     glEnd();
  125. ///////////////////////
  126. if(m_brightness<1)
  127. {
  128.   glBlendFunc(GL_ZERO,GL_SRC_COLOR);
  129. glColor3f(m_brightness,m_brightness,m_brightness);
  130. glBegin(GL_QUADS);
  131.     glVertex3f(-size,-size, -1.05f);
  132.     glVertex3f( size,-size, -1.05f);
  133.     glVertex3f( size, size, -1.05f);
  134.     glVertex3f(-size, size, -1.05f);
  135.     glEnd();
  136.         m_brightness+=0.04f;
  137. }
  138. glDisable(GL_BLEND);
  139. */
  140. }