/* * Triangle.cpp * * Copyright (C) 2008 Matthias Schiffer * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "Triangle.h" #include namespace ZoomEdit { namespace Data { Vertex Triangle::loadVertex(xmlpp::Element *node) const { Vertex v; v.setX(std::atof(node->get_attribute_value("x").c_str())); v.setY(std::atof(node->get_attribute_value("y").c_str())); v.setZ(std::atof(node->get_attribute_value("z").c_str())); return v; } Vector Triangle::loadVector(xmlpp::Element *node) const { Vector v; v.setX(std::atof(node->get_attribute_value("x").c_str())); v.setY(std::atof(node->get_attribute_value("y").c_str())); v.setZ(std::atof(node->get_attribute_value("z").c_str())); return v; } TexCoords Triangle::loadTexCoords(xmlpp::Element *node) const { TexCoords t; t.setS(std::atof(node->get_attribute_value("s").c_str())); t.setT(std::atof(node->get_attribute_value("t").c_str())); t.setR(std::atof(node->get_attribute_value("r").c_str())); t.setQ(std::atof(node->get_attribute_value("q").c_str())); return t; } Triangle::Triangle(xmlpp::Element *node) : triangleNode(node) { xmlpp::Node::NodeList nodeList = node->get_children(); int i = -1; std::memset(vertexNodes, 0, sizeof(vertexNodes)); for(xmlpp::Node::NodeList::iterator n = nodeList.begin(); n != nodeList.end(); ++n) { xmlpp::Element *e = dynamic_cast(*n); if(!e) continue; if(i >= 0) { if(e->get_name() == "normal") { normalNodes[i] = e; normals[i] = loadVector(e); continue; } else if(e->get_name() == "texcoords") { texCoordsNodes[i] = e; texCoords[i] = loadTexCoords(e); continue; } } if(e->get_name() == "vertex") { vertexNodes[++i] = e; vertices[i] = loadVertex(e); } } visible = (node->get_attribute_value("visible").lowercase() != "false"); texture = node->get_attribute_value("texture"); } } }