HeightmapScene.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:4k
- // HeightmapScene.cpp: implementation of the CHeightmapScene class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "HeightmapScene.h"
- #include "Text.h"
- #include <stdio.h>
- #include "texture.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CHeightmapScene::CHeightmapScene()
- {
- m_pInput=NULL; /////only quote, need't release memory
- m_gamma=0.2f;
- m_brightness=0;
- }
- CHeightmapScene::~CHeightmapScene()
- {
- }
- bool CHeightmapScene::InitHeightmapScene(INPUT *pInput)
- {
- m_pInput=pInput; //指向3dExplorer.cpp中的全局变量Input
- if(!m_cText.InitRasterText())
- {
- MessageBox(0, "cText error", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_cSkyBox.InitSkyBox(10000,7000,10000,0,-1200,0))
- {
- MessageBox(0, "cSkyBox error", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_3dExplorer.Init3dExplorer(VERTEX(700,200,1340),300,true))//450,200,66),157,
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_cTerrain.InitTerrain())
- {
- MessageBox(0, "Init Terrain failed heightmapscene.cpp", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_cLensFlare.InitLensFlare())
- {
- MessageBox(0, "Init LensFlare failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
-
- if(!m_cSprites.InitSpriteManager())
- {
- MessageBox(0, "Init Terrain failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_cHouse.InitHouse(VERTEX(820,m_cHmap.GetHeight(820,1250)-1 ,1250)))
- {
- MessageBox(0, "Init house failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- return true;
- }
- void CHeightmapScene::RenderHeightmapScene()
- {
- glColor3f(1,1,1);
- m_3dExplorer.ProcessInput(m_pInput);
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- m_3dExplorer.TransformWorld(0);
- m_cSkyBox.DrawSkyBox();
- m_3dExplorer.TransformWorld(1);
- m_3dExplorer.Update3dEAmmo();
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- GLfloat light0_position[]={1.0f,0.5f,-0.8f,0.0f};
- glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
- glEnable(GL_FOG);
- //画地形
- m_cTerrain.UpdateTerrainmap();
- ///////////////now render scene
- m_cTerrain.RendTerrain();
- //////////////////////////
- m_cTerrain.RestoreDrawMap();
- glDisable(GL_FOG);
- ///////////////////house
- m_cHouse.DrawHouse();
-
- //////////////////////////////////
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- m_cSprites.UpdateSpriteManager();
- m_cLensFlare.UpdateLensFlare();
- m_3dExplorer.m_cAmmoManager.DrawAmmoManager();
- m_3dExplorer.m_cAmmoManager.UpdateAmmoManager();
- //////////////////////////////////////////
- glColor3f(1,1,1);
- glLoadIdentity();
- // 显示文字信息
- char infoStr[64];
- m_cText.ShowInformation();
- sprintf(infoStr,"%.2f %d %d %d %d %d",m_gamma,m_cTerrain.GetNumTriangles() ,
- int(m_3dExplorer.m_RotY) ,
- int(m_3dExplorer.m_eyePos.xpos),
- int(m_3dExplorer.m_eyePos.ypos),
- int(m_3dExplorer.m_eyePos.zpos));
- glRasterPos3f(0.1f,0.6f,-1.2f);
- m_cText.PrintString(infoStr);
-
- /*
- ///////////// 伪Gamma调节
- if(m_pInput->keys['A'])m_gamma+=0.01f;
- if(m_pInput->keys['S'])m_gamma-=0.01f;
- if(m_pInput->keys['Q'])return;
- if(m_gamma<0)m_gamma=0;
- if(m_gamma>1)m_gamma=1;
- glColor3f(m_gamma,m_gamma,m_gamma);
- glDisable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_COLOR,GL_ONE);
- glEnable(GL_BLEND);
- float size=1.45f;
- glBegin(GL_QUADS);
- glVertex3f(-size,-size, -1.1f);
- glVertex3f( size,-size, -1.1f);
- glVertex3f( size, size, -1.1f);
- glVertex3f(-size, size, -1.1f);
- glEnd();
-
- ///////////////////////
- if(m_brightness<1)
- {
- glBlendFunc(GL_ZERO,GL_SRC_COLOR);
- glColor3f(m_brightness,m_brightness,m_brightness);
- glBegin(GL_QUADS);
- glVertex3f(-size,-size, -1.05f);
- glVertex3f( size,-size, -1.05f);
- glVertex3f( size, size, -1.05f);
- glVertex3f(-size, size, -1.05f);
- glEnd();
- m_brightness+=0.04f;
- }
- glDisable(GL_BLEND);
- */
- }