]> git.lizzy.rs Git - irrlicht.git/blob - include/S3DVertex.h
2040f9d1d985cc280401829fe2b94106dd8671ec
[irrlicht.git] / include / S3DVertex.h
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
4 \r
5 #ifndef __S_3D_VERTEX_H_INCLUDED__\r
6 #define __S_3D_VERTEX_H_INCLUDED__\r
7 \r
8 #include "vector3d.h"\r
9 #include "vector2d.h"\r
10 #include "SColor.h"\r
11 \r
12 namespace irr\r
13 {\r
14 namespace video\r
15 {\r
16 \r
17 //! Enumeration for all vertex types there are.\r
18 enum E_VERTEX_TYPE\r
19 {\r
20         //! Standard vertex type used by the Irrlicht engine, video::S3DVertex.\r
21         EVT_STANDARD = 0,\r
22 \r
23         //! Vertex with two texture coordinates, video::S3DVertex2TCoords.\r
24         /** Usually used for geometry with lightmaps or other special materials. */\r
25         EVT_2TCOORDS,\r
26 \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
30         */\r
31         EVT_TANGENTS\r
32 };\r
33 \r
34 //! Array holding the built in vertex type names\r
35 const char* const sBuiltInVertexTypeNames[] =\r
36 {\r
37         "standard",\r
38         "2tcoords",\r
39         "tangents",\r
40         0\r
41 };\r
42 \r
43 //! standard vertex used by the Irrlicht engine.\r
44 struct S3DVertex\r
45 {\r
46         //! default constructor\r
47         S3DVertex() {}\r
48 \r
49         //! 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
52 \r
53         //! constructor\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
57 \r
58         //! Position\r
59         core::vector3df Pos;\r
60 \r
61         //! Normal vector\r
62         core::vector3df Normal;\r
63 \r
64         //! Color\r
65         SColor Color;\r
66 \r
67         //! Texture coordinates\r
68         core::vector2d<f32> TCoords;\r
69 \r
70         bool operator==(const S3DVertex& other) const\r
71         {\r
72                 return ((Pos == other.Pos) && (Normal == other.Normal) &&\r
73                         (Color == other.Color) && (TCoords == other.TCoords));\r
74         }\r
75 \r
76         bool operator!=(const S3DVertex& other) const\r
77         {\r
78                 return ((Pos != other.Pos) || (Normal != other.Normal) ||\r
79                         (Color != other.Color) || (TCoords != other.TCoords));\r
80         }\r
81 \r
82         bool operator<(const S3DVertex& other) const\r
83         {\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
88         }\r
89 \r
90         //! Get type of the class\r
91         static E_VERTEX_TYPE getType()\r
92         {\r
93                 return EVT_STANDARD;\r
94         }\r
95 \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
98         {\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
104         }\r
105 };\r
106 \r
107 \r
108 //! Vertex with two texture coordinates.\r
109 /** Usually used for geometry with lightmaps\r
110 or other special materials.\r
111 */\r
112 struct S3DVertex2TCoords : public S3DVertex\r
113 {\r
114         //! default constructor\r
115         S3DVertex2TCoords() : S3DVertex() {}\r
116 \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
120 \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
125 \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
130 \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
134 \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
138 \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
143 \r
144         //! constructor from S3DVertex\r
145         S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}\r
146 \r
147         //! Second set of texture coordinates\r
148         core::vector2d<f32> TCoords2;\r
149 \r
150         //! Equality operator\r
151         bool operator==(const S3DVertex2TCoords& other) const\r
152         {\r
153                 return ((static_cast<S3DVertex>(*this)==other) &&\r
154                         (TCoords2 == other.TCoords2));\r
155         }\r
156 \r
157         //! Inequality operator\r
158         bool operator!=(const S3DVertex2TCoords& other) const\r
159         {\r
160                 return ((static_cast<S3DVertex>(*this)!=other) ||\r
161                         (TCoords2 != other.TCoords2));\r
162         }\r
163 \r
164         bool operator<(const S3DVertex2TCoords& other) const\r
165         {\r
166                 return ((static_cast<S3DVertex>(*this) < other) ||\r
167                                 ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));\r
168         }\r
169 \r
170         static E_VERTEX_TYPE getType()\r
171         {\r
172                 return EVT_2TCOORDS;\r
173         }\r
174 \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
177         {\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
184         }\r
185 };\r
186 \r
187 \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
191 */\r
192 struct S3DVertexTangents : public S3DVertex\r
193 {\r
194         //! default constructor\r
195         S3DVertexTangents() : S3DVertex() { }\r
196 \r
197         //! constructor\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
203 \r
204         //! constructor\r
205         S3DVertexTangents(const core::vector3df& pos, SColor c,\r
206                 const core::vector2df& tcoords)\r
207                 : S3DVertex(pos, core::vector3df(), c, tcoords) { }\r
208 \r
209         //! constructor\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
216 \r
217         //! Tangent vector along the x-axis of the texture\r
218         core::vector3df Tangent;\r
219 \r
220         //! Binormal vector (tangent x normal)\r
221         core::vector3df Binormal;\r
222 \r
223         bool operator==(const S3DVertexTangents& other) const\r
224         {\r
225                 return ((static_cast<S3DVertex>(*this)==other) &&\r
226                         (Tangent == other.Tangent) &&\r
227                         (Binormal == other.Binormal));\r
228         }\r
229 \r
230         bool operator!=(const S3DVertexTangents& other) const\r
231         {\r
232                 return ((static_cast<S3DVertex>(*this)!=other) ||\r
233                         (Tangent != other.Tangent) ||\r
234                         (Binormal != other.Binormal));\r
235         }\r
236 \r
237         bool operator<(const S3DVertexTangents& other) const\r
238         {\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
242         }\r
243 \r
244         static E_VERTEX_TYPE getType()\r
245         {\r
246                 return EVT_TANGENTS;\r
247         }\r
248 \r
249         S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)\r
250         {\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
258         }\r
259 };\r
260 \r
261 \r
262 \r
263 inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)\r
264 {\r
265         switch (vertexType)\r
266         {\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
271         default:\r
272                 return sizeof(video::S3DVertex);\r
273         }\r
274 }\r
275 \r
276 \r
277 } // end namespace video\r
278 } // end namespace irr\r
279 \r
280 #endif\r
281 \r