/******************************************************************/ /* This file is part of the homework assignments for CSCI-427/527 */ /* at The College of William & Mary and authored by Pieter Peers. */ /* No part of this file, whether altered or in original form, can */ /* be distributed or used outside the context of CSCI-427/527 */ /* without consent of either the College of William & Mary or */ /* Pieter Peers. */ /******************************************************************/ #include #include "sceneIO_core.h" #include "sceneIO_transformation3d.h" #include "rotationX3d.h" #include "rotationY3d.h" #include "rotationZ3d.h" #include "rotation3d.h" #include "translation3d.h" #include "scale3d.h" #include "errorMessage.h" static transformation3d importRotationX(const XMLNode& node) { return rotationX3d(getFloat(node, "angle", 0.0f)); } static transformation3d importRotationY(const XMLNode& node) { return rotationY3d(getFloat(node, "angle", 0.0f)); } static transformation3d importRotationZ(const XMLNode& node) { return rotationZ3d(getFloat(node, "angle", 0.0f)); } static transformation3d importRotationAxis(const XMLNode& node) { return rotation3d(getFloat(node, "angle", 0.0f), getVec3d(node, "axis", vec3d(0.0f, 0.0f, 1.0f))); } static transformation3d importTranslation(const XMLNode& node) { return translation3d(getVec3d(node, "offset", vec3d(0.0f))); } static transformation3d importScale(const XMLNode& node) { vec3d scale = getVec3d(node, "scale", vec3d(1.0f)); return scale3d(scale.x, scale.y, scale.z); } void importTransformation(const XMLNode& node, transformation3d& transform) { // sanity check assert(node.name() == "transformation"); // accumulate all child nodes for(XMLNode childNode = node.firstChild(); childNode.isValid(); childNode++) { // get transformation type: std::string type = childNode.name(); // parse if(type == "rotationX") transform *= importRotationX(childNode); else if(type == "rotationY") transform *= importRotationY(childNode); else if(type == "rotationZ") transform *= importRotationZ(childNode); else if(type == "rotation") transform *= importRotationAxis(childNode); else if(type == "translation") transform *= importTranslation(childNode); else if(type == "scale") transform *= importScale(childNode); else errorMessage("Unknown transformation (%s)", type.c_str()); } // Done. }