bead.H
12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/******************************************************************************\
Copyright 1995 The University of North Carolina at Chapel Hill.
All Rights Reserved.
Permission to use, copy, modify and distribute this software and its
documentation for educational, research and non-profit purposes, without
fee, and without a written agreement is hereby granted, provided that the
above copyright notice and the following three paragraphs appear in all
copies.
IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA
AT CHAPEL HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
UNIVERSITY OF NORTH CAROLINA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HERUNDER IS
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATIONS
TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
The author may be contacted via:
US Mail: Mike Goslin
Department of Computer Science
Sitterson Hall, CB #3175
University of N. Carolina
Chapel Hill, NC 27599-3175
Phone: (919)962-1719
EMail: goslin@cs.unc.edu
*******************************************************************************/
/*******************************************************************************
* FILENAME: bead.H
* CLASS: Bead
* DESCRIPTION:
* AUTHOR: Mike Goslin
* CREATED: 2/7/95
* REVISIONS:
*
*******************************************************************************/
#ifndef _DBBEAD_HPP_
#define _DBBEAD_HPP_
#include <string.h>
#include "flt14_1.h" // MultiGen Flight format V. 14.1 header file
#include "aux.h" // Auxiliary data to flight format
#define ID_LENGTH 32
#define MAX_SHORT_ID_LENGTH 6
#define PATH_LENGTH 512
#define MG_VTXOFFSET 400 // not used by MultiGen
#define VEC3COPY(a,b) {a[0]=b[0];a[1]=b[1];a[2]=b[2];}
#define VEC4COPY(a,b) {a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];}
#define VEC2COPY(a,b) {a[0]=b[0];a[1]=b[1];}
#define VEC3EQUAL(a,b) ((a[0]==b[0])&&(a[1]==b[1])&&(a[2]==b[2]))
#define VEC3MINUS(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
#define VEC2MINUS(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];}
#define VEC3NEG(a) {a[0]= -a[0];a[1]= -a[1];a[2]= -a[2];}
#define VEC3ADD(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
#define VEC3MULT(a,b,c) {c[0]=a*b[0];c[1]=a*b[1];c[2]=a*b[2];}
#define DOTPRODUCT(a,b,c) c=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
#define V2DOTPRODUCT(a,b,c) c=a[0]*b[0]+a[1]*b[1];
#define CROSSPRODUCT(a,b,c){c[0]=a[1]*b[2]-a[2]*b[1]; \
c[1]=a[2]*b[0]-a[0]*b[2]; \
c[2]=a[0]*b[1]-a[1]*b[0];}
#define DEFAULT_NAME "DEFAULT"
//_____________________________________________________________________________
// Lengths of flight structures: Some of these are hard-coded to avoid
// byte-alignment difficulty resulting from different compilers/platforms
// *** Check these against new flight format version changes ***
//_____________________________________________________________________________
#define FLT14_HEADER_RECORD_LENGTH 256
#define FLT13_HEADER_RECORD_LENGTH 184
#define FLT_VTXTABLE_LENGTH sizeof(mgVertTable);
#define FLT_VERT_SHARED_ABS_LENGTH 32
#define FLT_VERT_SHARED_NORM_LENGTH 48
#define FLT_VERT_SHARED_NORM_TEX_LENGTH 56
#define FLT_VERT_SHARED_ABS_TEX_LENGTH 40
#define FLT_VERT_LIST_LENGTH sizeof(mgVertList);
#define FLT_GROUP_LENGTH 28
#define FLT_OBJECT_LENGTH 28
#define FLT_POLYGON_LENGTH 44
#define FLT_COLOR_TABLE_LENGTH sizeof(mgColorTable);
#define FLT_MATERIAL_TABLE_LENGTH sizeof(mgMaterialTable);
//_____________________________________________________________________________
#define NUM_MATERIALS 64
typedef unsigned int uint;
typedef unsigned long ulong;
class Bead
{
protected:
short type;
char name[ID_LENGTH];
Bead *parent,
*next,
*prev,
*child;
public:
ushort Type(void) const { return (type); }
fltStruct(void); // returns the local flight structure
void Name(char *_name) { strcpy(name, _name); }
char *Name(void) { return name; }
// for support of traversal functions
Bead *up(void) const { return parent; }
void up(Bead *bead) { parent = bead; }
Bead *right(void) const { return next; }
void right(Bead *bead) { next = bead; }
Bead *left(void) const { return prev; }
void left(Bead *bead) { prev = bead; }
Bead *down(void) const { return child; }
void down(Bead *bead) { child = bead; }
virtual void print(void) const = 0; // for debugging
};
void printComment(const mgComment& comment);
class HeaderBead : public Bead
// First bead in a file - gives global file information
{
mgHeader fltHeader;
public:
HeaderBead(void);
HeaderBead(const mgHeader& _fltHeader);
~HeaderBead();
const mgHeader& fltStruct(void) const { return fltHeader; }
void nextGroup(short group) { fltHeader.nextGroupId = group; }
void nextObj(short obj) { fltHeader.nextObjId = obj; }
void nextPoly(short poly) { fltHeader.nextPolyId = poly; }
void print(void) const;
};
void printHeader(const mgHeader& fltHeader);
#define VERT_FUZZ 1e-10
class VertexRecordBead : public Bead
// Vertex record holds normal and color information, as well as position
{
void *fltVert; // Can handle any vertex type
// mgVertSharedAbs, mgVertSharedNorm
// mgVertSharedNormTex, or
// mgVertSharedAbsTex
vertexAux aux;
int offset;
public:
VertexRecordBead(void);
VertexRecordBead(double coord[3]);
VertexRecordBead(double coord[3], float norm[3]);
VertexRecordBead(double coord[3], float u, float v);
VertexRecordBead(double coord[3], float norm[3], float tex[2]);
VertexRecordBead(ushort _type, void* _fltVert);
~VertexRecordBead();
void* fltStruct(void) const { return fltVert; }
int Offset(void) const { return offset; }
void Offset(int _offset) { offset = _offset; }
void getPoint(double point[3]) const;
uint getNormal(float norm[3]) const;
uint getUV(float uv[2]) const;
void print(void) const;
};
void printVertexRecord(ushort type, void *fltVert);
#define VERTEX_OFFSET_LENGTH 4
class VertexOffsetBead : public Bead
{
mgVertOffset fltVertOffset;
public:
VertexOffsetBead(void);
VertexOffsetBead(int offset);
VertexOffsetBead(const mgVertOffset& _fltVertOffset);
~VertexOffsetBead();
const mgVertOffset& fltStruct(void) const { return fltVertOffset; }
int offset(void) const { return (fltVertOffset.vtxoffset); }
void print(void) const;
};
class VertexTableBead : public Bead
// Precedes the vertex table composed of vertex records of various types
{
ushort fltflag; // Indicates if source was flight file
mgVertTable fltVertTable;
VertexRecordBead *vpool,
*current;
int currentOffset;
ushort sharedVertex;
public:
VertexTableBead(void);
VertexTableBead(const mgVertTable& _fltVertTable);
~VertexTableBead();
const mgVertTable& fltStruct(void) const { return fltVertTable; }
const VertexRecordBead* vPool(void) const { return vpool; }
// Methods to add vertices to the vertex pool
int addVertex(ushort type, void* fltVert);
int addVertex(double coord[3]);
int addVertex(double coord[3], float norm[3]);
int addVertex(double coord[3], float u, float v);
int addVertex(double coord[3], float norm[3], float tex[2]);
VertexRecordBead *getVertex(int offset);
VertexRecordBead *getVertex(const VertexOffsetBead voffset);
void print(void) const;
void printVertPool(void) const;
};
void printVertexTable(const mgVertTable& fltVertTable);
class VertexListBead : public Bead
{
short fltflag;
mgVertList fltVertList;
public:
VertexListBead(void);
VertexListBead(const mgVertList& _fltVertList);
~VertexListBead();
void addOffset(void);
const mgVertList& fltStruct(void) const { return fltVertList; }
void print(void) const;
};
class GroupBead : public Bead
{
mgGroup fltGroup;
groupAux aux;
public:
GroupBead(void);
GroupBead(char *_name);
GroupBead(const mgGroup& _fltGroup);
const mgGroup& fltStruct(void) const { return fltGroup; }
const groupAux& auxStruct(void) const { return aux; }
void LongID(char *name);
void print(void) const;
};
void printGroup(const mgGroup& fltGroup);
class SwitchBead : public Bead
{
mgSwitch fltSwitch;
public:
SwitchBead(void);
SwitchBead(const mgSwitch& _fltSwitch);
void print(void) const;
};
class DofBead : public Bead
{
mgDof fltDof;
public:
DofBead(void);
DofBead(const mgDof& _fltDof);
const mgDof& fltStruct(void) const { return fltDof; }
void print(void) const;
};
class LodBead : public Bead
{
mgLod fltLod;
public:
LodBead(void);
LodBead(const mgLod& _fltLod);
const mgLod& fltStruct(void) const { return fltLod; }
void print(void) const;
};
class FLodBead : public Bead
{
mgFLod fltLod;
public:
FLodBead(void);
FLodBead(const mgFLod& _fltLod);
const mgFLod& fltStruct(void) const { return fltLod; }
void print(void) const;
};
class ObjectBead : public Bead
{
mgObject fltObject;
objectAux aux;
public:
ObjectBead(void);
ObjectBead(char *_name);
ObjectBead(const mgObject& _fltObject);
const mgObject& fltStruct(void) const { return fltObject; }
const objectAux& auxStruct(void) const { return aux; }
void LongID(char *name);
void print(void) const;
};
void printObject(const mgObject& fltObject);
class PolygonBead : public Bead
{
mgPolygon fltPoly;
polygonAux aux;
public:
PolygonBead(void);
PolygonBead(char *_name);
PolygonBead(const mgPolygon& _fltPoly);
const mgPolygon& fltStruct(void) const { return fltPoly; }
const polygonAux& auxStruct(void) const { return aux; }
void textureIndex(short index) { fltPoly.texture = index; }
short textureIndex(void) { return (fltPoly.texture); }
void colorIndex(short index) { fltPoly.color1 = index; }
short colorIndex(void) { return (fltPoly.color1); }
void Comment(char *comment);
void Comment(mgComment& comment);
void print(void) const;
};
void printPolygon(const mgPolygon& fltPoly);
void printPolygonAux(const polygonAux& aux);
#define COLOR_INTENSITIES 128
#define NUM_INTERP_COLORS 28
#define TOTAL_INTERP_COLORS NUM_INTERP_COLORS * COLOR_INTENSITIES
#define CT_SPARE 4
#define TOTAL_SPARE CT_SPARE * COLOR_INTENSITIES
#define TOTAL_INTERP_PLUS_SPARE 4096
#define NUM_FIXED_COLORS 56
class ColorTableBead : public Bead
{
mgColorTable fltColTable;
ulong fixedColorCount;
public:
ColorTableBead(void);
ColorTableBead(const mgColorTable& _fltColTable);
~ColorTableBead();
const mgColorTable& fltStruct(void) const { return fltColTable; }
ulong add(short value[3]);
ulong add(short value[3], int delta);
void print(void) const;
};
void printColorTable(const mgColorTable& fltColTable);
uint convertRGB(const mgColorTable& fltColTable, short index, double color[3]);
class MaterialTableBead : public Bead
{
mgMaterialTable fltMatTable;
public:
MaterialTableBead(void); // flight file doesn't require a mat. table
MaterialTableBead(const mgMaterialTable& _fltMatTable);
~MaterialTableBead();
const mgMaterialTable& fltStruct(void) const { return fltMatTable; }
void print(void) const;
};
void printMaterialTable(const mgMaterialTable& fltMatTable, int matCnt=64);
class TextureBead : public Bead
{
char path[PATH_LENGTH];
mgTextureRef fltTexRef;
public:
TextureBead(void);
TextureBead(const mgTextureRef& _fltTexRef);
TextureBead(char *texfilename, long index=0, long x=0, long y=0);
~TextureBead();
const mgTextureRef& fltStruct(void) const { return fltTexRef; }
long Index(void) const { return (fltTexRef.index); }
void Index(long _index) { fltTexRef.index = _index; }
void print(void) const;
};
void printTextureRef(const mgTextureRef& fltTexRef);
#define MG_TEXTURE_ATTR 871
class TextureAttrBead : public Bead
{
FILE *file;
char path[PATH_LENGTH];
mgTextureAttr fltTexAttr;
public:
TextureAttrBead(void);
TextureAttrBead(const mgTextureAttr& _fltTexAttr);
TextureAttrBead(char *texfilename, uint size);
~TextureAttrBead();
const mgTextureAttr& fltStruct(void) const { return fltTexAttr; }
void width(long _width) { fltTexAttr.width = _width; }
void height(long _height) { fltTexAttr.height = _height; }
uint Write(void);
void print(void) const;
};
void printTextureAttr(const mgTextureAttr& fltTexAttr);
#endif