Vertex and Polygon formats

Started by
3 comments, last by MessageBox 20 years, 6 months ago
Vertex and polygon formats I want to standardize the vertex and polygon formats I use before I get too deep into programming my engine. So I thought I''d ask what everyone else is using This is what I''m using at the moment:

// Just the member variables shown

class VERTEX
{
public:
	float x, y, z;
	float nx, ny, nz;
	float tu, tv;
};

class POLYGON
{
public:
	int	verts[3]; // vert indices

	int	texid;
}
Would it be wise to store a list of neighbouring polygons in the polygon class, for example?
Advertisement
What emidiatly come to my mind is to store the uv-coordinates in a seperate array. In your Struct you can only assign one pair of uv-coordinates to a vertex. This hinders you later, when you implement multitexturing. I''m using different Arrays for Vertices,Normalvectors,Colors and UV-Tables.

My Struct''s look like:

typedef struct lwtVertex lwVertex;struct lwtVertex{  lwFloat x;   lwFloat y;     lwFloat z; };typedef struct lwtTriangle   lwTriangle;struct lwtTriangle{	int       vec[3];  /* vertextableindex*/        lwVertex  vn;      /* normalvector of the face*/};typedef struct UVCoordsType lwUVCoords;typedef struct UV3CoordsType lwUV3Coords;typedef struct SurfaceTypeDef lwSurface;/* this will be used by polygons (like portals)*/struct UVCoordsType{  lwFloat u,v;};/* this will be used by triangles */struct UV3CoordsType{  lwFloat u[3];  lwFloat v[3];};struct SurfaceTypeDef{   int           type;   lwFloat       alpha;   int           texture;   int           material;   union Surface   {     lwUV3Coords  *triangle;     lwUVCoords   *polygon;   } uvtable;};typedef struct MeshHItemType  lwHItemMesh;struct MeshHItemType{	int         maxvertices;   /* size of vertextable */	int         vertices;	   /* number of used vertices */	lwVertex   *vertextab;     /* pointer to vertextable */	lwVertex   *normaltab;     /* vertexnormals */	int         maxtriangles;  /* size of meshtable */	int         triangles;     /* number of used triangles */	lwTriangle *triangletab;   /* pointer to triangletable */	int         numsurfaces;   /* Number of Surfaces */     	lwSurface   surface[lwMaxSurfaces];   /* Surfacedata */};


This structs are a cut out of the Lapwing-Engine structures. This Engine is being designed for use with OpenGL under Linux and Windows. The Engine itself is written entirely in C.

See "lapwing.games-net.de" for some pictures. Look under "Lapwing/Bilder". Sorry, but the site is german only.
I dont like that way of storing the coords, normal and texcoords in one class/struct. I have a Vector3 and Vector2 classes with an overloaded (float *) operator that makes easy to 'communicate' with OpenGL (thanks to 3D Game Engine Design for the idea).

Vector3 akVerts[100];glVertexPointer( (float*) akVerts); 


[edited by - tiutiu on September 25, 2003 7:35:05 AM]
I use that VERTEX structure but just an array of them for the object. That way you can use line lists, or tri-strips or whatever. 32 byte vertices are the most efficient.

Mark
tiutiu : why would you need to overload float* operator? It works just fine without.

example:
class CVertex {public:   CVector3 position, normal;   CColor4 color;   ...}CVertex vertices[ 150 ];glVertexPointer( 3, GL_FLOAT, sizeof( CVertex ), &vertices[ 0 ].position );glNormalPointer( 3, GL_FLOAT, sizeof( CVertex ), &vertices[ 0 ].normal);glColorPointer( 4, GL_FLOAT, sizeof( CVertex ), &vertices[ 0 ].color);


Edit: And just one more thing. gl*Pointer takes as last argument void pointer, not float pointer.


You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on September 26, 2003 5:28:47 AM]

[edited by - _DarkWIng_ on September 26, 2003 5:29:09 AM]
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement