summaryrefslogtreecommitdiffstats
path: root/src/Data/Triangle.h
blob: 1bbb16414ce3633b4dd9ed94d1317f2ceec21efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Triangle.h
 * 
 * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
 * 
 * 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 <http://www.gnu.org/licenses/>.
 */

#ifndef ZOOMEDIT_DATA_TRIANGLE_H_
#define ZOOMEDIT_DATA_TRIANGLE_H_

#include "TexCoords.h"

#include <libxml++/nodes/element.h>
#include <vmmlib/vector.hpp>

namespace ZoomEdit {
namespace Data {

class Triangle {
  private:
    xmlpp::Element *triangleNode;
    xmlpp::Element *vertexNodes[3];
    xmlpp::Element *normalNodes[3];
    xmlpp::Element *texCoordsNodes[3];
    
    vmml::vec3f vertices[3];
    vmml::vec3f normals[3];
    TexCoords texCoords[3];
    
    bool visible;
    
    Glib::ustring texture;
    
    vmml::vec3f loadVector(xmlpp::Element *node) const;
    TexCoords loadTexCoords(xmlpp::Element *node) const;
    
  public:
    Triangle(xmlpp::Element *node);
    
    const vmml::vec3f& getVertex(unsigned int i) const {return vertices[i%3];}
    void setVertex(unsigned int i, const vmml::vec3f &v);
    
    void setVertices(const vmml::vec3f *v) {
      for(int i = 0; i < 3; ++i)
        setVertex(i, v[i]);
    }
    
    const vmml::vec3f& getNormal(unsigned int i) const {return normals[i%3];}
    void setNormal(unsigned int i, const vmml::vec3f &n);
    
    void setNormals(const vmml::vec3f *n) {
      for(int i = 0; i < 3; ++i)
        setNormal(i, n[i]);
    }
    
    const TexCoords& getTexCoords(unsigned int i) const {return texCoords[i%3];}
    void setTexCoords(unsigned int i, const TexCoords &t);
    
    void setTexCoords(const TexCoords *t) {
      for(int i = 0; i < 3; ++i)
        setTexCoords(i, t[i]);
    }
    
    bool isVisible() const {return visible;}
    void setVisible(bool vis) {
      visible = vis;
      triangleNode->set_attribute("visible", vis ? "true" : "false");
    }
    
    xmlpp::Element* getNode() const {
      return triangleNode;
    }
};

}
}

#endif /*ZOOMEDIT_DATA_TRIANGLE_H_*/