Skylicht Engine
Loading...
Searching...
No Matches
S3DVertex.h
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
12namespace irr
13{
14namespace video
15{
16
19{
22
24
26
28
30
33 EVT_SKIN_TANGENTS,
34 EVT_2TCOORDS_TANGENTS,
35 EVT_SKIN_2TCOORDS_TANGENTS,
38};
39
41const char* const sBuiltInVertexTypeNames[] =
42{
43 "standard",
44 "2tcoords",
45 "tangents",
46 "skin",
47 "skintangents",
48 "2tcoordstangents",
49 "skin2tcoordtangents",
50 0
51};
52
55{
58
60 S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
61 : Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
62
64 S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
65 SColor color, const core::vector2d<f32>& tcoords)
66 : Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
67
70
73
76
79
80 bool operator==(const S3DVertex& other) const
81 {
82 return ((Pos == other.Pos) && (Normal == other.Normal) &&
83 (Color == other.Color) && (TCoords == other.TCoords));
84 }
85
86 bool operator!=(const S3DVertex& other) const
87 {
88 return ((Pos != other.Pos) || (Normal != other.Normal) ||
89 (Color != other.Color) || (TCoords != other.TCoords));
90 }
91
92 bool operator<(const S3DVertex& other) const
93 {
94 return ((Pos < other.Pos) ||
95 ((Pos == other.Pos) && (Normal < other.Normal)) ||
96 ((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
97 ((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
98 }
99
100 E_VERTEX_TYPE getType() const
101 {
102 return EVT_STANDARD;
103 }
104
105 S3DVertex getInterpolated(const S3DVertex& other, f32 d)
106 {
107 d = core::clamp(d, 0.0f, 1.0f);
108 return S3DVertex(Pos.getInterpolated(other.Pos, d),
109 Normal.getInterpolated(other.Normal, d),
110 Color.getInterpolated(other.Color, d),
111 TCoords.getInterpolated(other.TCoords, d));
112 }
113};
114
115
117
121{
124
126 S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2, f32 lx, f32 ly, f32 lz)
127 : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2), Lightmap(lx, ly, lz) {}
128
129 S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
130 : S3DVertex(x, y, z, 0.0f, 0.0f, 0.0f, c, tu, tv), TCoords2(tu2, tv2), Lightmap(tu2, tu2, 0.0f) {}
131
134 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2, const core::vector3df& lm)
135 : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2), Lightmap(lm) {}
136
137 S3DVertex2TCoords(const core::vector3df& pos, SColor color,
138 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
139 : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2), Lightmap(tcoords2.X, tcoords2.Y, 0.0f) {}
140
142 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
143 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2, const core::vector3df& lm)
144 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2), Lightmap(lm) {}
145
147 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2, f32 lx, f32 ly, f32 lz)
148 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2), Lightmap(lx, ly, lz) {}
149
150 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
151 : S3DVertex(x, y, z, nx, ny, nz, c, tu, tv), TCoords2(tu2, tv2), Lightmap(tu2, tv2, 0.0f) {}
152
154 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
155 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv), Lightmap(tu, tv, 0.0f) {}
156
159 SColor color, const core::vector2d<f32>& tcoords)
160 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords), Lightmap(tcoords.X, tcoords.Y, 0.0f) {}
161
164
167
170
172 bool operator==(const S3DVertex2TCoords& other) const
173 {
174 return ((static_cast<S3DVertex>(*this)==other) &&
175 (TCoords2 == other.TCoords2) &&
176 (Lightmap == other.Lightmap));
177 }
178
180 bool operator!=(const S3DVertex2TCoords& other) const
181 {
182 return ((static_cast<S3DVertex>(*this)!=other) ||
183 (TCoords2 != other.TCoords2) ||
184 (Lightmap != other.Lightmap));
185 }
186
187 bool operator<(const S3DVertex2TCoords& other) const
188 {
189 return ((static_cast<S3DVertex>(*this) < other) ||
190 ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2) && (Lightmap < other.Lightmap)));
191 }
192
193 E_VERTEX_TYPE getType() const
194 {
195 return EVT_2TCOORDS;
196 }
197
198 S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
199 {
200 d = core::clamp(d, 0.0f, 1.0f);
201 return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
202 Normal.getInterpolated(other.Normal, d),
203 Color.getInterpolated(other.Color, d),
204 TCoords.getInterpolated(other.TCoords, d),
205 TCoords2.getInterpolated(other.TCoords2, d),
206 Lightmap.getInterpolated(other.Lightmap, d));
207 }
208};
209
210
212
214{
217 {
218 VertexData.set(1.0f, 0.0f);
219 }
220
222 S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
223 SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
224 f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
225 f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
226 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz)
227 {
228 VertexData.set(1.0f, 0.0f);
229 }
230
233 const core::vector2df& tcoords)
234 : S3DVertex(pos, core::vector3df(), c, tcoords)
235 {
236 VertexData.set(1.0f, 0.0f);
237 }
238
241 const core::vector3df& normal, SColor c,
242 const core::vector2df& tcoords,
243 const core::vector3df& tangent=core::vector3df(),
244 const core::vector3df& binormal=core::vector3df())
245 : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal)
246 {
247 VertexData.set(1.0f, 0.0f);
248 }
249
252
255
260
261 bool operator==(const S3DVertexTangents& other) const
262 {
263 return ((static_cast<S3DVertex>(*this)==other) &&
264 (Tangent == other.Tangent) &&
265 (Binormal == other.Binormal));
266 }
267
268 bool operator!=(const S3DVertexTangents& other) const
269 {
270 return ((static_cast<S3DVertex>(*this)!=other) ||
271 (Tangent != other.Tangent) ||
272 (Binormal != other.Binormal));
273 }
274
275 bool operator<(const S3DVertexTangents& other) const
276 {
277 return ((static_cast<S3DVertex>(*this) < other) ||
278 ((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
279 ((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
280 }
281
282 E_VERTEX_TYPE getType() const
283 {
284 return EVT_TANGENTS;
285 }
286
287 S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
288 {
289 d = core::clamp(d, 0.0f, 1.0f);
290 return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
291 Normal.getInterpolated(other.Normal, d),
292 Color.getInterpolated(other.Color, d),
293 TCoords.getInterpolated(other.TCoords, d),
294 Tangent.getInterpolated(other.Tangent, d),
295 Binormal.getInterpolated(other.Binormal, d));
296 }
297};
298
299
300struct SVec4
301{
302 float X;
303 float Y;
304 float Z;
305 float W;
306
307 SVec4()
308 {
309 X = 0;
310 Y = 0;
311 Z = 0;
312 W = 0;
313 }
314
315 SVec4(float x)
316 {
317 X = x;
318 Y = 0;
319 Z = 0;
320 W = 0;
321 }
322 SVec4(float x, float y)
323 {
324 X = x;
325 Y = y;
326 Z = 0;
327 W = 0;
328 }
329 SVec4(float x, float y, float z)
330 {
331 X = x;
332 Y = y;
333 Z = z;
334 W = 0;
335 }
336 SVec4(float x, float y, float z, float w)
337 {
338 X = x;
339 Y = y;
340 Z = z;
341 W = w;
342 }
343
344 bool operator==(const SVec4& other) const
345 {
346 return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
347 }
348};
349
350struct S3DVertexSkin : public S3DVertex
351{
352 S3DVertexSkin(): S3DVertex()
353 {
354 }
355
356 SVec4 BoneIndex;
357 SVec4 BoneWeight;
358
359 E_VERTEX_TYPE getType() const
360 {
361 return EVT_SKIN;
362 }
363};
364
365struct S3DVertexSkinTangents: public S3DVertexTangents
366{
367 S3DVertexSkinTangents(): S3DVertexTangents()
368 {
369 VertexData.set(1.0f, 0.0f);
370 }
371
372 SVec4 BoneIndex;
373 SVec4 BoneWeight;
374
375 E_VERTEX_TYPE getType() const
376 {
377 return EVT_SKIN_TANGENTS;
378 }
379};
380
381struct S3DVertex2TCoordsTangents : public S3DVertex2TCoords
382{
383 S3DVertex2TCoordsTangents() : S3DVertex2TCoords()
384 {
385 }
386
387 S3DVertex2TCoordsTangents(S3DVertex2TCoords& v) : S3DVertex2TCoords(v)
388 {
389 VertexData.set(1.0f, 0.0f);
390 }
391
394
397
402
403 E_VERTEX_TYPE getType() const
404 {
405 return EVT_2TCOORDS_TANGENTS;
406 }
407};
408
409struct S3DVertexSkin2TCoordsTangents : public S3DVertex2TCoordsTangents
410{
411 S3DVertexSkin2TCoordsTangents() : S3DVertex2TCoordsTangents()
412 {
413
414 }
415
416 SVec4 BoneIndex;
417 SVec4 BoneWeight;
418
419 E_VERTEX_TYPE getType() const
420 {
421 return EVT_SKIN_2TCOORDS_TANGENTS;
422 }
423};
424
425inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
426{
427 switch (vertexType)
428 {
430 return sizeof(video::S3DVertex2TCoords);
432 return sizeof(video::S3DVertexTangents);
433 case video::EVT_SKIN:
434 return sizeof(video::S3DVertexSkin);
435 case video::EVT_SKIN_TANGENTS:
436 return sizeof(video::S3DVertexSkinTangents);
437 case video::EVT_SKIN_2TCOORDS_TANGENTS:
439 case video::EVT_2TCOORDS_TANGENTS:
441 default:
442 return sizeof(video::S3DVertex);
443 }
444}
445
446} // end namespace video
447} // end namespace irr
448
449#endif
450
2d vector template class with lots of operators and methods.
Definition vector2d.h:22
vector2d< T > getInterpolated(const vector2d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector2d.h:278
vector3d< T > getInterpolated(const vector3d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector3d.h:247
Class representing a 32 bit ARGB color.
Definition SColor.h:285
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.h:423
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.h:166
The video namespace contains classes for accessing the video driver. All 2d and 3d rendering is done ...
Definition EDriverFeatures.h:11
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.h:19
@ EVT_SKIN
Skylicht support hardware skinning.
Definition S3DVertex.h:32
@ EVT_UNKNOWN
Null.
Definition S3DVertex.h:37
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.h:25
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.h:29
@ EVT_STANDARD
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition S3DVertex.h:21
const char *const sBuiltInVertexTypeNames[]
Array holding the built in vertex type names.
Definition S3DVertex.h:41
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
Vertex with two texture coordinates.
Definition S3DVertex.h:121
bool operator!=(const S3DVertex2TCoords &other) const
Inequality operator.
Definition S3DVertex.h:180
S3DVertex2TCoords()
default constructor
Definition S3DVertex.h:123
core::vector2d< f32 > TCoords2
Second set of texture coordinates.
Definition S3DVertex.h:166
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:154
core::vector3df Lightmap
Lightmap uv.
Definition S3DVertex.h:169
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2, f32 lx, f32 ly, f32 lz)
constructor with all values
Definition S3DVertex.h:147
bool operator==(const S3DVertex2TCoords &other) const
Equality operator.
Definition S3DVertex.h:172
S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2, f32 lx, f32 ly, f32 lz)
constructor with two different texture coords, but no normal
Definition S3DVertex.h:126
S3DVertex2TCoords(const core::vector3df &pos, SColor color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2, const core::vector3df &lm)
constructor with two different texture coords, but no normal
Definition S3DVertex.h:133
S3DVertex2TCoords(S3DVertex &o)
constructor from S3DVertex
Definition S3DVertex.h:163
S3DVertex2TCoords(const core::vector3df &pos, const core::vector3df &normal, const SColor &color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2, const core::vector3df &lm)
constructor with all values
Definition S3DVertex.h:142
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:158
Definition S3DVertex.h:382
core::vector2df VertexData
Definition S3DVertex.h:401
core::vector3df Binormal
Binormal vector (tangent x normal).
Definition S3DVertex.h:396
core::vector3df Tangent
Tangent vector along the x-axis of the texture.
Definition S3DVertex.h:393
standard vertex used by the Irrlicht engine.
Definition S3DVertex.h:55
core::vector2d< f32 > TCoords
Texture coordinates.
Definition S3DVertex.h:78
S3DVertex()
default constructor
Definition S3DVertex.h:57
S3DVertex(const core::vector3df &pos, const core::vector3df &normal, SColor color, const core::vector2d< f32 > &tcoords)
constructor
Definition S3DVertex.h:64
core::vector3df Normal
Normal vector.
Definition S3DVertex.h:72
SColor Color
Color.
Definition S3DVertex.h:75
S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
constructor
Definition S3DVertex.h:60
core::vector3df Pos
Position.
Definition S3DVertex.h:69
Definition S3DVertex.h:351
Definition S3DVertex.h:366
Vertex with a tangent and binormal vector.
Definition S3DVertex.h:214
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:240
core::vector3df Binormal
Binormal vector (tangent x normal).
Definition S3DVertex.h:254
core::vector3df Tangent
Tangent vector along the x-axis of the texture.
Definition S3DVertex.h:251
S3DVertexTangents(const core::vector3df &pos, SColor c, const core::vector2df &tcoords)
constructor
Definition S3DVertex.h:232
S3DVertexTangents()
default constructor
Definition S3DVertex.h:216
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:222
core::vector2df VertexData
Definition S3DVertex.h:259
Definition S3DVertex.h:301