]> git.mxchange.org Git - flightgear.git/blob - Stripe_u/init.c
Rearrange a bit of code ...
[flightgear.git] / Stripe_u / init.c
1 /********************************************************************/
2 /*   STRIPE: converting a polygonal model to triangle strips    
3      Francine Evans, 1996.
4      SUNY @ Stony Brook
5      Advisors: Steven Skiena and Amitabh Varshney
6 */
7 /********************************************************************/
8
9 /*---------------------------------------------------------------------*/
10 /*   STRIPE: init.c
11      This file contains the initialization of data structures.
12 */
13 /*---------------------------------------------------------------------*/
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "global.h"
18 #include "polverts.h"
19
20 void init_vert_norms(int num_vert)
21 {
22      /*   Initialize vertex/normal array to have all zeros to
23           start with.
24      */
25      register int x;
26
27      for (x = 0; x < num_vert; x++)
28           *(vert_norms + x) = 0;
29 }
30
31 void init_vert_texture(int num_vert)
32 {
33      /*   Initialize vertex/normal array to have all zeros to
34           start with.
35      */
36      register int x;
37
38      for (x = 0; x < num_vert; x++)
39           *(vert_texture + x) = 0;
40 }
41
42 BOOL InitVertTable( int nSize )
43 {
44      register int nIndex;
45
46         /*   Initialize the vertex table */
47      PolVerts = (ListHead**) malloc(sizeof(ListHead*) * nSize ); 
48         if ( PolVerts )
49         {
50                 for ( nIndex=0; nIndex < nSize; nIndex++ )
51                 {
52                         PolVerts[nIndex] = NULL;
53                 }
54                 return( TRUE ); 
55         }
56         return( FALSE );
57 }  
58
59 BOOL InitFaceTable( int nSize )
60 {
61         register int nIndex;
62
63         /*     Initialize the face table */
64         PolFaces = (ListHead**) malloc(sizeof(ListHead*) * nSize ); 
65         if ( PolFaces )
66         {
67                 for ( nIndex=0; nIndex < nSize; nIndex++ )
68                 {
69                         PolFaces[nIndex] = NULL;
70                 }
71                 return( TRUE );
72         }
73         return( FALSE );
74
75
76 BOOL InitEdgeTable( int nSize )
77 {
78         register int nIndex;
79
80         /*     Initialize the edge table */
81         PolEdges = (ListHead**) malloc(sizeof(ListHead*) * nSize );
82         if ( PolEdges )
83         {
84                 for ( nIndex=0; nIndex < nSize; nIndex++ )
85                 {
86                         PolEdges[nIndex] = NULL;
87                 }
88                 return( TRUE );
89         }
90         return( FALSE );
91 }
92
93
94 void InitStripTable(  )
95 {
96
97      PLISTHEAD pListHead;
98
99      /*   Initialize the strip table */
100      pListHead = ( PLISTHEAD ) malloc(sizeof(ListHead));
101         if ( pListHead )
102      {
103                 InitList( pListHead );
104                 strips[0] = pListHead;
105         }
106      else
107         {
108              printf("Out of memory !\n");
109                 exit(0);
110         }
111
112 }
113
114 void Init_Table_SGI()
115 {
116         PLISTHEAD pListHead;
117         int max_adj = 60;
118         register int x;
119         
120         /*   This routine will initialize the table that will
121                 have the faces sorted by the number of adjacent polygons
122                 to it.
123         */
124
125         for (x=0; x< max_adj; x++)
126         {
127                 /*   We are allowing the max number of sides of a polygon
128                         to be max_adj.
129                 */                      
130                 pListHead = ( PLISTHEAD ) malloc(sizeof(ListHead));
131                 if ( pListHead )
132              {
133                         InitList( pListHead );
134                         array[x] = pListHead;
135                 }
136              else
137                 {
138                      printf("Out of memory !\n");
139                         exit(0);
140                 }
141         }
142 }
143
144 void BuildVertTable( int nSize )
145 {
146      register int nIndex;
147      PLISTHEAD pListHead;
148         
149         for ( nIndex=0; nIndex < nSize; nIndex++ )
150         {
151                 pListHead = ( PLISTHEAD ) malloc(sizeof(ListHead));
152                 if ( pListHead )
153                 {
154                         InitList( pListHead );
155                         PolVerts[nIndex] = pListHead;
156                 }
157                 else
158                         return; 
159                 
160         }
161 }
162    
163
164 void BuildFaceTable( int nSize )
165 {
166         register int nIndex;
167         PLISTHEAD pListHead;
168         
169         for ( nIndex=0; nIndex < nSize; nIndex++ )
170         {
171                 pListHead = ( PLISTHEAD ) malloc(sizeof(ListHead));
172                 if ( pListHead )
173                 {
174                         InitList( pListHead );
175                         PolFaces[nIndex] = pListHead;
176                 }
177                 else
178                         return; 
179                 
180         }
181 }
182    
183 void BuildEdgeTable( int nSize )
184 {
185         register int nIndex;
186         PLISTHEAD pListHead;
187
188         for ( nIndex=0; nIndex < nSize; nIndex++ )
189         {
190                 pListHead = ( PLISTHEAD ) malloc(sizeof(ListHead));
191                 if ( pListHead )
192                 {
193                         InitList( pListHead );
194                         PolEdges[nIndex] = pListHead;
195                 }
196                 else
197                         return;
198         }
199 }
200
201 void Start_Face_Struct(int numfaces)
202 {
203         if (InitFaceTable(numfaces))
204         {
205                 BuildFaceTable(numfaces);
206         }
207 }
208
209 void Start_Edge_Struct(int numverts)
210 {
211         if (InitEdgeTable(numverts))
212         {
213                 BuildEdgeTable(numverts);
214         }
215 }
216
217