Mail Archives: djgpp/1997/07/04/18:10:57
Tan Mu Yen wrote:
>
> I am trying to write a polygon class that allows me to add vertex to it
> using linked list ... ie I can add or delete a vertex anytime using
> the polygon ...
>
> Anyone has any idea? pls help me!
I wouldn't try it if I were you, linked lists can be very useful, but
for storing vertexes (which need to be accessed often, and not always in
consecutive order) a simple array is much nicer. If you need to add &
delete vertexes, just make the array large enough to hold the maximum
number of vertexes & keep a record of how many you actually are using:
typedef struct
{
int num_verts;
VERTEX verts[MAX_VERTS];
.
.
.
} POLY;
To delete a vert 'v' just do:
memcpy(ply->verts[v],ply->verts[v+1],ply->num_verts-v-1);
where ply = POLY*. (This is slower than a linked list, but not by much,
and you're not going to be deleting verts as often as you'll be using
them.)
Just as a guess... You're trying to make an editor, aren't you? If
that's the case and you'll not be modifying the polygons in the program
that finally uses them, just write and read num_verts vertexes from the
storage file, then you'll not be wasting memory or disk space.
Hope this helps,
Sincerely,
Joshua Heyer
imwho AT hotmail DOT com
**********************************************************************
Never let your sense of morals prevent you from doing what is right.
-- Salvor Hardin, "Foundation"
**********************************************************************
- Raw text -