intensity_t lighting(scene_t *scene, entity_t *ent, hitinfo_t *hit) { assert(ent->magic == ENTITY_T); intensity_t returnIntensity = {0,0,0}; intensity_t tmpIntensity; iterator_t *lightitr = newIterator(scene->lightList); entity_t *light; while((light = l_next(lightitr)) != NULL) { tmpIntensity = processPointLight(scene, ent, light, hit); returnIntensity.x = tmpIntensity.x + returnIntensity.x; returnIntensity.y = tmpIntensity.y + returnIntensity.y; returnIntensity.z = tmpIntensity.z + returnIntensity.z; } free(lightitr); return(returnIntensity); }
void ObjectLoader::loadLights(Object* object, XmlTreeNode* objectNode){ for(int i=0; i < objectNode->getChildNodes().size(); i++){ XmlTreeNode* lightNode = objectNode->getChildNodes()[i]; if(lightNode->getName().compare("Light")==0){ XmlNodeAttribute* typeAttribute = lightNode->searchForAttribute("type"); if(!typeAttribute){ Logger::getInstance()->logDebug(new Log("ObjectLoader#loadLights: Falta atributo \"type\" en etiqueta Light, se ignora la luz")); return; } //Busco toda la informacion de la luz //Dependiendo del tipo de luz consigo los parametros correspondientes ObjectLight* light = NULL; string lightType = typeAttribute->getValue(); if(lightType.compare("Spot")==0) light = processSpotLight(object, lightNode); else if(lightType.compare("Point")==0) light = processPointLight(object, lightNode); else if(lightType.compare("PointDiffuse")==0) light = processPointDiffuseLight(object, lightNode); else if(lightType.compare("Directional")==0) light = processDirectionalLight(object, lightNode); else{ Logger::getInstance()->logDebug(new Log("ObjectLoader#loadLights: Atributo \"type\" invalido, se ignora la luz")); return; } //Cargo la sombra si es que hay XmlNodeAttribute* shadowAtt = lightNode->searchForAttribute("castShadow"); if((shadowAtt)&&(shadowAtt->getValue().compare("true")==0)){ processShadow(lightNode, light); } // Agrego la luz al objeto object->addLight(light); } } }