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