示例#1
0
triple_t diffuse_illumination(
   model_t  *model,        /* pointer to model structure     */
   obj_t    *hitobj)       /* object that was hit by the ray */
{
/****variables****/
   obj_t *currlight;
   list_t *lightlist;
   triple_t total_illumination;
   triple_t processed_light;
/*****************/

   //Point to list of lights in the model
   lightlist = model->lights;

   //Initialize to zero
   total_illumination = tl_scale3(&total_illumination, 0);
   processed_light = tl_scale3(&processed_light, 0);
   
   //Reset list so that position points to head
   l_reset(lightlist);

   //Walk through the lights list and process each light
   //Sum up the total illumination
   while((currlight = l_get(lightlist)) != NULL)
   {
      processed_light = process_light(model->scene, hitobj, currlight->lightData);
      total_illumination = tl_sum3(&total_illumination, &processed_light);
   }

   return total_illumination;
}
示例#2
0
void S_render(Screen * screen)
{
    for(size_t i = 0;i < l_length(&screen->mRenderQueue);i++)
    {
        imgKey key = l_get(&screen->mRenderQueue,i)->mKey;
        S_apply(screen,&key.mImage);
    }
}
示例#3
0
/** model_dump **/
void model_dump(model_t *model) {
/****variables****/
   obj_t *obj;
   int ctr;
   int flag;
/*****************/
   
   l_reset(model->scene);
   l_reset(model->lights);

   while ((obj = l_get(model->scene)) != NULL)
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, (helper[ctr]).objecttype) == 0) {
            (helper[ctr]).dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }

   while ((obj = l_get(model->lights)) != NULL)
   {
      flag = 0;
      for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
         if(strcmp(obj->objclass, helper[ctr].objecttype) == 0) {
            helper[ctr].dump(obj);
            flag = 1;
            break;
         }
      }
      if(flag == 0) {
         fprintf(stderr, "Bad class\n");
         exit(1);
      }
   }
}
示例#4
0
文件: ray.c 项目: Kuwagata/Raytracer
obj_t *find_closest_obj(list_t *scene, triple_t *base, triple_t *unitDir, obj_t *lasthit){
/****variables****/
   obj_t *obj;
   obj_t *clstobj;
   double dist;
/*****************/
   
   // Reset the scene list and initate variables
   l_reset(scene);
   clstobj = NULL;
   obj = NULL;
   dist = 0;
   
   // Run through the scene list
   while ((obj = ((obj_t *)l_get(scene))) != NULL)
   {
      // If the object is the last hit, don't do anything as it is a waste
      if(obj != lasthit) {
         // Call the object's hits function
         dist = obj->sceneData->hits(base, unitDir, obj);
         
         // If the distance is negative, it missed
         if(dist > 0) {
            // First hit scenario -- auto assigns
            if(clstobj == NULL) {
               clstobj = obj;
            }
            else {
               // Multiple hit objects scenario -- checks to see who is closest
               if(dist < clstobj->sceneData->distance){
                  clstobj = obj;
               }
            }
         }
      }
   }
   return clstobj;
}