Beispiel #1
0
bool RMaterialList::Open(MXmlElement *pElement)
{
	MXmlElement	aMaterialNode,aChild;
	int nCount = pElement->GetChildNodeCount();

	char szTagName[256],szContents[256];
	for (int i = 0; i < nCount; i++)
	{
		aMaterialNode = pElement->GetChildNode(i);
		aMaterialNode.GetTagName(szTagName);

		if(stricmp(szTagName,RTOK_MATERIAL)==0)
		{
			RMATERIAL *pMaterial=new RMATERIAL;
			pMaterial->dwFlags=0;
			aMaterialNode.GetAttribute(szContents,RTOK_NAME);
			pMaterial->Name=szContents;

			int nChildCount=aMaterialNode.GetChildNodeCount();
			for(int j=0;j<nChildCount;j++)
			{
				aChild = aMaterialNode.GetChildNode(j);
				aChild.GetTagName(szTagName);
				aChild.GetContents(szContents);

#define READVECTOR(v) sscanf(szContents,"%f %f %f",&v.x,&v.y,&v.z)

				if(stricmp(szTagName,RTOK_AMBIENT)==0)		READVECTOR(pMaterial->Ambient); else
				if(stricmp(szTagName,RTOK_DIFFUSE)==0)		READVECTOR(pMaterial->Diffuse); else
				if(stricmp(szTagName,RTOK_SPECULAR)==0)		READVECTOR(pMaterial->Specular); else
				if(stricmp(szTagName,RTOK_DIFFUSEMAP)==0)	pMaterial->DiffuseMap=szContents; else
				if(stricmp(szTagName,RTOK_POWER)==0)		sscanf(szContents,"%f",&pMaterial->Power); else
				if(stricmp(szTagName,RTOK_ADDITIVE)==0)		pMaterial->dwFlags|=RM_FLAG_ADDITIVE; else
				if(stricmp(szTagName,RTOK_USEOPACITY)==0)	pMaterial->dwFlags|=RM_FLAG_USEOPACITY; else
				if(stricmp(szTagName,RTOK_TWOSIDED)==0)		pMaterial->dwFlags|=RM_FLAG_TWOSIDED; else
				if(stricmp(szTagName,RTOK_USEALPHATEST)==0)	pMaterial->dwFlags|=RM_FLAG_USEALPHATEST;
			}

			push_back(pMaterial);
		}
	}
	return true;
}
bool RLightList::Open(::CCXmlElement *pElement)
{
	CCXmlElement	aLightNode,aChild;
	int nCount = pElement->GetChildNodeCount();

	char szTagName[256],szContents[256];
	for (int i = 0; i < nCount; i++)
	{
		aLightNode = pElement->GetChildNode(i);
		aLightNode.GetTagName(szTagName);

		if(stricmp(szTagName,RTOK_LIGHT)==0)
		{
			RLIGHT *plight=new RLIGHT;
			aLightNode.GetAttribute(szContents,RTOK_NAME);
			plight->Name=szContents;
			plight->dwFlags=0;

			int nChildCount=aLightNode.GetChildNodeCount();
			for(int j=0;j<nChildCount;j++)
			{
				aChild = aLightNode.GetChildNode(j);
				aChild.GetTagName(szTagName);
				aChild.GetContents(szContents);

	#define READVECTOR(v) sscanf(szContents,"%f %f %f",&v.x,&v.y,&v.z)

				if(stricmp(szTagName,RTOK_POSITION)==0)		READVECTOR(plight->sPosition); else
				if(stricmp(szTagName,RTOK_COLOR)==0)		READVECTOR(plight->Color); else
				if(stricmp(szTagName,RTOK_INTENSITY)==0)	sscanf(szContents,"%f",&plight->fIntensity); else
				if(stricmp(szTagName,RTOK_ATTNSTART)==0)	sscanf(szContents,"%f",&plight->fAttnStart); else
				if(stricmp(szTagName,RTOK_ATTNEND)==0)		sscanf(szContents,"%f",&plight->fAttnEnd); else
				if(stricmp(szTagName,RTOK_CASTSHADOW)==0)	plight->dwFlags|=RM_FLAG_CASTSHADOW;
			}

			push_back(plight);
		}
	}
	return true;
}
bool ROcclusionList::Open(MXmlElement *pElement)
{
	MXmlElement	aOcclusionNode,aChild;
	int nCount = pElement->GetChildNodeCount();

	char szTagName[256],szContents[256];
	int j = 0;
	for (int i = 0; i < nCount; i++)
	{
		aOcclusionNode = pElement->GetChildNode(i);
		aOcclusionNode.GetTagName(szTagName);

		if(stricmp(szTagName,RTOK_OCCLUSION)==0)
		{
			ROcclusion *poc=new ROcclusion;
			aOcclusionNode.GetAttribute(szContents,RTOK_NAME);
			poc->Name=szContents;

			list<rvector> winding;

			int nChildCount=aOcclusionNode.GetChildNodeCount();
			for(j=0;j<nChildCount;j++)
			{
				aChild = aOcclusionNode.GetChildNode(j);
				aChild.GetTagName(szTagName);
				aChild.GetContents(szContents);

	#define READVECTOR(v) sscanf(szContents,"%f %f %f",&v.x,&v.y,&v.z)

				if(stricmp(szTagName,RTOK_POSITION)==0)	{
					rvector temp;
					READVECTOR(temp);
					winding.push_back(temp);
				}
			}

			poc->nCount=winding.size();
			poc->pVertices=new rvector[poc->nCount];
			list<rvector>::iterator k=winding.begin();
			for(j=0;j<poc->nCount;j++)
			{
				poc->pVertices[j]=*k;
				k++;
			}

			push_back(poc);
		}
	}
	return true;
}