Carna  Version 3.3.2
Vertex.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Leonid Kostrykin
3  *
4  */
5 
6 #ifndef VERTEX_H_6014714286
7 #define VERTEX_H_6014714286
8 
9 #include <Carna/Carna.h>
11 
19 namespace Carna
20 {
21 
22 namespace base
23 {
24 
25 
26 
27 // ----------------------------------------------------------------------------------
28 // VertexPosition
29 // ----------------------------------------------------------------------------------
30 
40 {
54  float x, y, z, w;
55 
59 
62  template< typename VectorType >
63  void setPosition( const VectorType& position );
64 };
65 
66 
67 template< typename VectorType >
68 void VertexPosition::setPosition( const VectorType& position )
69 {
70  x = position.x();
71  y = position.y();
72  z = position.z();
73 }
74 
75 
76 
77 // ----------------------------------------------------------------------------------
78 // VertexNormal
79 // ----------------------------------------------------------------------------------
80 
89 {
103  float nx, ny, nz, nw;
104 
107  VertexNormal();
108 
113  template< typename VectorType >
114  void setNormal( const VectorType& normal );
115 };
116 
117 
118 template< typename VectorType >
119 void VertexNormal::setNormal( const VectorType& normal )
120 {
121  nx = normal.x();
122  ny = normal.y();
123  nz = normal.z();
124 }
125 
126 
127 
128 // ----------------------------------------------------------------------------------
129 // VertexColor
130 // ----------------------------------------------------------------------------------
131 
140 {
153  float r, g, b, a;
154 
157  VertexColor();
158 
163  template< typename VectorType >
164  void setColor( const VectorType& color );
165 };
166 
167 
168 template< typename VectorType >
169 void VertexColor::setColor( const VectorType& color )
170 {
171  r = color.x();
172  g = color.y();
173  b = color.z();
174  a = color.w();
175 }
176 
177 
178 
179 // ----------------------------------------------------------------------------------
180 // VERTEX_NULL_COMPONENT
181 // ----------------------------------------------------------------------------------
182 
190 #define VERTEX_NULL_COMPONENT( name ) \
191  template< typename VectorType > \
192  void set ## name( const VectorType& ) \
193  { \
194  }
195 
196 
197 
198 // ----------------------------------------------------------------------------------
199 // PVertex
200 // ----------------------------------------------------------------------------------
201 
276 struct CARNA_LIB PVertex
277  : public VertexPosition
278 {
283 
288  VERTEX_NULL_COMPONENT( Normal );
289 
295 };
296 
297 
298 
299 // ----------------------------------------------------------------------------------
300 // PNVertex
301 // ----------------------------------------------------------------------------------
302 
310 struct CARNA_LIB PNVertex
311  : public VertexPosition
312  , public VertexNormal
313 {
318 
324 };
325 
326 
327 
328 // ----------------------------------------------------------------------------------
329 // PCVertex
330 // ----------------------------------------------------------------------------------
331 
338 struct CARNA_LIB PCVertex
339  : public VertexPosition
340  , public VertexColor
341 {
346 
351  VERTEX_NULL_COMPONENT( Normal );
352 };
353 
354 
355 
356 } // namespace Carna :: base
357 
358 } // namespace Carna
359 
360 #endif // VERTEX_H_6014714286
static const VertexAttributes attributes
Holds the declaration of the vertex format.
Definition: Vertex.h:345
float z
Holds the positional z-component of this vertex.
Definition: Vertex.h:54
float nz
Holds the normal vector z-component of this vertex.
Definition: Vertex.h:103
void setColor(const VectorType &color)
Definition: Vertex.h:169
Defines vertex component for position vectors. Usage is explained here.
Definition: Vertex.h:39
Defines vertex that consists of the two attributes position and color.
Definition: Vertex.h:338
Defines vertex component for normal vectors. Usage is explained here.
Definition: Vertex.h:88
void setPosition(const VectorType &position)
Definition: Vertex.h:68
Defines Carna::base::VertexAttributes.
#define VERTEX_NULL_COMPONENT(name)
Adds null implementation for setter corresponding the the given vertex component. ...
Definition: Vertex.h:190
float w
Holds the positional w-component of this vertex. This will be 1 usually.
Definition: Vertex.h:54
static const VertexAttributes attributes
Holds the declaration of the vertex format.
Definition: Vertex.h:317
float x
Holds the positional x-component of this vertex.
Definition: Vertex.h:54
Defines vertex component for colors. Usage is explained here.
Definition: Vertex.h:139
void setNormal(const VectorType &normal)
Definition: Vertex.h:119
Represents a color. Objects from this class are copyable and assignable.
Definition: Color.h:41
float r
Holds the red color component of this vertex.
Definition: Vertex.h:153
Defines vertex that consists of the two attributes position and normal vector.
Definition: Vertex.h:310
static const VertexAttributes attributes
Holds the declaration of the vertex format.
Definition: Vertex.h:282
std::vector< VertexAttribute > VertexAttributes
Defines VertexAttribute vector.
Defines simple-most vertex that only consists of a positional attribute.
Definition: Vertex.h:276
float y
Holds the positional y-component of this vertex.
Definition: Vertex.h:54