/* mattest.c */ #include "ray.h" int main() { model_t mod; model_t *model = &mod; material_t *mat; char entity[16]; drgb_t dpix; int count; /* Create a material list */ model->mats = list_init(); /* Input should consist only of material definitions */ count = fscanf(stdin, "%s", entity); /* but there can be any number of material defs in the file */ while (count == 1) { /* create material_t structure and read attributes */ material_init(stdin, model, 0); /* this test is designed to ensure that list_add */ /* pointed current to the material just loaded */ mat = (material_t *)list_get_entity(model->mats); assert(mat->cookie == MAT_COOKIE); fprintf(stderr, "loaded %s \n", mat->name); count = fscanf(stdin, "%s", entity); } /* Read them all in .. now try to print them */ material_list_print(model, stderr); /* See if we can find the first in the list */ mat = material_getbyname(model, "blue"); assert(mat->cookie == MAT_COOKIE); fprintf(stderr, "found %s \n", mat->name); material_getamb(mat, dpix); vec_print(stderr, "ambient is: ", dpix); /* See if we can find the last one */ mat = material_getbyname(model, "yellow"); assert(mat->cookie == MAT_COOKIE); fprintf(stderr, "found %s \n", mat->name); material_getamb(mat, dpix); vec_print(stderr, "ambient is: ", dpix); /* See what happens if we try to find a non-existent element */ mat = material_getbyname(model, "chartreuse"); assert(mat == NULL); return(0); }