1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_3D_VERTEX_H_INCLUDED__
\r
6 #define __S_3D_VERTEX_H_INCLUDED__
\r
8 #include "vector3d.h"
\r
9 #include "vector2d.h"
\r
17 //! Enumeration for all vertex types there are.
\r
20 //! Standard vertex type used by the Irrlicht engine, video::S3DVertex.
\r
23 //! Vertex with two texture coordinates, video::S3DVertex2TCoords.
\r
24 /** Usually used for geometry with lightmaps or other special materials. */
\r
27 //! Vertex with a tangent and binormal vector, video::S3DVertexTangents.
\r
28 /** Usually used for tangent space normal mapping.
\r
29 Usually tangent and binormal get send to shaders as texture coordinate sets 1 and 2.
\r
34 //! Array holding the built in vertex type names
\r
35 const char* const sBuiltInVertexTypeNames[] =
\r
43 //! standard vertex used by the Irrlicht engine.
\r
46 //! default constructor
\r
50 S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
\r
51 : Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
\r
54 S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
\r
55 SColor color, const core::vector2d<f32>& tcoords)
\r
56 : Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
\r
59 core::vector3df Pos;
\r
62 core::vector3df Normal;
\r
67 //! Texture coordinates
\r
68 core::vector2d<f32> TCoords;
\r
70 bool operator==(const S3DVertex& other) const
\r
72 return ((Pos == other.Pos) && (Normal == other.Normal) &&
\r
73 (Color == other.Color) && (TCoords == other.TCoords));
\r
76 bool operator!=(const S3DVertex& other) const
\r
78 return ((Pos != other.Pos) || (Normal != other.Normal) ||
\r
79 (Color != other.Color) || (TCoords != other.TCoords));
\r
82 bool operator<(const S3DVertex& other) const
\r
84 return ((Pos < other.Pos) ||
\r
85 ((Pos == other.Pos) && (Normal < other.Normal)) ||
\r
86 ((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
\r
87 ((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
\r
90 //! Get type of the class
\r
91 static E_VERTEX_TYPE getType()
\r
93 return EVT_STANDARD;
\r
96 //\param d d=0 returns other, d=1 returns this, values between interpolate.
\r
97 S3DVertex getInterpolated(const S3DVertex& other, f32 d)
\r
99 d = core::clamp(d, 0.0f, 1.0f);
\r
100 return S3DVertex(Pos.getInterpolated(other.Pos, d),
\r
101 Normal.getInterpolated(other.Normal, d),
\r
102 Color.getInterpolated(other.Color, d),
\r
103 TCoords.getInterpolated(other.TCoords, d));
\r
108 //! Vertex with two texture coordinates.
\r
109 /** Usually used for geometry with lightmaps
\r
110 or other special materials.
\r
112 struct S3DVertex2TCoords : public S3DVertex
\r
114 //! default constructor
\r
115 S3DVertex2TCoords() : S3DVertex() {}
\r
117 //! constructor with two different texture coords, but no normal
\r
118 S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
\r
119 : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
\r
121 //! constructor with two different texture coords, but no normal
\r
122 S3DVertex2TCoords(const core::vector3df& pos, SColor color,
\r
123 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
\r
124 : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
\r
126 //! constructor with all values
\r
127 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
\r
128 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
\r
129 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
\r
131 //! constructor with all values
\r
132 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
\r
133 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
\r
135 //! constructor with the same texture coords and normal
\r
136 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
\r
137 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
\r
139 //! constructor with the same texture coords and normal
\r
140 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
\r
141 SColor color, const core::vector2d<f32>& tcoords)
\r
142 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
\r
144 //! constructor from S3DVertex
\r
145 S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
\r
147 //! Second set of texture coordinates
\r
148 core::vector2d<f32> TCoords2;
\r
150 //! Equality operator
\r
151 bool operator==(const S3DVertex2TCoords& other) const
\r
153 return ((static_cast<S3DVertex>(*this)==other) &&
\r
154 (TCoords2 == other.TCoords2));
\r
157 //! Inequality operator
\r
158 bool operator!=(const S3DVertex2TCoords& other) const
\r
160 return ((static_cast<S3DVertex>(*this)!=other) ||
\r
161 (TCoords2 != other.TCoords2));
\r
164 bool operator<(const S3DVertex2TCoords& other) const
\r
166 return ((static_cast<S3DVertex>(*this) < other) ||
\r
167 ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));
\r
170 static E_VERTEX_TYPE getType()
\r
172 return EVT_2TCOORDS;
\r
175 //\param d d=0 returns other, d=1 returns this, values between interpolate.
\r
176 S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
\r
178 d = core::clamp(d, 0.0f, 1.0f);
\r
179 return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
\r
180 Normal.getInterpolated(other.Normal, d),
\r
181 Color.getInterpolated(other.Color, d),
\r
182 TCoords.getInterpolated(other.TCoords, d),
\r
183 TCoords2.getInterpolated(other.TCoords2, d));
\r
188 //! Vertex with a tangent and binormal vector.
\r
189 /** Usually used for tangent space normal mapping.
\r
190 Usually tangent and binormal get send to shaders as texture coordinate sets 1 and 2.
\r
192 struct S3DVertexTangents : public S3DVertex
\r
194 //! default constructor
\r
195 S3DVertexTangents() : S3DVertex() { }
\r
198 S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
\r
199 SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
\r
200 f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
\r
201 f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
\r
202 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
\r
205 S3DVertexTangents(const core::vector3df& pos, SColor c,
\r
206 const core::vector2df& tcoords)
\r
207 : S3DVertex(pos, core::vector3df(), c, tcoords) { }
\r
210 S3DVertexTangents(const core::vector3df& pos,
\r
211 const core::vector3df& normal, SColor c,
\r
212 const core::vector2df& tcoords,
\r
213 const core::vector3df& tangent=core::vector3df(),
\r
214 const core::vector3df& binormal=core::vector3df())
\r
215 : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
\r
217 //! Tangent vector along the x-axis of the texture
\r
218 core::vector3df Tangent;
\r
220 //! Binormal vector (tangent x normal)
\r
221 core::vector3df Binormal;
\r
223 bool operator==(const S3DVertexTangents& other) const
\r
225 return ((static_cast<S3DVertex>(*this)==other) &&
\r
226 (Tangent == other.Tangent) &&
\r
227 (Binormal == other.Binormal));
\r
230 bool operator!=(const S3DVertexTangents& other) const
\r
232 return ((static_cast<S3DVertex>(*this)!=other) ||
\r
233 (Tangent != other.Tangent) ||
\r
234 (Binormal != other.Binormal));
\r
237 bool operator<(const S3DVertexTangents& other) const
\r
239 return ((static_cast<S3DVertex>(*this) < other) ||
\r
240 ((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
\r
241 ((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
\r
244 static E_VERTEX_TYPE getType()
\r
246 return EVT_TANGENTS;
\r
249 S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
\r
251 d = core::clamp(d, 0.0f, 1.0f);
\r
252 return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
\r
253 Normal.getInterpolated(other.Normal, d),
\r
254 Color.getInterpolated(other.Color, d),
\r
255 TCoords.getInterpolated(other.TCoords, d),
\r
256 Tangent.getInterpolated(other.Tangent, d),
\r
257 Binormal.getInterpolated(other.Binormal, d));
\r
263 inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
\r
265 switch (vertexType)
\r
267 case video::EVT_2TCOORDS:
\r
268 return sizeof(video::S3DVertex2TCoords);
\r
269 case video::EVT_TANGENTS:
\r
270 return sizeof(video::S3DVertexTangents);
\r
272 return sizeof(video::S3DVertex);
\r
277 } // end namespace video
\r
278 } // end namespace irr
\r