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
/** Usually used for geometry with lightmaps
or other special materials.
*/
struct S3DVertex2TCoords
struct S3DVertex2TCoords : S3DVertex
{
//! 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)
: 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,
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,
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
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
S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal,
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
S3DVertex2TCoords(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;
S3DVertex2TCoords(S3DVertex& o) : S3DVertex(o) {}
//! Second set of texture coordinates
core::vector2d<f32> TCoords2;
......@@ -129,16 +116,14 @@ struct S3DVertex2TCoords
//! Equality operator
bool operator == (const S3DVertex2TCoords& other) const
{
return (Pos == other.Pos && Normal == other.Normal &&
Color == other.Color && TCoords == other.TCoords &&
return (static_cast<S3DVertex>(*this)==other &&
TCoords2 == other.TCoords2);
}
//! Inequality operator
bool operator != (const S3DVertex2TCoords& other) const
{
return (Pos != other.Pos || Normal != other.Normal ||
Color != other.Color || TCoords != other.TCoords ||
return (static_cast<S3DVertex>(*this)!=other &&
TCoords2 != other.TCoords2);
}
......@@ -152,31 +137,27 @@ struct S3DVertex2TCoords
//! Vertex with a tangent and binormal vector.
/** Usually used for tangent space normal mapping.
*/
struct S3DVertexTangents
struct S3DVertexTangents : S3DVertex
{
//! default constructor
S3DVertexTangents() { };
S3DVertexTangents() : S3DVertex() { }
//! constructor
S3DVertexTangents(f32 x, f32 y, f32 z)
: Pos(x,y,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)
: S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
//! constructor
S3DVertexTangents(const core::vector3df& pos,
const core::vector2df& tcoords, SColor c)
: Pos(pos), Color(c), TCoords(tcoords) { }
//! Position
core::vector3df Pos;
//! Normal vector
core::vector3df Normal;
//! Color
SColor Color;
S3DVertexTangents(const core::vector3df& pos, SColor c,
const core::vector2df& tcoords)
: S3DVertex(pos, core::vector3df(0.0f, 0.0f, 0.0f), c, tcoords) { }
//! Texture coordinates
core::vector2d<f32> TCoords;
//! constructor
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
core::vector3df Tangent;
......@@ -186,15 +167,13 @@ struct S3DVertexTangents
bool operator == (const S3DVertexTangents& other) const
{
return (Pos == other.Pos && Normal == other.Normal &&
Color == other.Color && TCoords == other.TCoords &&
return (static_cast<S3DVertex>(*this)==other &&
Tangent == other.Tangent && Binormal == other.Binormal);
}
bool operator != (const S3DVertexTangents& other) const
{
return (Pos != other.Pos || Normal != other.Normal ||
Color != other.Color || TCoords != other.TCoords ||
return (static_cast<S3DVertex>(*this)!=other &&
Tangent != other.Tangent || Binormal != other.Binormal);
}
......
......@@ -711,7 +711,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const
for (s32 i=0; i<idxCnt; ++i)
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;
case video::EVT_2TCOORDS:
......@@ -721,7 +721,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const
for (s32 i=0; i<idxCnt; ++i)
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;
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