arsa  2.7
S3DVertex.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __S_3D_VERTEX_H_INCLUDED__
6 #define __S_3D_VERTEX_H_INCLUDED__
7 
8 #include "vector3d.h"
9 #include "vector2d.h"
10 #include "SColor.h"
11 
12 namespace irr
13 {
14 namespace video
15 {
16 
19 {
22 
24 
26 
28 
32 };
33 
35 const char* const sBuiltInVertexTypeNames[] =
36 {
37  "standard",
38  "2tcoords",
39  "tangents",
40  0
41 };
42 
44 struct S3DVertex
45 {
47  S3DVertex() {}
48 
51  : Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
52 
54  S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
55  SColor color, const core::vector2d<f32>& tcoords)
56  : Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
57 
60 
63 
66 
69 
70  bool operator==(const S3DVertex& other) const
71  {
72  return ((Pos == other.Pos) && (Normal == other.Normal) &&
73  (Color == other.Color) && (TCoords == other.TCoords));
74  }
75 
76  bool operator!=(const S3DVertex& other) const
77  {
78  return ((Pos != other.Pos) || (Normal != other.Normal) ||
79  (Color != other.Color) || (TCoords != other.TCoords));
80  }
81 
82  bool operator<(const S3DVertex& other) const
83  {
84  return ((Pos < other.Pos) ||
85  ((Pos == other.Pos) && (Normal < other.Normal)) ||
86  ((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
87  ((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
88  }
89 
92  {
93  return EVT_STANDARD;
94  }
95 
96  //\param d d=0 returns other, d=1 returns this, values between interpolate.
98  {
99  d = core::clamp(d, 0.0f, 1.0f);
100  return S3DVertex(Pos.getInterpolated(other.Pos, d),
101  Normal.getInterpolated(other.Normal, d),
102  Color.getInterpolated(other.Color, d),
103  TCoords.getInterpolated(other.TCoords, d));
104  }
105 };
106 
107 
109 
113 {
116 
118  S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
119  : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
120 
123  const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
124  : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
125 
127  S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
128  const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
129  : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
130 
132  S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
133  : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
134 
137  : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
138 
141  SColor color, const core::vector2d<f32>& tcoords)
142  : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
143 
146 
149 
151  bool operator==(const S3DVertex2TCoords& other) const
152  {
153  return ((static_cast<S3DVertex>(*this)==other) &&
154  (TCoords2 == other.TCoords2));
155  }
156 
158  bool operator!=(const S3DVertex2TCoords& other) const
159  {
160  return ((static_cast<S3DVertex>(*this)!=other) ||
161  (TCoords2 != other.TCoords2));
162  }
163 
164  bool operator<(const S3DVertex2TCoords& other) const
165  {
166  return ((static_cast<S3DVertex>(*this) < other) ||
167  ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));
168  }
169 
171  {
172  return EVT_2TCOORDS;
173  }
174 
175  //\param d d=0 returns other, d=1 returns this, values between interpolate.
177  {
178  d = core::clamp(d, 0.0f, 1.0f);
179  return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
180  Normal.getInterpolated(other.Normal, d),
181  Color.getInterpolated(other.Color, d),
182  TCoords.getInterpolated(other.TCoords, d),
183  TCoords2.getInterpolated(other.TCoords2, d));
184  }
185 };
186 
187 
189 
193 {
196 
199  SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
200  f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
201  f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
202  : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
203 
206  const core::vector2df& tcoords)
207  : S3DVertex(pos, core::vector3df(), c, tcoords) { }
208 
211  const core::vector3df& normal, SColor c,
212  const core::vector2df& tcoords,
213  const core::vector3df& tangent=core::vector3df(),
214  const core::vector3df& binormal=core::vector3df())
215  : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
216 
219 
222 
223  bool operator==(const S3DVertexTangents& other) const
224  {
225  return ((static_cast<S3DVertex>(*this)==other) &&
226  (Tangent == other.Tangent) &&
227  (Binormal == other.Binormal));
228  }
229 
230  bool operator!=(const S3DVertexTangents& other) const
231  {
232  return ((static_cast<S3DVertex>(*this)!=other) ||
233  (Tangent != other.Tangent) ||
234  (Binormal != other.Binormal));
235  }
236 
237  bool operator<(const S3DVertexTangents& other) const
238  {
239  return ((static_cast<S3DVertex>(*this) < other) ||
240  ((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
241  ((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
242  }
243 
245  {
246  return EVT_TANGENTS;
247  }
248 
250  {
251  d = core::clamp(d, 0.0f, 1.0f);
252  return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
253  Normal.getInterpolated(other.Normal, d),
254  Color.getInterpolated(other.Color, d),
255  TCoords.getInterpolated(other.TCoords, d),
256  Tangent.getInterpolated(other.Tangent, d),
257  Binormal.getInterpolated(other.Binormal, d));
258  }
259 };
260 
261 
262 
264 {
265  switch (vertexType)
266  {
267  case video::EVT_2TCOORDS:
268  return sizeof(video::S3DVertex2TCoords);
269  case video::EVT_TANGENTS:
270  return sizeof(video::S3DVertexTangents);
271  default:
272  return sizeof(video::S3DVertex);
273  }
274 }
275 
276 
277 } // end namespace video
278 } // end namespace irr
279 
280 #endif
281 
S3DVertex2TCoords(const core::vector3df &pos, const core::vector3df &normal, const SColor &color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2)
constructor with all values
Definition: S3DVertex.h:127
bool operator==(const S3DVertex2TCoords &other) const
Equality operator.
Definition: S3DVertex.h:151
bool operator!=(const S3DVertexTangents &other) const
Definition: S3DVertex.h:230
core::vector2d< f32 > TCoords2
Second set of texture coordinates.
Definition: S3DVertex.h:148
S3DVertexTangents getInterpolated(const S3DVertexTangents &other, f32 d)
Definition: S3DVertex.h:249
core::vector3df Binormal
Binormal vector (tangent x normal)
Definition: S3DVertex.h:221
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition: SColor.h:455
bool operator==(const S3DVertex &other) const
Definition: S3DVertex.h:70
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
vector3d< T > getInterpolated(const vector3d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition: vector3d.h:261
GLbyte GLbyte bz
core::vector3df Pos
Position.
Definition: S3DVertex.h:59
S3DVertex getInterpolated(const S3DVertex &other, f32 d)
Definition: S3DVertex.h:97
S3DVertex2TCoords(S3DVertex &o)
constructor from S3DVertex
Definition: S3DVertex.h:145
static E_VERTEX_TYPE getType()
Definition: S3DVertex.h:244
S3DVertex2TCoords()
default constructor
Definition: S3DVertex.h:115
bool operator<(const S3DVertex &other) const
Definition: S3DVertex.h:82
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
static E_VERTEX_TYPE getType()
Get type of the class.
Definition: S3DVertex.h:91
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition: S3DVertex.h:25
bool operator!=(const S3DVertex2TCoords &other) const
Inequality operator.
Definition: S3DVertex.h:158
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition: vector3d.h:461
vector2d< T > getInterpolated(const vector2d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition: vector2d.h:316
static E_VERTEX_TYPE getType()
Definition: S3DVertex.h:170
Vertex with two texture coordinates.
Definition: S3DVertex.h:112
GLfixed ny
S3DVertex2TCoords(const core::vector3df &pos, SColor color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2)
constructor with two different texture coords, but no normal
Definition: S3DVertex.h:122
core::vector3df Tangent
Tangent vector along the x-axis of the texture.
Definition: S3DVertex.h:218
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition: S3DVertex.h:31
S3DVertex()
default constructor
Definition: S3DVertex.h:47
GLfloat f
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition: S3DVertex.h:21
S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
constructor
Definition: S3DVertex.h:50
GLbyte nx
S3DVertexTangents(const core::vector3df &pos, SColor c, const core::vector2df &tcoords)
constructor
Definition: S3DVertex.h:205
S3DVertex(const core::vector3df &pos, const core::vector3df &normal, SColor color, const core::vector2d< f32 > &tcoords)
constructor
Definition: S3DVertex.h:54
S3DVertexTangents(const core::vector3df &pos, const core::vector3df &normal, SColor c, const core::vector2df &tcoords, const core::vector3df &tangent=core::vector3df(), const core::vector3df &binormal=core::vector3df())
constructor
Definition: S3DVertex.h:210
standard vertex used by the Irrlicht engine.
Definition: S3DVertex.h:44
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords &other, f32 d)
Definition: S3DVertex.h:176
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
constructor with the same texture coords and normal
Definition: S3DVertex.h:136
S3DVertex2TCoords(const core::vector3df &pos, const core::vector3df &normal, SColor color, const core::vector2d< f32 > &tcoords)
constructor with the same texture coords and normal
Definition: S3DVertex.h:140
Class representing a 32 bit ARGB color.
Definition: SColor.h:316
bool operator<(const S3DVertex2TCoords &other) const
Definition: S3DVertex.h:164
SColor Color
Color.
Definition: S3DVertex.h:65
S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
constructor with two different texture coords, but no normal
Definition: S3DVertex.h:118
GLfixed GLfixed nz
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLuint color
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition: S3DVertex.h:18
S3DVertexTangents()
default constructor
Definition: S3DVertex.h:195
core::vector2d< f32 > TCoords
Texture coordinates.
Definition: S3DVertex.h:68
const char *const sBuiltInVertexTypeNames[]
Array holding the built in vertex type names.
Definition: S3DVertex.h:35
core::vector3df Normal
Normal vector.
Definition: S3DVertex.h:62
Vertex with a tangent and binormal vector.
Definition: S3DVertex.h:192
const GLubyte * c
bool operator!=(const S3DVertex &other) const
Definition: S3DVertex.h:76
GLdouble GLdouble z
bool operator<(const S3DVertexTangents &other) const
Definition: S3DVertex.h:237
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
constructor with all values
Definition: S3DVertex.h:132
bool operator==(const S3DVertexTangents &other) const
Definition: S3DVertex.h:223
S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f, SColor c=0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f, f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f, f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
constructor
Definition: S3DVertex.h:198
GLbyte by
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167
u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
Definition: S3DVertex.h:263