I wanna use 0 represent invalid

Started by
2 comments, last by derek7 18 years, 4 months ago

//--------------------------------------------------------------
Terrain::Terrain(IDirect3DDevice9* device,
				 std::string heightmapFileName,
				 int numVertsPerRow,
				 int numVertsPerCol,
				 int cellSize,
				 float heightScale,
				 D3DXVECTOR3 *direction,
				 std::string baseMapName)
{
	m_device         = device;
	m_numVertsPerRow = numVertsPerRow;
	m_numVertsPerCol = numVertsPerCol;
	m_cellSize		 = cellSize;

//............

	if (baseMapName != 0)
		if( !genBigTexture(	baseMapName.c_str() ))
			exit(0);

	if (direction != 0)
	        if( !genBigTexture(	direction ))
		         exit(0);
}

here direction and baseMapName is optional. If you use one ,another one is forbidden. but string can not access 0 ,how to do???
Advertisement
You will need to have in your prototype parameter list: std::string baseMapName = "") then test against "" instead: if (baseMapName != "") The concept is that of default parameters.
I would make it into two constructors, since you said they are mutually exclusive.
thanks , another similar question:
void Terrain::loadMultiTexture(std::string name1, std::string name2);bool  Terrain::setMultiTexture(bool b){	if(!b) 	{		m_device->SetTexture(0, m_tex);		m_device->SetTexture(1, 0);		m_device->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );		m_device->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );		return true;	}	m_device->SetTexture(0, m_tex);	m_device->SetTexture(1, m_detailTex1);	m_device->SetTexture(2, m_alpha1);	m_device->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);	m_device->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);	//base pic	m_device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);	m_device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	m_device->SetTextureStageState(0, D3DTSS_RESULTARG, D3DTA_TEMP);	// detail pic1	m_device->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);	m_device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	//	first alpha	m_device->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);	m_device->SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEMP);	m_device->SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_CURRENT);	m_device->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);	m_device->SetTextureStageState(2, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);	//m_device->SetTextureStageState(3, D3DTSS_RESULTARG, D3DTA_TEMP);	m_device->SetTextureStageState( 3, D3DTSS_COLOROP,   D3DTOP_DISABLE );	m_device->SetTextureStageState( 3, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );	////detail pic2	//m_device->SetTextureStageState(4, D3DTSS_COLORARG1, D3DTA_TEXTURE);	//m_device->SetTextureStageState(4, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	////2nd alpha	//m_device->SetTextureStageState(5, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);	//m_device->SetTextureStageState(5, D3DTSS_COLORARG1, D3DTA_CURRENT);	//m_device->SetTextureStageState(5, D3DTSS_COLORARG2, D3DTA_TEMP);	//m_device->SetTextureStageState(5, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);	//m_device->SetTextureStageState(5, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);	////detail pic3	//m_device->SetTextureStageState(6, D3DTSS_COLORARG1, D3DTA_TEXTURE);	//m_device->SetTextureStageState(6, D3DTSS_COLOROP, D3DTOP_SELECTARG1);	////3nd alpha	//m_device->SetTextureStageState(7, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);	//m_device->SetTextureStageState(7, D3DTSS_COLORARG1, D3DTA_CURRENT);	//m_device->SetTextureStageState(7, D3DTSS_COLORARG2, D3DTA_TEMP);	//m_device->SetTextureStageState(7, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);	//m_device->SetTextureStageState(7, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);	return D3D_OK;}

if I load 2 map (detailmap and alpha) I will use and set 1 detail map,

if I load 4 map (detailmap and alpha) I will use and set 2 detail map,

So I must use 2 function or better way available??

This topic is closed to new replies.

Advertisement