www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/13/22:02:12

X-ROUTED: Sat, 13 Nov 1999 21:20:44 -0500
Message-ID: <382E1BCE.7A63BA1D@greenbelt.com>
Date: Sat, 13 Nov 1999 21:17:50 -0500
From: Ed James <edjames AT greenbelt DOT com>
Organization: GIAC
X-Mailer: Mozilla 4.51 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Dynamic pointer creation
References: <0FL50055B01WP9 AT cpt-proxy1 DOT mweb DOT co DOT za>
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019