forked from cubanismo/3dsconv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathc3d.h
138 lines (116 loc) · 3.29 KB
/
c3d.h
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
/*
* Data structures for 3D renderer
*/
/*
* a light can be of 1 of two types:
* (1) an "in scene" light: this has attenuation based on distance to
* the point being illuminated
* (2) sunlight: this is just a vector
*/
typedef struct light {
#ifdef USE_FLOATS
float x,y,z; /* light position, for in scene, or normal vector for sunlight */
float bright;
#else
short x,y,z; /* light position, for in scene, or normal vector for sunlight */
unsigned short bright; /* base intensity, for in scene, or 0 for sunlight */
#endif
} Light;
/*
* a lighting model consists of:
* (1) ambient illumination (from 0-$ffff)
* (2) some number of lights
*
* we (arbitrarily) impose a limit of MAXLIGHTS lights
* per scene.
*/
#define MAXLIGHTS 8
typedef struct lightmodel {
#ifdef USE_FLOATS
float ambient;
#else
unsigned short ambient; /* ambient illumination */
#endif
short numlights; /* number of lights */
Light lights[MAXLIGHTS]; /* pointer to lights */
} Lightmodel;
/*
* transformation matrix: a 4x4 matrix, last column is always 0 0 0 1 so is not stored
* numbers are 0.14 fractions (1 = 0x4000)
*/
#ifdef USE_FLOATS
#define frac float
#else
#define frac short
#endif
typedef struct matrix {
frac xrite,yrite,zrite;
frac xdown,ydown,zdown;
frac xhead,yhead,zhead;
frac xposn,yposn,zposn;
} Matrix;
/*
* points consist of the point + its vertex normal
*/
typedef struct point {
frac x, y, z;
frac vx, vy, vz;
} Point;
typedef unsigned char Pixel;
/*
* a bitmap consists of:
* (1) the width and height of the map
* (2) line length
* (3) a pointer to the actual data
*/
typedef struct texmap {
short width, height;
long linelen;
Pixel *data;
} Bitmap;
/*
* a "material" consists of:
* a color (used for Gouraud shading)
* flags (currently unused, set to 0)
* a pointer to a bitmap used for texture
* mapping
*/
typedef struct material {
unsigned short color;
unsigned short flags;
Bitmap *tmap;
} Material;
#if 0
/* data structure for a face */
typedef struct triangle {
short npts; /* number of points (same as # of sides) */
short material; /* index into Materials table */
short fx, fy, fz, fd; /* plane equation for polygon (face normal and -normal*point) */
/* for each point, keep:
(1) the index of the point into the points or tpoints table (2 bytes)
(2) texture map coordinates (U,V) (1 byte for each of U and V)
Thus, the points[] array has 2 words (4 bytes) per point
*/
unsigned short points[6];
} Face;
#else
typedef short Face;
#endif
/* object data: many objects may share the same object data (e.g. if there are 3 identical spaceships
flying around, all 3 objects can use the same data) */
typedef struct objdata {
short numpolys; /* number of faces in object */
short numpoints; /* number of points in object */
short nummaterials; /* number of entries in the materials table */
short reserved; /* reserved for future expansion, set to 0 */
Face *faces; /* pointer to polygons */
Point *points; /* point table */
Material *materials; /* pointer to table of materials (e.g. colors) */
} C3DObjdata;
/* finally, an object: a transformation matrix, pointer to object data, plus
* whatever else we eventually decide to include.
*/
typedef struct cobject {
C3DObjdata *data;
Matrix M; /* object space -> world space transformation */
} C3DObject;