12 |
|
#include "rtio.h" |
13 |
|
#include "rterror.h" |
14 |
|
#include "fvect.h" |
15 |
< |
#include <stdlib.h> |
15 |
> |
#include "paths.h" |
16 |
|
#include <ctype.h> |
17 |
|
#include "objutil.h" |
18 |
|
|
115 |
|
error(USER, errmsg); |
116 |
|
} |
117 |
|
|
118 |
– |
/* Add a vertex to our scene */ |
119 |
– |
static void |
120 |
– |
add_vertex(Scene *sc, double x, double y, double z) |
121 |
– |
{ |
122 |
– |
sc->vert = chunk_alloc(Vertex, sc->vert, sc->nverts); |
123 |
– |
sc->vert[sc->nverts].p[0] = x; |
124 |
– |
sc->vert[sc->nverts].p[1] = y; |
125 |
– |
sc->vert[sc->nverts].p[2] = z; |
126 |
– |
sc->vert[sc->nverts++].vflist = NULL; |
127 |
– |
} |
128 |
– |
|
129 |
– |
/* Add a texture coordinate to our scene */ |
130 |
– |
static void |
131 |
– |
add_texture(Scene *sc, double u, double v) |
132 |
– |
{ |
133 |
– |
sc->tex = chunk_alloc(TexCoord, sc->tex, sc->ntex); |
134 |
– |
sc->tex[sc->ntex].u = u; |
135 |
– |
sc->tex[sc->ntex].v = v; |
136 |
– |
sc->ntex++; |
137 |
– |
} |
138 |
– |
|
139 |
– |
/* Add a surface normal to our scene */ |
140 |
– |
static int |
141 |
– |
add_normal(Scene *sc, double xn, double yn, double zn) |
142 |
– |
{ |
143 |
– |
FVECT nrm; |
144 |
– |
|
145 |
– |
nrm[0] = xn; nrm[1] = yn; nrm[2] = zn; |
146 |
– |
if (normalize(nrm) == .0) |
147 |
– |
return(0); |
148 |
– |
sc->norm = chunk_alloc(Normal, sc->norm, sc->nnorms); |
149 |
– |
VCOPY(sc->norm[sc->nnorms], nrm); |
150 |
– |
sc->nnorms++; |
151 |
– |
return(1); |
152 |
– |
} |
153 |
– |
|
118 |
|
/* combine multi-group name into single identifier w/o spaces */ |
119 |
|
static char * |
120 |
|
group_name(int ac, char **av) |
143 |
|
return(nambuf); |
144 |
|
} |
145 |
|
|
182 |
– |
/* set current group */ |
183 |
– |
static void |
184 |
– |
set_group(Scene *sc, const char *nm) |
185 |
– |
{ |
186 |
– |
sc->lastgrp = findName(nm, (const char **)sc->grpname, sc->ngrps); |
187 |
– |
if (sc->lastgrp >= 0) |
188 |
– |
return; |
189 |
– |
sc->grpname = chunk_alloc(char *, sc->grpname, sc->ngrps); |
190 |
– |
sc->grpname[sc->lastgrp=sc->ngrps++] = savqstr((char *)nm); |
191 |
– |
} |
192 |
– |
|
193 |
– |
/* set current material */ |
194 |
– |
static void |
195 |
– |
set_material(Scene *sc, const char *nm) |
196 |
– |
{ |
197 |
– |
sc->lastmat = findName(nm, (const char **)sc->matname, sc->nmats); |
198 |
– |
if (sc->lastmat >= 0) |
199 |
– |
return; |
200 |
– |
sc->matname = chunk_alloc(char *, sc->matname, sc->nmats); |
201 |
– |
sc->matname[sc->lastmat=sc->nmats++] = savqstr((char *)nm); |
202 |
– |
} |
203 |
– |
|
146 |
|
/* Add a new face to scene */ |
147 |
|
static int |
148 |
|
add_face(Scene *sc, const VNDX ondx, int ac, char *av[]) |
230 |
|
syntax(fspec, "bad vertex"); |
231 |
|
goto failure; |
232 |
|
} |
233 |
< |
add_vertex(sc, atof(argv[1]), |
233 |
> |
addVertex(sc, atof(argv[1]), |
234 |
|
atof(argv[2]), |
235 |
|
atof(argv[3])); |
236 |
|
break; |
239 |
|
goto unknown; |
240 |
|
if (badarg(argc-1,argv+1,"ff")) |
241 |
|
goto unknown; |
242 |
< |
add_texture(sc, atof(argv[1]), atof(argv[2])); |
242 |
> |
addTexture(sc, atof(argv[1]), atof(argv[2])); |
243 |
|
break; |
244 |
|
case 'n': /* normal */ |
245 |
|
if (argv[0][2]) |
248 |
|
syntax(fspec, "bad normal"); |
249 |
|
goto failure; |
250 |
|
} |
251 |
< |
if (!add_normal(sc, atof(argv[1]), |
251 |
> |
if (addNormal(sc, atof(argv[1]), |
252 |
|
atof(argv[2]), |
253 |
< |
atof(argv[3]))) { |
253 |
> |
atof(argv[3])) < 0) { |
254 |
|
syntax(fspec, "zero normal"); |
255 |
|
goto failure; |
256 |
|
} |
276 |
|
syntax(fspec, "bad # arguments"); |
277 |
|
goto failure; |
278 |
|
} |
279 |
< |
set_material(sc, argv[1]); |
279 |
> |
setMaterial(sc, argv[1]); |
280 |
|
break; |
281 |
|
case 'o': /* object name */ |
282 |
|
case 'g': /* group name */ |
284 |
|
syntax(fspec, "missing argument"); |
285 |
|
goto failure; |
286 |
|
} |
287 |
< |
set_group(sc, group_name(argc-1, argv+1)); |
287 |
> |
setGroup(sc, group_name(argc-1, argv+1)); |
288 |
|
break; |
289 |
|
case '#': /* comment */ |
290 |
|
continue; |