⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terrain.h

📁 game programing code
💻 H
📖 第 1 页 / 共 2 页
字号:
	// Description:		A function to get the true height value (0-255) at a point
	// Arguments:		-iX, iZ: which height value to retrieve
	// Return Value:	An float value: the true height at
	//					the given point
	//--------------------------------------------------------------
	inline unsigned char GetTrueHeightAtPoint( int x, int z )
	{	return ( m_heightData.m_ucpData[( z*m_iSize )+x] );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::GetScaledHeightAtPoint - public
	// Description:		Retrieve the scaled height at a given point
	// Arguments:		-iX, iZ: which height value to retrieve
	// Return Value:	A float value: the scaled height at the given
	//					point.
	//--------------------------------------------------------------
	inline float GetScaledHeightAtPoint( int x, int z )
	{	return ( ( float )( m_heightData.m_ucpData[( z*m_iSize )+x] )*m_vecScale[1] );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::SaveTextureMap - public
	// Description:		Save the current texture map to a file
	// Arguments:		-szFilename: Name of the file to save to
	// Return Value:	A boolean value: -true: successful save
	//									 -false: unsuccessful save
	//--------------------------------------------------------------
	inline bool SaveTextureMap( char* szFilename )
	{
		//first check to see if a texture is loaded, if so, save it!
		if( m_texture.IsLoaded( ) )
			return ( m_texture.Save( szFilename ) );

		return false;
	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::LoadTexture - public
	// Description:		Load a texture map for the terrain
	// Arguments:		-szFilename: Name of the file to load
	// Return Value:	A boolean value: -true: successful load
	//									 -false: unsuccessful load
	//--------------------------------------------------------------
	inline bool LoadTexture( char* szFilename )
	{	return m_texture.Load( szFilename, GL_LINEAR, GL_LINEAR, false );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::UnloadTexture - public
	// Description:		Unload the terrain's texture
	// Arguments:		None
	// Return Value:	None
	//--------------------------------------------------------------
	inline void UnloadTexture( void )
	{	m_texture.Unload( );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::LoadDetailMap - public
	// Description:		Load a detail map to add realism to the terrain
	// Arguments:		-szFilename: Name of the file to load
	// Return Value:	A boolean value: -true: successful load
	//									 -false: unsuccessful load
	//--------------------------------------------------------------
	inline bool LoadDetailMap( char* szFilename )
	{	return m_detailMap.Load( szFilename, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, true );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::UnloadDetailMap - public
	// Description:		Unload the terrain's detail map
	// Arguments:		None
	// Return Value:	None
	//--------------------------------------------------------------
	inline void UnloadDetailMap( void )
	{	m_detailMap.Unload( );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::DoDetailMapping - public
	// Description:		Do a detail map texture pass (which is much more
	//					economical if we can use hardware multitexturing)
	// Arguments:		-bDo: Do detail mapping or not
	// Return Value:	None
	//--------------------------------------------------------------
	inline void DoDetailMapping( bool bDo, int iRepeatNum )
	{
		m_bDetailMapping  = bDo;
		m_iRepeatDetailMap= iRepeatNum;
	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::DoTextureMapping - public
	// Description:		Do texturing (large color map)
	// Arguments:		-bDo: Do texture mapping or not
	// Return Value:	None
	//--------------------------------------------------------------
	inline void DoTextureMapping( bool bDo )
	{	m_bTextureMapping= bDo;	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::DoMultitexturing - public
	// Description:		Do hardware multitexturing
	// Arguments:		-bDo: Use hardware multitexturing or not
	// Return Value:	None
	//--------------------------------------------------------------
	inline void DoMultitexturing( bool bDo )
	{	m_bMultitexture= bDo;	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::LoadTile - public
	// Description:		Load a single tile for the texture generation
	// Arguments:		-tileType: the tile type to load
	//					-szFilename: filename of the tile to load in
	// Return Value:	A boolean value: -true: successful load
	//									 -false: unsuccessful load
	//--------------------------------------------------------------
	inline bool LoadTile( ETILE_TYPES tileType, char* szFilename )
	{	return m_tiles.textureTiles[tileType].LoadData( szFilename );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::UnloadTile - public
	// Description:		Unload a single tile
	// Arguments:		-tileType: the texture which is currently loaded
	//							   for this tile type
	// Return Value:	None
	//--------------------------------------------------------------
	inline void UnloadTile( ETILE_TYPES tileType )
	{	m_tiles.textureTiles[tileType].Unload( );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::UnloadAllTiles - public
	// Description:		Unload all tiles for the texture generation
	// Arguments:		None
	// Return Value:	None
	//--------------------------------------------------------------
	inline void UnloadAllTiles( void )
	{
		UnloadTile( LOWEST_TILE );
		UnloadTile( LOW_TILE );
		UnloadTile( HIGH_TILE );
		UnloadTile( HIGHEST_TILE );
	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::SetLightingType - public
	// Description:		Set the lighting technique to be used
	// Arguments:		-lightingType: which lighting technique to use
	// Return Value:	None
	//--------------------------------------------------------------
	inline void SetLightingType( ELIGHTING_TYPES lightingType )
	{	m_lightingType= lightingType;	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::SetBrightnessAtPoint - public
	// Description:		A function to set the brightness value at a
	//					certain point in a lightmap
	// Arguments:		-x, z: which height value to set
	//					-ucBrightness: value to set the lightmap pixel to
	// Return Value:	None
	//--------------------------------------------------------------
	inline void SetBrightnessAtPoint( int x, int z, unsigned char ucBrightness )
	{	m_lightmap.m_ucpData[( z*m_lightmap.m_iSize )+x]= ucBrightness;	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::GetBrightnessAtPoint - public
	// Description:		A function to get the brightness value at a
	//					certain point in a lightmap
	// Arguments:		-x, z: which height value to retrieve
	// Return Value:	An unsigned char value: the brightness
	//--------------------------------------------------------------
	inline unsigned char GetBrightnessAtPoint( int x, int z )
	{	return ( m_lightmap.m_ucpData[( z*m_lightmap.m_iSize )+x] );	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::SetLightColor - public
	// Description:		Set the color of the terrain's lighting system
	// Arguments:		-vecColor: the color of the light
	// Return Value:	None
	//--------------------------------------------------------------
	inline void SetLightColor( CVECTOR vecColor )
	{	m_vecLightColor= vecColor;	}

	//--------------------------------------------------------------
	// Name:			CTERRAIN::CustomizeSlopeLighting - public
	// Description:		Customize the parameters for slope lighting
	// Arguments:		-iDirX, iDirZ: direction of the light, which can only
	//					               be a whole number.
	//					-fSoftness: the softness of the shadows
	//					-fMinBrightness, fMaxBrightness: the min/max brightness
	//													 of the light
	// Return Value:	None
	//--------------------------------------------------------------
	inline void CustomizeSlopeLighting( int iDirX, int iDirZ, 
										float fMinBrightness, float fMaxBrightness, float fSoftness )
	{
		//set the light direction
		m_iDirectionX= iDirX;
		m_iDirectionZ= iDirZ;

		//set the min/max shading values
		m_fMinBrightness= fMinBrightness;
		m_fMaxBrightness= fMaxBrightness;

		//the light's softness
		m_fLightSoftness= fSoftness;
	}

	CTERRAIN( void ) : m_vecLightColor( 1.0f, 1.0f, 1.0f ), m_vecScale( 1.0f, 1.0f, 1.0f )
	{	}
	~CTERRAIN( void )
	{	}
};

#endif	//__TERRAIN_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -