Commit 981d1d61 authored by hybrid's avatar hybrid

Derive specialized vertices from the base one to avoid duplicated code.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@828 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 9c9beede
...@@ -79,49 +79,36 @@ struct S3DVertex ...@@ -79,49 +79,36 @@ struct S3DVertex
/** Usually used for geometry with lightmaps /** Usually used for geometry with lightmaps
or other special materials. or other special materials.
*/ */
struct S3DVertex2TCoords struct S3DVertex2TCoords : S3DVertex
{ {
//! default constructor //! default constructor
S3DVertex2TCoords() {}; S3DVertex2TCoords() : S3DVertex() {};
//! constructor with two different texture coords //! constructor with two different texture coords, but no normal
S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2) S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
: Pos(x,y,z), Color(c), TCoords(tu,tv), TCoords2(tu2,tv2) {} : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
//! constructor with two different texture coords //! constructor with two different texture coords, but no normal
S3DVertex2TCoords(const core::vector3df& pos, SColor color, S3DVertex2TCoords(const core::vector3df& pos, SColor color,
const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2) const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
: Pos(pos), Color(color), TCoords(tcoords), TCoords2(tcoords2) {} : S3DVertex(pos, core::vector3df(0.0f, 0.0f, 0.0f), color, tcoords), TCoords2(tcoords2) {}
//! constructor //! constructor with all values
S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color, S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2) const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
: Pos(pos), Normal(normal), Color(color), TCoords(tcoords), TCoords2(tcoords2) {} : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
//! constructor with the same texture coords and normal //! constructor with the same texture coords and normal
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv) S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
: Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv), TCoords2(tu,tv) {} : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
//! constructor with the same texture coords and normal //! constructor with the same texture coords and normal
S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
SColor color, const core::vector2d<f32>& tcoords) SColor color, const core::vector2d<f32>& tcoords)
: Pos(pos), Normal(normal), Color(color), TCoords(tcoords), TCoords2(tcoords) {} : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
//! constructor from S3DVertex //! constructor from S3DVertex
S3DVertex2TCoords(S3DVertex& o) S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
: Pos(o.Pos), Normal(o.Normal), Color(o.Color), TCoords(o.TCoords) {}
//! Position
core::vector3df Pos;
//! Normal
core::vector3df Normal;
//! Color
SColor Color;
//! First set of texture coordinates
core::vector2d<f32> TCoords;
//! Second set of texture coordinates //! Second set of texture coordinates
core::vector2d<f32> TCoords2; core::vector2d<f32> TCoords2;
...@@ -129,16 +116,14 @@ struct S3DVertex2TCoords ...@@ -129,16 +116,14 @@ struct S3DVertex2TCoords
//! Equality operator //! Equality operator
bool operator == (const S3DVertex2TCoords& other) const bool operator == (const S3DVertex2TCoords& other) const
{ {
return (Pos == other.Pos && Normal == other.Normal && return (static_cast<S3DVertex>(*this)==other &&
Color == other.Color && TCoords == other.TCoords &&
TCoords2 == other.TCoords2); TCoords2 == other.TCoords2);
} }
//! Inequality operator //! Inequality operator
bool operator != (const S3DVertex2TCoords& other) const bool operator != (const S3DVertex2TCoords& other) const
{ {
return (Pos != other.Pos || Normal != other.Normal || return (static_cast<S3DVertex>(*this)!=other &&
Color != other.Color || TCoords != other.TCoords ||
TCoords2 != other.TCoords2); TCoords2 != other.TCoords2);
} }
...@@ -152,31 +137,27 @@ struct S3DVertex2TCoords ...@@ -152,31 +137,27 @@ struct S3DVertex2TCoords
//! Vertex with a tangent and binormal vector. //! Vertex with a tangent and binormal vector.
/** Usually used for tangent space normal mapping. /** Usually used for tangent space normal mapping.
*/ */
struct S3DVertexTangents struct S3DVertexTangents : S3DVertex
{ {
//! default constructor //! default constructor
S3DVertexTangents() { }; S3DVertexTangents() : S3DVertex() { }
//! constructor //! constructor
S3DVertexTangents(f32 x, f32 y, f32 z) 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)
: Pos(x,y,z) { } : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
//! constructor //! constructor
S3DVertexTangents(const core::vector3df& pos, S3DVertexTangents(const core::vector3df& pos, SColor c,
const core::vector2df& tcoords, SColor c) const core::vector2df& tcoords)
: Pos(pos), Color(c), TCoords(tcoords) { } : S3DVertex(pos, core::vector3df(0.0f, 0.0f, 0.0f), c, tcoords) { }
//! Position
core::vector3df Pos;
//! Normal vector
core::vector3df Normal;
//! Color
SColor Color;
//! Texture coordinates //! constructor
core::vector2d<f32> TCoords; S3DVertexTangents(const core::vector3df& pos,
const core::vector3df& normal, SColor c,
const core::vector2df& tcoords,
const core::vector3df& tangent=core::vector3df(0.0f, 0.0f, 0.0f),
const core::vector3df& binormal=core::vector3df(0.0f, 0.0f, 0.0f))
: S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
//! Tangent vector along the x-axis of the texture //! Tangent vector along the x-axis of the texture
core::vector3df Tangent; core::vector3df Tangent;
...@@ -186,15 +167,13 @@ struct S3DVertexTangents ...@@ -186,15 +167,13 @@ struct S3DVertexTangents
bool operator == (const S3DVertexTangents& other) const bool operator == (const S3DVertexTangents& other) const
{ {
return (Pos == other.Pos && Normal == other.Normal && return (static_cast<S3DVertex>(*this)==other &&
Color == other.Color && TCoords == other.TCoords &&
Tangent == other.Tangent && Binormal == other.Binormal); Tangent == other.Tangent && Binormal == other.Binormal);
} }
bool operator != (const S3DVertexTangents& other) const bool operator != (const S3DVertexTangents& other) const
{ {
return (Pos != other.Pos || Normal != other.Normal || return (static_cast<S3DVertex>(*this)!=other &&
Color != other.Color || TCoords != other.TCoords ||
Tangent != other.Tangent || Binormal != other.Binormal); Tangent != other.Tangent || Binormal != other.Binormal);
} }
......
...@@ -711,7 +711,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const ...@@ -711,7 +711,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const
for (s32 i=0; i<idxCnt; ++i) for (s32 i=0; i<idxCnt; ++i)
buffer->Vertices.push_back( buffer->Vertices.push_back(
video::S3DVertexTangents( video::S3DVertexTangents(
v[idx[i]].Pos, v[idx[i]].TCoords, v[idx[i]].Color)); v[idx[i]].Pos, v[idx[i]].Color, v[idx[i]].TCoords));
} }
break; break;
case video::EVT_2TCOORDS: case video::EVT_2TCOORDS:
...@@ -721,7 +721,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const ...@@ -721,7 +721,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const
for (s32 i=0; i<idxCnt; ++i) for (s32 i=0; i<idxCnt; ++i)
buffer->Vertices.push_back(video::S3DVertexTangents( buffer->Vertices.push_back(video::S3DVertexTangents(
v[idx[i]].Pos, v[idx[i]].TCoords, v[idx[i]].Color)); v[idx[i]].Pos, v[idx[i]].Color, v[idx[i]].TCoords));
} }
break; break;
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment