00001
00002
00003
00004
00005 #ifndef __S_3D_VERTEX_H_INCLUDED__
00006 #define __S_3D_VERTEX_H_INCLUDED__
00007
00008 #include "vector3d.h"
00009 #include "vector2d.h"
00010 #include "SColor.h"
00011
00012 namespace irr
00013 {
00014 namespace video
00015 {
00016
00018 enum E_VERTEX_TYPE
00019 {
00021 EVT_STANDARD = 0,
00022
00024
00025 EVT_2TCOORDS,
00026
00028
00029 EVT_TANGENTS
00030 };
00031
00033 const char* const sBuiltInVertexTypeNames[] =
00034 {
00035 "standard",
00036 "2tcoords",
00037 "tangents",
00038 0
00039 };
00040
00042 struct S3DVertex
00043 {
00045 S3DVertex() {}
00046
00048 S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
00049 : Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
00050
00052 S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
00053 SColor color, const core::vector2d<f32>& tcoords)
00054 : Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
00055
00057 core::vector3df Pos;
00058
00060 core::vector3df Normal;
00061
00063 SColor Color;
00064
00066 core::vector2d<f32> TCoords;
00067
00068 bool operator==(const S3DVertex& other) const
00069 {
00070 return ((Pos == other.Pos) && (Normal == other.Normal) &&
00071 (Color == other.Color) && (TCoords == other.TCoords));
00072 }
00073
00074 bool operator!=(const S3DVertex& other) const
00075 {
00076 return ((Pos != other.Pos) || (Normal != other.Normal) ||
00077 (Color != other.Color) || (TCoords != other.TCoords));
00078 }
00079
00080 bool operator<(const S3DVertex& other) const
00081 {
00082 return ((Pos < other.Pos) ||
00083 ((Pos == other.Pos) && (Normal < other.Normal)) ||
00084 ((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
00085 ((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
00086 }
00087
00088 E_VERTEX_TYPE getType() const
00089 {
00090 return EVT_STANDARD;
00091 }
00092
00093
00094 S3DVertex getInterpolated(const S3DVertex& other, f32 d)
00095 {
00096 d = core::clamp(d, 0.0f, 1.0f);
00097 return S3DVertex(Pos.getInterpolated(other.Pos, d),
00098 Normal.getInterpolated(other.Normal, d),
00099 Color.getInterpolated(other.Color, d),
00100 TCoords.getInterpolated(other.TCoords, d));
00101 }
00102 };
00103
00104
00106
00109 struct S3DVertex2TCoords : public S3DVertex
00110 {
00112 S3DVertex2TCoords() : S3DVertex() {}
00113
00115 S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
00116 : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
00117
00119 S3DVertex2TCoords(const core::vector3df& pos, SColor color,
00120 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
00121 : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
00122
00124 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
00125 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
00126 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
00127
00129 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
00130 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
00131
00133 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
00134 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
00135
00137 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
00138 SColor color, const core::vector2d<f32>& tcoords)
00139 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
00140
00142 S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
00143
00145 core::vector2d<f32> TCoords2;
00146
00148 bool operator==(const S3DVertex2TCoords& other) const
00149 {
00150 return ((static_cast<S3DVertex>(*this)==other) &&
00151 (TCoords2 == other.TCoords2));
00152 }
00153
00155 bool operator!=(const S3DVertex2TCoords& other) const
00156 {
00157 return ((static_cast<S3DVertex>(*this)!=other) ||
00158 (TCoords2 != other.TCoords2));
00159 }
00160
00161 bool operator<(const S3DVertex2TCoords& other) const
00162 {
00163 return ((static_cast<S3DVertex>(*this) < other) ||
00164 ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));
00165 }
00166
00167 E_VERTEX_TYPE getType() const
00168 {
00169 return EVT_2TCOORDS;
00170 }
00171
00172
00173 S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
00174 {
00175 d = core::clamp(d, 0.0f, 1.0f);
00176 return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
00177 Normal.getInterpolated(other.Normal, d),
00178 Color.getInterpolated(other.Color, d),
00179 TCoords.getInterpolated(other.TCoords, d),
00180 TCoords2.getInterpolated(other.TCoords2, d));
00181 }
00182 };
00183
00184
00186
00187 struct S3DVertexTangents : public S3DVertex
00188 {
00190 S3DVertexTangents() : S3DVertex() { }
00191
00193 S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
00194 SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
00195 f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
00196 f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
00197 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
00198
00200 S3DVertexTangents(const core::vector3df& pos, SColor c,
00201 const core::vector2df& tcoords)
00202 : S3DVertex(pos, core::vector3df(), c, tcoords) { }
00203
00205 S3DVertexTangents(const core::vector3df& pos,
00206 const core::vector3df& normal, SColor c,
00207 const core::vector2df& tcoords,
00208 const core::vector3df& tangent=core::vector3df(),
00209 const core::vector3df& binormal=core::vector3df())
00210 : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
00211
00213 core::vector3df Tangent;
00214
00216 core::vector3df Binormal;
00217
00218 bool operator==(const S3DVertexTangents& other) const
00219 {
00220 return ((static_cast<S3DVertex>(*this)==other) &&
00221 (Tangent == other.Tangent) &&
00222 (Binormal == other.Binormal));
00223 }
00224
00225 bool operator!=(const S3DVertexTangents& other) const
00226 {
00227 return ((static_cast<S3DVertex>(*this)!=other) ||
00228 (Tangent != other.Tangent) ||
00229 (Binormal != other.Binormal));
00230 }
00231
00232 bool operator<(const S3DVertexTangents& other) const
00233 {
00234 return ((static_cast<S3DVertex>(*this) < other) ||
00235 ((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
00236 ((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
00237 }
00238
00239 E_VERTEX_TYPE getType() const
00240 {
00241 return EVT_TANGENTS;
00242 }
00243
00244 S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
00245 {
00246 d = core::clamp(d, 0.0f, 1.0f);
00247 return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
00248 Normal.getInterpolated(other.Normal, d),
00249 Color.getInterpolated(other.Color, d),
00250 TCoords.getInterpolated(other.TCoords, d),
00251 Tangent.getInterpolated(other.Tangent, d),
00252 Binormal.getInterpolated(other.Binormal, d));
00253 }
00254 };
00255
00256
00257
00258 inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
00259 {
00260 switch (vertexType)
00261 {
00262 case video::EVT_2TCOORDS:
00263 return sizeof(video::S3DVertex2TCoords);
00264 case video::EVT_TANGENTS:
00265 return sizeof(video::S3DVertexTangents);
00266 default:
00267 return sizeof(video::S3DVertex);
00268 }
00269 }
00270
00271
00272 }
00273 }
00274
00275 #endif
00276