I've been working on a game idea for awhile now and I'm having difficulty with makeing and drawing polygons. I've had success with what I made, but the foundation is weak. Basically, the NODE holds the information, the Edge will point to two known NODEs and for future development the FACE will point to three EDGES.
/***************/
//From file Polygon.h
class Polygon
{
public:
struct Nodes
{
double x;
double y;
double z;
Nodes( double x0 = 0, double y0 = 0, double z0 = 0 ): x(x0), y(y0), z(z0) {}
};
struct Edges
{
Nodes * start;
Nodes * end;
Edges( Nodes * a = NULL, Nodes * b = NULL ): start(a), end(b) {}
};
public:
Polygon( Nodes * n = NULL, int n_num = 0, Edges * e = NULL, int e_num = 0 ): nodes(n), nodes_num(n_num), edges(e), edges_num(e_num) {}
~Polygon();
void draw( Monitor * m );
Nodes addNode( const Nodes & n );
Edges addEdge( const Edges & e );
void subNode( Nodes & n );
void subEdge( Edges * e );
void setNodes( Nodes * x, int a );
void setEdges( Edges * x, int a );
Nodes * getNodes() { return nodes; }
Edges * getEdges() { return edges; }
int getNodesNum() { return nodes_num; }
int getEdgesNum() { return edges_num; }
private:
Nodes * nodes;
int nodes_num;
Edges * edges;
int edges_num;
};
/************/
//From file Polygon.cpp
#include "Polygon.h"
Polygon::~Polygon()
{
delete [] nodes;
delete [] edges;
}
void Polygon::draw( Monitor * m )
{
for( int temp = 0; temp < edges_num; temp++ )
m->DrawLine( int( edges[temp].start->x ), int( edges[temp].start->y ),
int( edges[temp].end->x ), int( edges[temp].end->y ),
WHITE );
}
Polygon::Nodes Polygon::addNode( const Nodes & n )
{
Nodes * temp = new Nodes[ getNodesNum() + 1 ];
int a = 0;
for( a = 0; a < getNodesNum(); a++ )
{
temp[a] = getNodes()[a];
}
temp[a] = n;
setNodes( temp, getNodesNum() + 1 );
return temp[a];
}
Polygon::Edges Polygon::addEdge( const Edges & e )
{
Edges * temp = new Edges[ getEdgesNum() + 1 ];
int a = 0;
for( a = 0; a < getEdgesNum(); a++ )
temp[a] = getEdges()[a];
temp[a] = e;
setEdges( temp, getEdgesNum() + 1 );
return *temp;
}
void Polygon::subNode( Nodes & n )
{
}
void Polygon::subEdge( Edges * e )
{
}
void Polygon::setNodes( Nodes * x, int a )
{
delete [] nodes;
nodes = x;
nodes_num = a;
}
void Polygon::setEdges( Edges * x, int a )
{
delete [] edges;
edges = x;
edges_num = a;
}
Any suggestions has to what I might be doing wrong? Or maybe changes to make it better? The more universal the better.