Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
vertex.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "graphics/core/color.h"
29 
30 #include "math/vector.h"
31 #include "math/point.h"
32 
33 #include <sstream>
34 
35 
36 // Graphics module namespace
37 namespace Gfx {
38 
39 
51 struct Vertex
52 {
53  Math::Vector coord;
54  Math::Vector normal;
55  Math::Point texCoord;
56 
57  explicit Vertex(Math::Vector aCoord = Math::Vector(),
58  Math::Vector aNormal = Math::Vector(),
59  Math::Point aTexCoord = Math::Point())
60  : coord(aCoord), normal(aNormal),
61  texCoord(aTexCoord) {}
62 
63 
65  inline std::string ToString() const
66  {
67  std::stringstream s;
68  s.precision(3);
69  s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
70  << ", tc: " << texCoord.ToString() << ")";
71  return s.str();
72  }
73 };
74 
83 struct VertexCol
84 {
85  Math::Vector coord;
86  Color color;
87 
88  VertexCol() = default;
89 
90  explicit VertexCol(Math::Vector aCoord,
91  Color aColor = Color())
92  : coord(aCoord), color(aColor) {}
93 
95  inline std::string ToString() const
96  {
97  std::stringstream s;
98  s.precision(3);
99  s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ")";
100  return s.str();
101  }
102 };
103 
104 
113 {
114  Math::Vector coord;
115  Math::Vector normal;
116  Math::Point texCoord;
117  Math::Point texCoord2;
118 
119  explicit VertexTex2(Math::Vector aCoord = Math::Vector(),
120  Math::Vector aNormal = Math::Vector(),
121  Math::Point aTexCoord = Math::Point(),
122  Math::Point aTexCoord2 = Math::Point())
123  : coord(aCoord), normal(aNormal),
124  texCoord(aTexCoord), texCoord2(aTexCoord2) {}
125 
127  void FromVertex(const Vertex &v)
128  {
129  coord = v.coord;
130  normal = v.normal;
131  texCoord = v.texCoord;
132  texCoord2 = Math::Point();
133  }
134 
136  inline std::string ToString() const
137  {
138  std::stringstream s;
139  s.precision(3);
140  s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
141  << ", tc: " << texCoord.ToString() << ", tc2: " << texCoord2.ToString() << ")";
142  return s.str();
143  }
144 };
145 
146 
147 } // namespace Gfx
148 
Vertex of a primitive.
Definition: vertex.h:51
Vertex with secondary texture coordinates.
Definition: vertex.h:112
std::string ToString() const
Returns a string (r, g, b, a)
Definition: color.h:65
void FromVertex(const Vertex &v)
Sets the fields from Vertex with texCoord2 = (0,0)
Definition: vertex.h:127
Point struct and related functions.
std::string ToString() const
Returns a string "[x, y, z]".
Definition: vector.h:223
std::string ToString() const
Returns a string "(c: [...], n: [...], tc: [...], tc2: [...])".
Definition: vertex.h:136
Color structs and related functions.
std::string ToString() const
Returns a string "(c: [...], n: [...], tc: [...])".
Definition: vertex.h:65
2D point
Definition: point.h:49
std::string ToString() const
Returns a string "(c: [...], col: [...])".
Definition: vertex.h:95
Colored vertex.
Definition: vertex.h:83
Namespace for (new) graphics code.
Definition: app.h:49
Vector struct and related functions.
3D (3x1) vector
Definition: vector.h:52
RGBA color.
Definition: color.h:38
std::string ToString() const
Returns a string "[x, y]".
Definition: point.h:162