Game Development Reference
In-Depth Information
Each component has its own definition of
VGenerateXML()
, but for the sake of
completeness, here
'
s the definition for the
TransformComponent
, which stores the
position and orientation of an actor:
TiXmlElement* TransformComponent::VGenerateXml(void)
{
TiXmlElement* pBaseElement = GCC_NEW TiXmlElement(VGetName());
TiXmlElement* pPosition = GCC_NEW TiXmlElement(
“
Position
”
);
Vec3 pos(m_transform.GetPosition());
pPosition->SetAttribute(
“
x
”
, ToStr(pos.x).c_str());
pPosition->SetAttribute(
“
y
”
, ToStr(pos.y).c_str());
pPosition->SetAttribute(
, ToStr(pos.z).c_str());
pBaseElement->LinkEndChild(pPosition);
“
z
”
TiXmlElement* pDirection = GCC_NEW TiXmlElement(
“
YawPitchRoll
”
);
Vec3 orient(m_transform.GetYawPitchRoll());
orient.x = RADIANS_TO_DEGREES(orient.x);
orient.y = RADIANS_TO_DEGREES(orient.y);
orient.z = RADIANS_TO_DEGREES(orient.z);
pDirection->SetAttribute(
“
x
”
, ToStr(orient.x).c_str());
pDirection->SetAttribute(
“
y
”
, ToStr(orient.y).c_str());
pDirection->SetAttribute(
, ToStr(orient.z).c_str());
pBaseElement->LinkEndChild(pDirection);
“
z
”
}
The resulting XML for a particular actor might look like this:
<Actor type=“Grid”>
<TransformComponent>
<Position x=
“
0
”
y=
“
0
”
z=
“
0
”
/>
<YawPitchRoll x=
“
0
”
y=
“
0
”
z=
“
0
”
/>
</TransformComponent>
<PhysicsComponent>
<Shape>Box</Shape>
<Density>Infinite</Density>
<PhysicsMaterial>Normal</PhysicsMaterial>
<RigidBodyTransform>
<Scale x=
“
50
”
y=
“
0.01
”
z=
“
50
”
/>
</RigidBodyTransform>
</PhysicsComponent>
<GridRenderComponent>
<Color r=
“
0.4
”
g=
“
0.4
”
b=
“
0.4
”
a=
“
1.0
”
/>
<Texture>art\grid.dds</Texture>
<Division>100</Division>