Game Development Reference
In-Depth Information
4.
Actual data holders are made public for convenience:
public:
// position X, Y, Z
std::vector<LVector3> FVertices;
// texture coordinate U, V
std::vector<LVector2> FTexCoords;
// normal in object space
std::vector<LVector3> FNormals;
// RGBA color
std::vector<LVector4> FColors;
};
How it works…
To use clVertexAttribs and populate it with useful data, we declare a few helper
functions:
clPtr<clVertexAttribs> CreateTriangle2D( float vX, float vY,
float dX, float dY, float Z );
clPtr<clVertexAttribs> CreateRect2D( float X1, float Y1, float X2,
float Y2, float Z, bool FlipTexCoordsVertical,
int Subdivide );
clPtr<clVertexAttribs> CreateAxisAlignedBox( const LVector3& Min,
const LVector3& Max );
clPtr<clVertexAttribs> CreatePlane( float SizeX, float SizeY,
int SegmentsX, int SegmentsY, float Z );
The following is an example deinition of one of these:
clPtr<clVertexAttribs> clGeomServ::CreateTriangle2D( float vX,
float vY, float dX, float dY, float Z )
{
clPtr<clVertexAttribs> VA = new clVertexAttribs();
Restart the regeneration and allocate space for 3 vertices:
VA->Restart( 3 );
VA->SetNormalV( LVector3( 0, 0, 1 ) );
VA->SetTexCoord( 1, 1, 0 );
VA->EmitVertexV( LVector3( vX , vY , Z ) );
VA->SetTexCoord( 1, 0, 0 );
VA->EmitVertexV( LVector3( vX , vY - dY, Z ) );
VA->SetTexCoord( 0, 1, 0 );
VA->EmitVertexV( LVector3( vX + dX, vY , Z ) );
return VA;
}
 
Search WWH ::




Custom Search