static errcode GetLight(parsehandle * ph, SceneHandle scene) { char tmp[255]; apiflt rad, Kc, Kl, Kq; apivector ctr; apitexture tex; float r, g, b, a; errcode rc; void * li; memset(&tex, 0, sizeof(apitexture)); rc = GetString(ph, "CENTER"); rc |= GetVector(ph, &ctr); rc |= GetString(ph, "RAD"); fscanf(ph->ifp, "%f", &a); /* read in radius */ rad=a; fscanf(ph->ifp, "%s", tmp); if (!stringcmp(tmp, "COLOR")) { fscanf(ph->ifp, "%f %f %f", &r, &g, &b); tex.col.r=r; tex.col.g=g; tex.col.b=b; li = rt_light(scene, rt_texture(scene, &tex), ctr, rad); } else { if (stringcmp(tmp, "ATTENUATION")) return -1; rc |= GetString(ph, "CONSTANT"); fscanf(ph->ifp, "%f", &a); Kc=a; rc |= GetString(ph, "LINEAR"); fscanf(ph->ifp, "%f", &a); Kl=a; rc |= GetString(ph, "QUADRATIC"); fscanf(ph->ifp, "%f", &a); Kq=a; rc |= GetColor(ph, &tex.col); li = rt_light(scene, rt_texture(scene, &tex), ctr, rad); rt_light_attenuation(li, Kc, Kl, Kq); } return rc; }
static errcode GetScenedefs(FILE * dfile, SceneHandle scene) { apivector Ccenter, Cview, Cup; apiflt zoom, aspectratio; int raydepth, antialiasing; rt_outputfile(scene, "outfile.tga"); rt_resolution(scene, 512, 512); rt_verbose(scene, 0); zoom=1.0; aspectratio=1.0; antialiasing=0; raydepth=6; Ccenter.x = 0.0; Ccenter.y = 0.0; Ccenter.z = -5.0; Cview.x = 0.0; Cview.y = 0.0; Cview.z = 1.0; Cup.x = 0.0; Cup.y = 1.0; Cup.z = 0.0; rt_camera_setup(scene, zoom, aspectratio, antialiasing, raydepth, Ccenter, Cview, Cup); { /* lighting hack */ apivector ctr; apitexture tex; memset(&tex, 0, sizeof(apitexture)); tex.col.r = 1.0; tex.col.g = 1.0; tex.col.b = 1.0; ctr.x = 0.0; ctr.y = 0.0; ctr.z = -100.0; rt_light(scene, rt_texture(scene, &tex), ctr, 1.0); } return PARSENOERR; }
int NFFGetLight(FILE *dfile, SceneHandle scene) { apiflt rad; apivector ctr; apitexture tex; float r, g, b; NFFGetVector(dfile, &ctr); rad = 1.0; /* XXX hack for now */ r = g = b = 1.0; fscanf(dfile, "%f %f %f", &r, &g, &b); tex.col.r = r; tex.col.g = g; tex.col.b = b; rt_light(scene, rt_texture(scene, &tex), ctr, rad); return NFFNOERR; }
static errcode GetLight(FILE * dfile) { apiflt rad; vector ctr; apitexture tex; float a; errcode rc; memset(&tex, 0, sizeof(apitexture)); rc = GetString(dfile,"CENTER"); rc |= GetVector(dfile, &ctr); rc |= GetString(dfile,"RAD"); fscanf(dfile,"%f",&a); /* read in radius */ rad=a; rc |= GetColor(dfile, &tex.col); rt_light(rt_texture(&tex), ctr, rad); return rc; }
void * rt_light3fv(SceneHandle voidscene, void * tex, const float *ctr, float rad) { vector vctr; vctr.x = ctr[0]; vctr.y = ctr[1]; vctr.z = ctr[2]; return rt_light(voidscene, tex, vctr, rad); }
int main(int argc, char **argv) { SceneHandle scene; int i, j; apivector Ccenter, Cview, Cup; apivector ctr1, ctr2; apitexture tex1, tex2; void * vtx1, * vtx2; char fname[100]; rt_initialize(&argc, &argv); Ccenter.x=0.0; Ccenter.y=0.0; Ccenter.z=-3.0; Cview.x=0.0; Cview.y=0.0; Cview.z=1.0; Cup.x=0.0; Cup.y=1.0; Cup.z=0.0; ctr1.x=20.0; ctr1.y=20.0; ctr1.z=-40.0; ctr2.x=-20.0; ctr2.y=20.0; ctr2.z=-40.0; tex1.col.r=1.0; tex1.col.g=0.5; tex1.col.b=0.0; tex1.ambient=1.0; tex1.opacity=1.0; tex2=tex1; tex2.col.r=0.0; tex2.col.b=1.0; initspheres(); for (i=0; i<MAXFRAMES; i++) { scene = rt_newscene(); vtx1=rt_texture(scene, &tex1); vtx2=rt_texture(scene, &tex2); sprintf(fname,"outfile.%4.4d.tga",i); if (rt_mynode()==0) printf("Rendering: %s\n", fname); rt_outputfile(scene, fname); rt_resolution(scene, XRES, YRES); rt_verbose(scene, 0); rt_camera_setup(scene, 1.0, 1.0, 0, 5, Ccenter, Cview, Cup); movesp(); drawsp(scene); rt_light(scene, vtx1, ctr1, 1.0); rt_light(scene, vtx2, ctr2, 1.0); rt_renderscene(scene); rt_deletescene(scene); for (j=0; j<NUMSP; j++) free(sp[i].voidtex); } rt_finalize(); return 0; }