1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __S_3D_VERTEX_H_INCLUDED__
6
#define __S_3D_VERTEX_H_INCLUDED__
17
//! Enumeration for all vertex types there are.
20
//! Standard vertex type used by the Irrlicht engine, video::S3DVertex.
23
//! Vertex with two texture coordinates, video::S3DVertex2TCoords.
24
/** Usually used for geometry with lightmaps or other special materials. */
27
//! Vertex with a tangent and binormal vector, video::S3DVertexTangents.
28
/** Usually used for tangent space normal mapping. */
32
//! Array holding the built in vertex type names
33
const char* const sBuiltInVertexTypeNames[] =
41
//! standard vertex used by the Irrlicht engine.
44
//! default constructor
48
S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
49
: Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
52
S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
53
SColor color, const core::vector2d<f32>& tcoords)
54
: Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
60
core::vector3df Normal;
65
//! Texture coordinates
66
core::vector2d<f32> TCoords;
68
bool operator==(const S3DVertex& other) const
70
return ((Pos == other.Pos) && (Normal == other.Normal) &&
71
(Color == other.Color) && (TCoords == other.TCoords));
74
bool operator!=(const S3DVertex& other) const
76
return ((Pos != other.Pos) || (Normal != other.Normal) ||
77
(Color != other.Color) || (TCoords != other.TCoords));
80
bool operator<(const S3DVertex& other) const
82
return ((Pos < other.Pos) ||
83
((Pos == other.Pos) && (Normal < other.Normal)) ||
84
((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
85
((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
88
E_VERTEX_TYPE getType() const
93
S3DVertex getInterpolated(const S3DVertex& other, f32 d)
95
d = core::clamp(d, 0.0f, 1.0f);
96
return S3DVertex(Pos.getInterpolated(other.Pos, d),
97
Normal.getInterpolated(other.Normal, d),
98
Color.getInterpolated(other.Color, d),
99
TCoords.getInterpolated(other.TCoords, d));
104
//! Vertex with two texture coordinates.
105
/** Usually used for geometry with lightmaps
106
or other special materials.
108
struct S3DVertex2TCoords : public S3DVertex
110
//! default constructor
111
S3DVertex2TCoords() : S3DVertex() {}
113
//! constructor with two different texture coords, but no normal
114
S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
115
: S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
117
//! constructor with two different texture coords, but no normal
118
S3DVertex2TCoords(const core::vector3df& pos, SColor color,
119
const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
120
: S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
122
//! constructor with all values
123
S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
124
const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
125
: S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
127
//! constructor with all values
128
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
129
: S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
131
//! constructor with the same texture coords and normal
132
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
133
: S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
135
//! constructor with the same texture coords and normal
136
S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
137
SColor color, const core::vector2d<f32>& tcoords)
138
: S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
140
//! constructor from S3DVertex
141
S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
143
//! Second set of texture coordinates
144
core::vector2d<f32> TCoords2;
146
//! Equality operator
147
bool operator==(const S3DVertex2TCoords& other) const
149
return ((static_cast<S3DVertex>(*this)==other) &&
150
(TCoords2 == other.TCoords2));
153
//! Inequality operator
154
bool operator!=(const S3DVertex2TCoords& other) const
156
return ((static_cast<S3DVertex>(*this)!=other) ||
157
(TCoords2 != other.TCoords2));
160
bool operator<(const S3DVertex2TCoords& other) const
162
return ((static_cast<S3DVertex>(*this) < other) ||
163
((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));
166
E_VERTEX_TYPE getType() const
171
S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
173
d = core::clamp(d, 0.0f, 1.0f);
174
return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
175
Normal.getInterpolated(other.Normal, d),
176
Color.getInterpolated(other.Color, d),
177
TCoords.getInterpolated(other.TCoords, d),
178
TCoords2.getInterpolated(other.TCoords2, d));
183
//! Vertex with a tangent and binormal vector.
184
/** Usually used for tangent space normal mapping. */
185
struct S3DVertexTangents : public S3DVertex
187
//! default constructor
188
S3DVertexTangents() : S3DVertex() { }
191
S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
192
SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
193
f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
194
f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
195
: S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
198
S3DVertexTangents(const core::vector3df& pos, SColor c,
199
const core::vector2df& tcoords)
200
: S3DVertex(pos, core::vector3df(), c, tcoords) { }
203
S3DVertexTangents(const core::vector3df& pos,
204
const core::vector3df& normal, SColor c,
205
const core::vector2df& tcoords,
206
const core::vector3df& tangent=core::vector3df(),
207
const core::vector3df& binormal=core::vector3df())
208
: S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
210
//! Tangent vector along the x-axis of the texture
211
core::vector3df Tangent;
213
//! Binormal vector (tangent x normal)
214
core::vector3df Binormal;
216
bool operator==(const S3DVertexTangents& other) const
218
return ((static_cast<S3DVertex>(*this)==other) &&
219
(Tangent == other.Tangent) &&
220
(Binormal == other.Binormal));
223
bool operator!=(const S3DVertexTangents& other) const
225
return ((static_cast<S3DVertex>(*this)!=other) ||
226
(Tangent != other.Tangent) ||
227
(Binormal != other.Binormal));
230
bool operator<(const S3DVertexTangents& other) const
232
return ((static_cast<S3DVertex>(*this) < other) ||
233
((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
234
((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
237
E_VERTEX_TYPE getType() const
242
S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
244
d = core::clamp(d, 0.0f, 1.0f);
245
return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
246
Normal.getInterpolated(other.Normal, d),
247
Color.getInterpolated(other.Color, d),
248
TCoords.getInterpolated(other.TCoords, d),
249
Tangent.getInterpolated(other.Tangent, d),
250
Binormal.getInterpolated(other.Binormal, d));
256
inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
260
case video::EVT_2TCOORDS:
261
return sizeof(video::S3DVertex2TCoords);
262
case video::EVT_TANGENTS:
263
return sizeof(video::S3DVertexTangents);
265
return sizeof(video::S3DVertex);
270
} // end namespace video
271
} // end namespace irr