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  explicit VertexCol(Math::Vector aCoord = Math::Vector(),
86  Color aColor = Color())
87  : coord(aCoord), color(aColor) {}
88 
90  inline std::string ToString() const
91  {
92  std::stringstream s;
93  s.precision(3);
94  s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ")";
95  return s.str();
96  }
97 };
98 
99 
108 {
109  Math::Vector coord;
110  Math::Vector normal;
111  Math::Point texCoord;
112  Math::Point texCoord2;
113 
114  explicit VertexTex2(Math::Vector aCoord = Math::Vector(),
115  Math::Vector aNormal = Math::Vector(),
116  Math::Point aTexCoord = Math::Point(),
117  Math::Point aTexCoord2 = Math::Point())
118  : coord(aCoord), normal(aNormal),
119  texCoord(aTexCoord), texCoord2(aTexCoord2) {}
120 
122  void FromVertex(const Vertex &v)
123  {
124  coord = v.coord;
125  normal = v.normal;
126  texCoord = v.texCoord;
127  texCoord2 = Math::Point();
128  }
129 
131  inline std::string ToString() const
132  {
133  std::stringstream s;
134  s.precision(3);
135  s << "(c: " << coord.ToString() << ", n: " << normal.ToString()
136  << ", tc: " << texCoord.ToString() << ", tc2: " << texCoord2.ToString() << ")";
137  return s.str();
138  }
139 };
140 
141 
142 } // namespace Gfx
143 
Vertex of a primitive.
Definition: vertex.h:48
Vertex with secondary texture coordinates.
Definition: vertex.h:107
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:122
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:131
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:90
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