Mail Archives: djgpp/1999/11/13/22:02:12
Quick answer - use a 'linked-list' to hold the faces...adding a new face means
just adding a new node to the linked-list. faces becomes a pointer to the node
data structure, which is basically a face_s, which has been modified to include
a pointer to another face_s structure. To access a particular face you would
start at the head of the linked list, pointed to by faces, and traverse the
list until you find the one you want, or hit a NULL next-node pointer (end of
the list).
Marius Myburg wrote:
> Hi all,
>
> I am working on a 3D engine, and I am having a little trouble. Here are
> the relevant source
>
> //==============
> // structures
>
> typedef struct // a point
> {
> float x, y, z;
> int scrx, scry;
> int distance;
> int color;
> }point_s;
>
> typedef struct // a face (trigon)
> {
> point_s p1;
> point_s p2;
> point_s p3;
> }face_s;
>
> typedef struct // an object
> {
> face_s *faces;
> int numfaces;
> }object_s;
>
> I want the object_s structure to be able to have any number of faces, hence
> face_s *faces. But, if I want to add a face (or a pointer to a face), how
> do I do it? Also, how do I access any given face, if I have say 20
> pointers
> to 20 faces in a given object?
>
> Thank you,
> Marius Myburg
- Raw text -