From 7db6adf7e9e178c83f0278124a3d6c786134b014 Mon Sep 17 00:00:00 2001 From: neoraider Date: Thu, 10 Apr 2008 22:47:04 +0000 Subject: zoomedit: * TexCoords saves number of used coordinates now. * All data classes save changes in the XML tree now. --- src/Data/Gate.h | 22 +++++++++++++++ src/Data/Info.cpp | 1 - src/Data/Info.h | 19 +++++++++++++ src/Data/Makefile.in | 2 -- src/Data/Room.h | 13 +++++++++ src/Data/TexCoords.h | 7 ++++- src/Data/Texture.h | 18 +++++++++++++ src/Data/Triangle.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/Data/Triangle.h | 29 +++++++++++++------- 9 files changed, 167 insertions(+), 18 deletions(-) (limited to 'src/Data') diff --git a/src/Data/Gate.h b/src/Data/Gate.h index 9aa539a..91acbce 100644 --- a/src/Data/Gate.h +++ b/src/Data/Gate.h @@ -35,6 +35,28 @@ class Gate { public: Gate(xmlpp::Element *node); + + const std::list& getTriangles() { + return triangles; + } + + const Glib::ustring& getRoom1() const { + return room1; + } + + void setRoom1(const Glib::ustring &room) { + room1 = room; + gateNode->set_attribute("room1", room); + } + + const Glib::ustring& getRoom2() const { + return room2; + } + + void setRoom2(const Glib::ustring &room) { + room2 = room; + gateNode->set_attribute("room2", room); + } }; } diff --git a/src/Data/Info.cpp b/src/Data/Info.cpp index bb384b6..28b85db 100644 --- a/src/Data/Info.cpp +++ b/src/Data/Info.cpp @@ -18,7 +18,6 @@ */ #include "Info.h" -#include namespace ZoomEdit { namespace Data { diff --git a/src/Data/Info.h b/src/Data/Info.h index bc51855..1678b81 100644 --- a/src/Data/Info.h +++ b/src/Data/Info.h @@ -21,6 +21,7 @@ #define ZOOMEDIT_DATA_INFO_H_ #include +#include namespace ZoomEdit { namespace Data { @@ -35,6 +36,24 @@ class Info { public: Info(xmlpp::Element *node); + + const Glib::ustring& getName() const { + return name; + } + + void setName(const Glib::ustring &n) { + name = n; + nameNode->get_child_text()->set_content(n); + } + + const Glib::ustring& getDescription() const { + return desc; + } + + void setDescription(const Glib::ustring &d) { + desc = d; + descNode->get_child_text()->set_content(d); + } }; } diff --git a/src/Data/Makefile.in b/src/Data/Makefile.in index 7b7ff9b..2e1f63f 100644 --- a/src/Data/Makefile.in +++ b/src/Data/Makefile.in @@ -84,7 +84,6 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ -DSYMUTIL = @DSYMUTIL@ ECHO = @ECHO@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ @@ -110,7 +109,6 @@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ -NMEDIT = @NMEDIT@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ diff --git a/src/Data/Room.h b/src/Data/Room.h index f01b051..efd67cb 100644 --- a/src/Data/Room.h +++ b/src/Data/Room.h @@ -35,6 +35,19 @@ class Room { public: Room(xmlpp::Element *node); + + const std::list& getTriangles() { + return triangles; + } + + const Glib::ustring& getId() const { + return id; + } + + void setId(const Glib::ustring &nid) { + id = nid; + roomNode->set_attribute("id", nid); + } }; } diff --git a/src/Data/TexCoords.h b/src/Data/TexCoords.h index 679c41c..06f8b59 100644 --- a/src/Data/TexCoords.h +++ b/src/Data/TexCoords.h @@ -25,10 +25,15 @@ namespace Data { class TexCoords { private: + unsigned int coordCount; float s, t, r, q; public: - TexCoords(float s0 = 0, float t0 = 0, float r0 = 0, float q0 = 0) : s(s0), t(t0), r(r0), q(q0) {} + TexCoords(unsigned int c = 2, float s0 = 0, float t0 = 0, float r0 = 0, float q0 = 0) + : coordCount(c), s(s0), t(t0), r(r0), q(q0) {} + + unsigned int getCoordCount() const {return coordCount;} + void setCoordCount(unsigned int c) {coordCount = c;} float getS() const {return s;} void setS(float s0) {s = s0;} diff --git a/src/Data/Texture.h b/src/Data/Texture.h index b6a605a..e0cea59 100644 --- a/src/Data/Texture.h +++ b/src/Data/Texture.h @@ -33,6 +33,24 @@ class Texture { public: Texture(xmlpp::Element *node); + + const Glib::ustring& getId() const { + return id; + } + + void setId(const Glib::ustring &nid) { + id = nid; + texNode->set_attribute("id", nid); + } + + const Glib::ustring& getName() const { + return name; + } + + void setName(const Glib::ustring &nname) { + name = nname; + texNode->set_attribute("name", nname); + } }; } diff --git a/src/Data/Triangle.cpp b/src/Data/Triangle.cpp index 8966b09..d334c12 100644 --- a/src/Data/Triangle.cpp +++ b/src/Data/Triangle.cpp @@ -44,12 +44,28 @@ Vector Triangle::loadVector(xmlpp::Element *node) const { } TexCoords Triangle::loadTexCoords(xmlpp::Element *node) const { - TexCoords t; + TexCoords t(1); + xmlpp::Attribute *attr; 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())); + + attr = node->get_attribute("t"); + if(attr) { + t.setT(std::atof(attr->get_value().c_str())); + t.setCoordCount(2); + } + + attr = node->get_attribute("r"); + if(attr) { + t.setR(std::atof(attr->get_value().c_str())); + t.setCoordCount(3); + } + + attr = node->get_attribute("q"); + if(attr) { + t.setQ(std::atof(attr->get_value().c_str())); + t.setCoordCount(4); + } return t; } @@ -83,6 +99,9 @@ Triangle::Triangle(xmlpp::Element *node) : triangleNode(node) { if(e->get_name() == "vertex") { vertexNodes[++i] = e; vertices[i] = loadVertex(e); + + normalNodes[i] = NULL; + texCoordsNodes[i] = NULL; } } @@ -90,5 +109,52 @@ Triangle::Triangle(xmlpp::Element *node) : triangleNode(node) { texture = node->get_attribute_value("texture"); } +void Triangle::setVertex(unsigned int i, const Vertex &v) { + vertices[i] = v; + + vertexNodes[i]->set_attribute("x", Glib::ustring::format(v.getX())); + vertexNodes[i]->set_attribute("y", Glib::ustring::format(v.getY())); + vertexNodes[i]->set_attribute("z", Glib::ustring::format(v.getZ())); +} + +void Triangle::setNormal(unsigned int i, const Vector &n) { + normals[i] = n; + + if(!normalNodes[i]) + normalNodes[i] = triangleNode->add_child(static_cast(vertexNodes[i]), "normal"); + + normalNodes[i]->set_attribute("x", Glib::ustring::format(n.getX())); + normalNodes[i]->set_attribute("y", Glib::ustring::format(n.getY())); + normalNodes[i]->set_attribute("z", Glib::ustring::format(n.getZ())); +} + +void Triangle::setTexCoords(unsigned int i, const TexCoords &t) { + texCoords[i] = t; + + if(!texCoordsNodes[i]) { + if(normalNodes[i]) + texCoordsNodes[i] = triangleNode->add_child(static_cast(normalNodes[i]), "texcoords"); + else + texCoordsNodes[i] = triangleNode->add_child(static_cast(vertexNodes[i]), "texcoords"); + } + + texCoordsNodes[i]->set_attribute("s", Glib::ustring::format(t.getS())); + + if(t.getCoordCount() >= 2) + texCoordsNodes[i]->set_attribute("t", Glib::ustring::format(t.getT())); + else + texCoordsNodes[i]->remove_attribute("t"); + + if(t.getCoordCount() >= 3) + texCoordsNodes[i]->set_attribute("r", Glib::ustring::format(t.getR())); + else + texCoordsNodes[i]->remove_attribute("r"); + + if(t.getCoordCount() >= 4) + texCoordsNodes[i]->set_attribute("q", Glib::ustring::format(t.getQ())); + else + texCoordsNodes[i]->remove_attribute("q"); +} + } } diff --git a/src/Data/Triangle.h b/src/Data/Triangle.h index f668289..3a235ce 100644 --- a/src/Data/Triangle.h +++ b/src/Data/Triangle.h @@ -50,25 +50,34 @@ class Triangle { Triangle(xmlpp::Element *node); const Vertex& getVertex(unsigned int i) const {return vertices[i%3];} - void setVertex(unsigned int i, Vertex v) {vertices[i%3] = v;} - void setVertices(Vertex v[3]) { - vertices[0] = v[0]; vertices[1] = v[1]; vertices[2] = v[2]; + void setVertex(unsigned int i, const Vertex &v); + + void setVertices(Vertex *v) { + for(int i = 0; i < 3; ++i) + setVertex(i, v[i]); } const Vector& getNormal(unsigned int i) const {return normals[i%3];} - void setNormal(unsigned int i, Vector n) {normals[i%3] = n;} - void setNormals(Vector n[3]) { - normals[0] = n[0]; normals[1] = n[1]; normals[2] = n[2]; + void setNormal(unsigned int i, const Vector &n); + + void setNormals(Vector *n) { + for(int i = 0; i < 3; ++i) + setNormal(i, n[i]); } const TexCoords& getTexCoords(unsigned int i) const {return texCoords[i%3];} - void getTexCoords(unsigned int i, TexCoords t) {texCoords[i%3] = t;} - void getTexCoords(TexCoords t[3]) { - texCoords[0] = t[0]; texCoords[1] = t[1]; texCoords[2] = t[2]; + void setTexCoords(unsigned int i, const TexCoords &t); + + void setTexCoords(TexCoords *t) { + for(int i = 0; i < 3; ++i) + setTexCoords(i, t[i]); } bool isVisible() const {return visible;} - void setVisible(bool vis) {visible = vis;} + void setVisible(bool vis) { + visible = vis; + triangleNode->set_attribute("visible", vis ? "true" : "false"); + } }; } -- cgit v1.2.3