Colobot
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-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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/point.h"
31 #include "math/vector.h"
32 
33 #include <sstream>
34 
35 
36 // Graphics module namespace
37 namespace Gfx
38 {
39 
40 
52 struct Vertex
53 {
54  Math::Vector coord;
55  Math::Vector normal;
56  Math::Point texCoord;
57 
58  explicit Vertex(Math::Vector aCoord = Math::Vector(),
59  Math::Vector aNormal = Math::Vector(),
60  Math::Point aTexCoord = Math::Point())
61  : coord(aCoord), normal(aNormal),
62  texCoord(aTexCoord) {}
63 
64 
66  inline std::string ToString() const
67  {
68  std::stringstream s;
69  s.precision(3);
70  s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
71  << ", tc: " << texCoord.ToString() << ")";
72  return s.str();
73  }
74 };
75 
84 struct VertexCol
85 {
86  Math::Vector coord;
87  Color color;
88 
89  VertexCol() = default;
90 
91  explicit VertexCol(Math::Vector aCoord,
92  Color aColor = Color())
93  : coord(aCoord), color(aColor) {}
94 
96  inline std::string ToString() const
97  {
98  std::stringstream s;
99  s.precision(3);
100  s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ")";
101  return s.str();
102  }
103 };
104 
105 
114 {
115  Math::Vector coord;
116  Math::Vector normal;
117  Math::Point texCoord;
118  Math::Point texCoord2;
119 
120  explicit VertexTex2(Math::Vector aCoord = Math::Vector(),
121  Math::Vector aNormal = Math::Vector(),
122  Math::Point aTexCoord = Math::Point(),
123  Math::Point aTexCoord2 = Math::Point())
124  : coord(aCoord), normal(aNormal),
125  texCoord(aTexCoord), texCoord2(aTexCoord2) {}
126 
128  void FromVertex(const Vertex &v)
129  {
130  coord = v.coord;
131  normal = v.normal;
132  texCoord = v.texCoord;
133  texCoord2 = Math::Point();
134  }
135 
137  inline std::string ToString() const
138  {
139  std::stringstream s;
140  s.precision(3);
141  s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
142  << ", tc: " << texCoord.ToString() << ", tc2: " << texCoord2.ToString() << ")";
143  return s.str();
144  }
145 };
146 
147 
148 } // namespace Gfx
149 
Vertex of a primitive.
Definition: vertex.h:52
Vertex with secondary texture coordinates.
Definition: vertex.h:113
std::string ToString() const
Returns a string (r, g, b, a)
Definition: color.h:66
void FromVertex(const Vertex &v)
Sets the fields from Vertex with texCoord2 = (0,0)
Definition: vertex.h:128
Point struct and related functions.
std::string ToString() const
Returns a string "[x, y, z]".
Definition: vector.h:224
std::string ToString() const
Returns a string "(c: [...], n: [...], tc: [...], tc2: [...])".
Definition: vertex.h:137
Color structs and related functions.
std::string ToString() const
Returns a string "(c: [...], n: [...], tc: [...])".
Definition: vertex.h:66
2D point
Definition: point.h:50
std::string ToString() const
Returns a string "(c: [...], col: [...])".
Definition: vertex.h:96
Colored vertex.
Definition: vertex.h:84
Namespace for (new) graphics code.
Definition: app.h:49
Vector struct and related functions.
3D (3x1) vector
Definition: vector.h:53
RGBA color.
Definition: color.h:39
std::string ToString() const
Returns a string "[x, y]".
Definition: point.h:163