コード例 #1
0
ファイル: stlvariables.cpp プロジェクト: dmpas/cbp2make
void CFloatVariable::SetChar(const char Value)
{
 m_Value = CharToFloat(Value);
}
コード例 #2
0
ファイル: stlvariables.cpp プロジェクト: dmpas/cbp2make
double CCharVariable::GetFloat(void) const
{
 return CharToFloat(m_Value);
}
コード例 #3
0
ファイル: MoonScene.cpp プロジェクト: wenqvip/MoonGame
bool MoonScene::Initialize(D3DCAPS9* d3dCaps, const char* scenename)
{
	_device = NULL;
	_d3dCaps = d3dCaps;
	//检查场景配置文件是否存在
	string scnpath(SCENE_DIR(scenename));
	scnpath += ".scn";
	if(!PathFileExists(scnpath.c_str()))
	{
		LogError("MoonScene::Initialize() Cannot find scene configure file!");
		::MessageBox(0,"Cannot find scene configure file, please check bin/start.cfg.",0,0);
		return false;
	}

	char ch[256];
	string temp;
	char c[5];
	//读取场景配置信息
	GetPrivateProfileString("configure","bRenderCollisionBox","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_CollisionTS = new MoonCollision(true);
	else
		_CollisionTS = new MoonCollision();

	//初始化摄像机
	_ThirdCamera = new MoonCamera(MoonCamera::RPG);
	_ThirdCamera->setPosition(&D3DXVECTOR3(0.0f, 0.0f, 0.0f));
	_ThirdCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize CameraOnPlayer OK!");
	_FirstCamera = new MoonCamera(MoonCamera::LANDOBJECT);
	_FirstCamera->setPosition(&D3DXVECTOR3(0.0f, 150.0f, 0.0f));
	_FirstCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize FreeCamera OK!");
	_Camera = _ThirdCamera;

	//读取地形和天空的配置名称
	GetPrivateProfileString("environment","terrain",NULL,ch,256,scnpath.c_str());
	_terrainname = ch;
	GetPrivateProfileString("environment","skybox",NULL,ch,256,scnpath.c_str());
	_skyboxname = ch;

	//读取环境光照参数
	D3DXVECTOR3 v;
	GetPrivateProfileString("environmentlight","range",NULL,ch,256,scnpath.c_str());
	_environmentLight.Range=CharToFloat(ch);
	GetPrivateProfileString("environmentlight","diffuse",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Diffuse.r=v.x;
	_environmentLight.Diffuse.b=v.y;
	_environmentLight.Diffuse.g=v.z;
	GetPrivateProfileString("environmentlight","ambient",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Ambient.r=v.x;
	_environmentLight.Ambient.b=v.y;
	_environmentLight.Ambient.g=v.z;
	GetPrivateProfileString("environmentlight","specular",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Specular.r=v.x;
	_environmentLight.Specular.b=v.y;
	_environmentLight.Specular.g=v.z;
	GetPrivateProfileString("environmentlight","direction",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	D3DXVec3Normalize((D3DXVECTOR3*)&(_environmentLight.Direction),&v);
	_environmentLight.Type = D3DLIGHT_DIRECTIONAL;

	GetPrivateProfileString("ambient","ambient",NULL,ch,256,scnpath.c_str());
	_ambient = CharToVector3(ch);

	//读取雾化参数
	GetPrivateProfileString("fog","fog",NULL,ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
	{
		_dwFog = TRUE;
		GetPrivateProfileString("fog","fogcolor",NULL,ch,256,scnpath.c_str());
		v = CharToVector3(ch);
		_dwFogColor = D3DCOLOR_XRGB((int)v.x,(int)v.y,(int)v.z);
		GetPrivateProfileString("fog","fogtablemode",NULL,ch,256,scnpath.c_str());
		temp = ch;
		float f;
		if(temp == "linear")
		{
			_dwFogTableMode = D3DFOG_LINEAR;
			GetPrivateProfileString("fog","fogstart",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogStart = *(DWORD*)&f;
			GetPrivateProfileString("fog","fogend",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogEnd = *(DWORD*)&f;
		}
		else
		{
			if(temp == "exp")
				_dwFogTableMode = D3DFOG_EXP;
			else if(temp == "exp2")
				_dwFogTableMode = D3DFOG_EXP2;
			GetPrivateProfileString("fog","fogdensity",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogDensity = *(DWORD*)&f;
		}
	}
	else
	{
		_dwFog = FALSE;
	}

	//读取角色相关参数
	string strPlayerName;
	D3DXVECTOR3 PlayerPos;
	D3DXVECTOR3 PlayerDir;
	D3DXVECTOR3 PlayerScl;
	GetPrivateProfileString("player","player",NULL,ch,256,scnpath.c_str());
	strPlayerName = ch;
	GetPrivateProfileString("player","position",NULL,ch,256,scnpath.c_str());
	PlayerPos = CharToVector3(ch);
	GetPrivateProfileString("player","direction",NULL,ch,256,scnpath.c_str());
	PlayerDir = CharToVector3(ch);
	GetPrivateProfileString("player","scale",NULL,ch,256,scnpath.c_str());
	PlayerScl = CharToVector3(ch);
	_thePlayer = new MoonCharacter(_d3dCaps,strPlayerName.c_str(), _ID++ ,PlayerPos,PlayerDir, PlayerScl);
	LogInfo("MoonScene::Initialize() Create MoonCharacter OK!");
	ReadCollisionBox("player",scnpath.c_str(),_thePlayer);

	//读取地面物体参数
	_blockcount = 0;
	_pBlock = NULL;
	GetPrivateProfileString("block","blockcount","0",ch,256,scnpath.c_str());
	_blockcount = CharToInt(ch);
	if(_blockcount>0)
		_pBlock = new MoonBlock[_blockcount];
	string str="block";
	string blockname;
	D3DXVECTOR3 blockpos,blockscl,blockrot;
	for(int i = 0; i < _blockcount; i++)
	{
		sprintf_s(c,"%04d",i);
		str+=c;
		GetPrivateProfileString(str.c_str(),"name",NULL,ch,256,scnpath.c_str());
		blockname = ch;
		GetPrivateProfileString(str.c_str(),"pos",NULL,ch,256,scnpath.c_str());
		blockpos = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"scl",NULL,ch,256,scnpath.c_str());
		blockscl = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"rot",NULL,ch,256,scnpath.c_str());
		blockrot = CharToVector3(ch);
		(_pBlock[i]).Initialize(_d3dCaps,blockname.c_str(), _ID++ ,blockpos,blockrot,blockscl);
		LogInfo("MoonScene::Initialize() Create new MoonBlock, name: %s.",blockname.c_str());
		ReadCollisionBox(str.c_str(),scnpath.c_str(),&_pBlock[i]);
		str="block";
	}

	//是否下雨
	GetPrivateProfileString("rain","brainy","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
		_pRain = new MoonRain();
	else
		_pRain = NULL;

	D3DXVECTOR3 vec1,vec2;
	//是否下雪
	GetPrivateProfileString("snow","bsnow","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("snow","boundingmin","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("snow","boundingmax","(1,1,1)",ch,256,scnpath.c_str());
		vec2 = CharToVector3(ch);
		GetPrivateProfileString("snow","size","0.5",ch,256,scnpath.c_str());
		float fsize = CharToFloat(ch);
		GetPrivateProfileString("snow","texture","snow.tga",ch,256,scnpath.c_str());
		_SnowTex = ch;
		GetPrivateProfileString("snow","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_SnowSystem = new MoonSnow(&BoundingBox(&vec1, &vec2), fsize, num);
	}
	else
		_SnowSystem = NULL;

	//是否绘制焰火
	GetPrivateProfileString("firework","bfirework","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("firework","position","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("firework","texture","fire.tga",ch,256,scnpath.c_str());
		_FireTex = ch;
		GetPrivateProfileString("firework","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_Firework = new MoonFirework(&vec1,num);
	}
	else
		_Firework = NULL;

	// 读取水体配置信息
	GetPrivateProfileString("water","water","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_pWater = new MoonWater();
	else
		_pWater = NULL;
	if(_pWater)
	{
		GetPrivateProfileString("water","height","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","waveheight","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedu","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedv","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
	}

	_SoundManager = new MoonSoundManager();
	if(_SoundManager->Initialize())
		LogInfo("MoonScene::Initialize() SoundManager initialized OK!");

	return true;
}