I'm trying to add a way to create scenes for my raytracer without having to recompile it every time. So far i've gotten the irrXML parser up and working. My xml file declares all the scene properties I need and i can get them into my raytracer, but my problem is when I want to add something to my scene I don't know how to declare a new variable name from my strings. For instance, when i'm hard coding my scene right into my raytracer I do something like this ...
Vector origin (0, 0, 0);
double radius = 1.0;
Color gray (0.5, 0.5, 0.5);
Sphere my_sphere (origin, radius, gray);
now I have an xml file with statements like ..
// scene.xml
<vector name="origin" x="0" y="0" z="0"/>
<color name="gray" r="0.5" g="0.5" b="0.5"/>
<sphere name="my_sphere" position="origin" radius="1" color="gray"/>
the way irrXML works, you can get the data into your program like this ...
string vectorName, colorName, sphereName, position, color;
float x, y, z, r, g, b, radius;
// parse the scene file
IrrXMLReader* xml = createIrrXMLReader("scene.xml");
// parse the file until end reached
while(xml && xml->read())
{
switch(xml->getNodeType())
{
case EXN_TEXT:
break;
case EXN_ELEMENT:
{
if (!strcmp("vector", xml->getNodeName())) {
vectorName = xml->getAttributeValue("name");
x = xml->getAttributeValueAsFloat("x");
y = xml->getAttributeValueAsFloat("y");
z = xml->getAttributeValueAsFloat("z");
}
if (!strcmp("color", xml->getNodeName())) {
colorName = xml->getAttributeValue("name");
r = xml->getAttributeValueAsFloat("r");
g = xml->getAttributeValueAsFloat("g");
b = xml->getAttributeValueAsFloat("b");
}
if (!strcmp("sphere", xml->getNodeName())) {
sphereName = xml->getAttributeValue("name");
position = xml->getAttributeValue("position");
radius = xml->getAttributeValueAsFloat("radius");
color = xml->getAttributeValue("color");
}
break;
}
}
}
so at this point, the vectorName variable contains the string "origin", but how do I declare a new Vector with that string as the variable? Same goes for vectorName and sphereName .. Any help would be appreciated. Thanks.