Irrlicht 3D Engine: S3DVertex.h Source File

| Irrlicht 3D Engine |

S3DVertex.h
Go to the documentation of this file.

    00001 // Copyright (C) 2002-2012 Nikolaus Gebhardt
    00002 // This file is part of the "Irrlicht Engine".
    00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
    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     S3DVertex getInterpolated(const S3DVertex& other, f32 d)
    00094     {
    00095         d = core::clamp(d, 0.0f, 1.0f);
    00096         return S3DVertex(Pos.getInterpolated(other.Pos, d),
    00097                 Normal.getInterpolated(other.Normal, d),
    00098                 Color.getInterpolated(other.Color, d),
    00099                 TCoords.getInterpolated(other.TCoords, d));
    00100     }
    00101 };
    00102
    00103
    00105
    00108 struct S3DVertex2TCoords : public S3DVertex
    00109 {
    00111     S3DVertex2TCoords() : S3DVertex() {}
    00112
    00114     S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
    00115         : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
    00116
    00118     S3DVertex2TCoords(const core::vector3df& pos, SColor color,
    00119         const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
    00120         : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
    00121
    00123     S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
    00124         const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
    00125         : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
    00126
    00128     S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
    00129         : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
    00130
    00132     S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
    00133         : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
    00134
    00136     S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
    00137         SColor color, const core::vector2d<f32>& tcoords)
    00138         : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
    00139
    00141     S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
    00142
    00144     core::vector2d<f32> TCoords2;
    00145
    00147     bool operator==(const S3DVertex2TCoords& other) const
    00148     {
    00149         return ((static_cast<S3DVertex>(*this)==other) &&
    00150             (TCoords2 == other.TCoords2));
    00151     }
    00152
    00154     bool operator!=(const S3DVertex2TCoords& other) const
    00155     {
    00156         return ((static_cast<S3DVertex>(*this)!=other) ||
    00157             (TCoords2 != other.TCoords2));
    00158     }
    00159
    00160     bool operator<(const S3DVertex2TCoords& other) const
    00161     {
    00162         return ((static_cast<S3DVertex>(*this) < other) ||
    00163                 ((static_cast<S3DVertex>(*this) == other) && (TCoords2 < other.TCoords2)));
    00164     }
    00165
    00166     E_VERTEX_TYPE getType() const
    00167     {
    00168         return EVT_2TCOORDS;
    00169     }
    00170
    00171     S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
    00172     {
    00173         d = core::clamp(d, 0.0f, 1.0f);
    00174         return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
    00175                 Normal.getInterpolated(other.Normal, d),
    00176                 Color.getInterpolated(other.Color, d),
    00177                 TCoords.getInterpolated(other.TCoords, d),
    00178                 TCoords2.getInterpolated(other.TCoords2, d));
    00179     }
    00180 };
    00181
    00182
    00184
    00185 struct S3DVertexTangents : public S3DVertex
    00186 {
    00188     S3DVertexTangents() : S3DVertex() { }
    00189
    00191     S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
    00192             SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
    00193             f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
    00194             f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
    00195         : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
    00196
    00198     S3DVertexTangents(const core::vector3df& pos, SColor c,
    00199         const core::vector2df& tcoords)
    00200         : S3DVertex(pos, core::vector3df(), c, tcoords) { }
    00201
    00203     S3DVertexTangents(const core::vector3df& pos,
    00204         const core::vector3df& normal, SColor c,
    00205         const core::vector2df& tcoords,
    00206         const core::vector3df& tangent=core::vector3df(),
    00207         const core::vector3df& binormal=core::vector3df())
    00208         : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
    00209
    00211     core::vector3df Tangent;
    00212
    00214     core::vector3df Binormal;
    00215
    00216     bool operator==(const S3DVertexTangents& other) const
    00217     {
    00218         return ((static_cast<S3DVertex>(*this)==other) &&
    00219             (Tangent == other.Tangent) &&
    00220             (Binormal == other.Binormal));
    00221     }
    00222
    00223     bool operator!=(const S3DVertexTangents& other) const
    00224     {
    00225         return ((static_cast<S3DVertex>(*this)!=other) ||
    00226             (Tangent != other.Tangent) ||
    00227             (Binormal != other.Binormal));
    00228     }
    00229
    00230     bool operator<(const S3DVertexTangents& other) const
    00231     {
    00232         return ((static_cast<S3DVertex>(*this) < other) ||
    00233                 ((static_cast<S3DVertex>(*this) == other) && (Tangent < other.Tangent)) ||
    00234                 ((static_cast<S3DVertex>(*this) == other) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
    00235     }
    00236
    00237     E_VERTEX_TYPE getType() const
    00238     {
    00239         return EVT_TANGENTS;
    00240     }
    00241
    00242     S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
    00243     {
    00244         d = core::clamp(d, 0.0f, 1.0f);
    00245         return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
    00246                 Normal.getInterpolated(other.Normal, d),
    00247                 Color.getInterpolated(other.Color, d),
    00248                 TCoords.getInterpolated(other.TCoords, d),
    00249                 Tangent.getInterpolated(other.Tangent, d),
    00250                 Binormal.getInterpolated(other.Binormal, d));
    00251     }
    00252 };
    00253
    00254
    00255
    00256 inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
    00257 {
    00258     switch (vertexType)
    00259     {
    00260     case video::EVT_2TCOORDS:
    00261         return sizeof(video::S3DVertex2TCoords);
    00262     case video::EVT_TANGENTS:
    00263         return sizeof(video::S3DVertexTangents);
    00264     default:
    00265         return sizeof(video::S3DVertex);
    00266     }
    00267 }
    00268
    00269
    00270 } // end namespace video
    00271 } // end namespace irr
    00272
    00273 #endif
    00274