Joint* JointInteraction::xmlParseJoint(IrrXMLReader* xml, std::string& jointType) { bool finished = false; Constraint* constraint = NULL; Joint* joint = JointFactory::create(xml->getAttributeValue("type")); jointType = xml->getAttributeValue("type"); joint->setWorld(world); joint->setId(atoi(xml->getAttributeValue("id"))); joint->setJointInteractionClass(this); if (xml->getAttributeValue("active")) joint->setActive(atoi(xml->getAttributeValue("active"))); while (!finished && xml && xml->read()) { switch (xml->getNodeType()) { case EXN_ELEMENT: if (!strcmp("entities", xml->getNodeName())) { xmlParseEntities(xml, joint); } // else if else if (!strcmp("anchor", xml->getNodeName())) { if (!jointType.compare("ball") || !jointType.compare("Ball") || !jointType.compare("BALL")) { BallJoint* ball = dynamic_cast<BallJoint*>(joint); ball->setAnchor(atof(xml->getAttributeValue("xPos")), atof(xml->getAttributeValue("yPos")), atof(xml->getAttributeValue("zPos"))); } // if else if (!jointType.compare("hinge") || !jointType.compare("Hinge") || !jointType.compare("HINGE")) { HingeJoint* hinge = dynamic_cast<HingeJoint*>(joint); hinge->setAnchor(atof(xml->getAttributeValue("xPos")), atof(xml->getAttributeValue("yPos")), atof(xml->getAttributeValue("zPos"))); } // else if else if (!jointType.compare("universal") || !jointType.compare("Universal") || !jointType.compare("UNIVERSAL")) { UniversalJoint* universal = dynamic_cast<UniversalJoint*>(joint); universal->setAnchor(atof(xml->getAttributeValue("xPos")), atof(xml->getAttributeValue("yPos")), atof(xml->getAttributeValue("zPos"))); } // else if else if (!jointType.compare("hinge2") || !jointType.compare("Hinge2") || !jointType.compare("HINGE2")) { Hinge2Joint* hinge2 = dynamic_cast<Hinge2Joint*>(joint); hinge2->setAnchor(atof(xml->getAttributeValue("xPos")), atof(xml->getAttributeValue("yPos")), atof(xml->getAttributeValue("zPos"))); } // else if else printd(WARNING, "JointInteraction::loadJoints(): WARNING: JOINT-TYPE %s NEEDS NO anchor ELEMENT!!!\n", jointType.c_str()); } // else if else if (!strcmp("axis", xml->getNodeName())) { if (!jointType.compare("hinge") || !jointType.compare("Hinge") || !jointType.compare("HINGE")) { HingeJoint* hinge = dynamic_cast<HingeJoint*>(joint); hinge->setAxis(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); } // if else if (!jointType.compare("slider") || !jointType.compare("Slider") || !jointType.compare("SLIDER")) { SliderJoint* slider = dynamic_cast<SliderJoint*>(joint); slider->setAxis(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); } // else if else if (!jointType.compare("universal") || !jointType.compare("Universal") || !jointType.compare("UNIVERSAL")) { UniversalJoint* universal = dynamic_cast<UniversalJoint*>(joint); if (atoi(xml->getAttributeValue("index")) == 1) universal->setAxis1(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); else if (atoi(xml->getAttributeValue("index")) == 2) universal->setAxis2(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); else printd(WARNING, "JointInteraction::loadJoints(): WARNING: WRONG ATTRIBUTE FOUND IN axis ELEMENT of UniversalJoint!!!\n"); } // else if else if (!jointType.compare("hinge2") || !jointType.compare("Hinge2") || !jointType.compare("HINGE2")) { Hinge2Joint* hinge2 = dynamic_cast<Hinge2Joint*>(joint); if (atoi(xml->getAttributeValue("index")) == 1) hinge2->setAxis1(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); else if (atoi(xml->getAttributeValue("index")) == 2) hinge2->setAxis2(atof(xml->getAttributeValue("xDir")), atof(xml->getAttributeValue("yDir")), atof(xml->getAttributeValue("zDir"))); else printd(WARNING, "JointInteraction::loadJoints(): WARNING: WRONG ATTRIBUTE FOUND IN axis ELEMENT of Hinge2Joint!!!\n"); } // else if else printd(WARNING, "JointInteraction::loadJoints(): WARNING: JOINT-TYPE %s NEEDS NO axis ELEMENT!!!\n", jointType.c_str()); } // else if else if (!strcmp("angles", xml->getNodeName())) { if (!jointType.compare("hinge") || !jointType.compare("Hinge") || !jointType.compare("HINGE")) { HingeJoint* hinge = dynamic_cast<HingeJoint*>(joint); hinge->setAngles(atof(xml->getAttributeValue("min")), atof(xml->getAttributeValue("max"))); } // if else printd(WARNING, "JointInteraction::loadJoints(): WARNING: JOINT-TYPE %s HAS NO angles ELEMENT!!!\n", jointType.c_str()); } // else if else if (!strcmp("positions", xml->getNodeName())) { SliderJoint* slider = dynamic_cast<SliderJoint*>(joint); slider->setPositions(atof(xml->getAttributeValue("min")), atof(xml->getAttributeValue("max"))); } // else if else if (!strcmp("activateIF", xml->getNodeName())) { constraint = new Constraint(this); constraint->setActionType(Constraint::ACTIVATEIF); constraint->setOwner(joint); xmlParseConstraintAttributes(xml, constraint); joint->addConstraint(constraint); constraint = NULL; } // else if else if (!strcmp("deactivateIF", xml->getNodeName())) { constraint = new Constraint(this); constraint->setActionType(Constraint::DEACTIVATEIF); constraint->setOwner(joint); xmlParseConstraintAttributes(xml, constraint); joint->addConstraint(constraint); constraint = NULL; } // else if else if (!strcmp("activeIF", xml->getNodeName())) { constraint = new Constraint(this); constraint->setActionType(Constraint::ACTIVEIF); constraint->setOwner(joint); xmlParseConstraintAttributes(xml, constraint); joint->addConstraint(constraint); constraint = NULL; } // else if else if (!strcmp("inactiveIF", xml->getNodeName())) { constraint = new Constraint(this); constraint->setActionType(Constraint::INACTIVEIF); constraint->setOwner(joint); xmlParseConstraintAttributes(xml, constraint); joint->addConstraint(constraint); constraint = NULL; } // else if break; case EXN_ELEMENT_END: if (!strcmp("joint", xml->getNodeName())) finished = true; break; default: break; } // switch } // while assert(xml); return joint; } // xmlParseJoint