int main(int argc, char *argv[])
{
list_t mats;
list_t objs;
material_t *mat;
object_t *obj;
std::string token,name;
vec_t pos(4.0, 3.0, 5.0);
vec_t dir(0.0, 0.0,-1.0);
int firsttime=1;
// input should consist only of material definitions
// but there can be any number of material defs in the file
while(!std::cin.eof()) {
if((std::cin >> token).good()) {
if(token == "material") {
std::cin >> (mat = new material_t());
std::cerr << "loaded " << mat->getname() << std::endl;
mats.add((void *)mat);
}
if(token == "plane") {
std::cin >> (obj = new plane_t(token));
std::cerr << "loaded " << obj->getname() << std::endl;
objs.add((void *)obj);
// test hits function
pos[0] = 4.0; pos[1] = 3.0; pos[2] = 5.0;
dir[0] = 0.0; dir[1] = 0.0; dir[2] = -1.0;
test_hits(obj,pos,dir);
if(firsttime) {
// make sure we don't get a hit on a miss...shoot
// straight down at backwall
std::cerr << "vertical ray test" << std::endl;
pos[0] = 4.0; pos[1] = 3.0; pos[2] = 5.0;
dir[0] = 0.0; dir[1] = -2.1; dir[2] = 0.0;
test_hits(obj,pos,dir);
firsttime = 1-firsttime;
} else {
// make sure we don't get a hit in +z space
std::cerr << "positive z test" << std::endl;
pos[0] = 4.0; pos[1] = 3.0; pos[2] = 5.0;
dir[0] = 0.0; dir[1] = -2.1; dir[2] = -1.0;
test_hits(obj,pos,dir);
}
}
}
}
// verify that we have all materials
material_list_print(mats);
// verify that we have all materials
object_list_print(objs);
}
void test_hits(object_t *obj, vec_t& pos, vec_t& dir)
{
double dist=0.0;
obj->setlast_hit(0.0,0.0,0.0);
dist = obj->hits(pos,dir);
std::cerr << "dist to plane " << obj->getname() << " " << dist << std::endl;
std::cerr << "hit point " << obj->getlast_hit() << std::endl;
}