コード例 #1
0
ファイル: raytrace.c プロジェクト: jrubill/2100
entity_t *closest(scene_t *scene, point_t base, vector_t unitDir, 
                  entity_t *self, hitinfo_t *hit) {
	// set up iterator for sobjList and create sentinel value for
	// min distance
	iterator_t *iter = createIterator(scene->sobjList);
	entity_t *temp = list_getnext(iter);
	// set sentinel value
	hit->distance = 9999;
	sobj_t *sobj = NULL;
	entity_t *closest = NULL;
	// temporary hit info
	hitinfo_t tempHit;

	// loop through the entire sobjList
	while (temp != NULL) {
		sobj = ((sobj_t*)temp->entDerived);
		/* if we have a hit, check the min distance
		 * if the mindistance previously calculated is
		 * greater, then set the new min distance
		 * and set the entity to the closest entity
		 */
		if (sobj->hits(temp, base, unitDir, &tempHit) == 1) {
			if (hit->distance > tempHit.distance 
				|| hit->distance == 9999) {
				hit->distance = tempHit.distance;
				closest = temp;
			}
		}
		temp = list_getnext(iter);
	}
	return closest;
}
コード例 #2
0
ファイル: list.c プロジェクト: lmaddalena/List
//
// Restituisce l'elemento alla posizione specificata
//
void *list_getelementat(t_list *list, int index)
{
	if (list == NULL || index < 0)
		return NULL;

	void *item = NULL;
    t_iterator *iter = list_getiterator(list);
    
	while (index-- >= 0)
		item = list_getnext(iter);

	return item;
}
コード例 #3
0
ファイル: list.c プロジェクト: lmaddalena/List
//
// restituisce il numero di elementi presenti nella lista
//
size_t list_getsize(t_list *list){

	void *item = NULL;
	size_t c = 0;
    
    t_iterator *iter = list_getiterator(list);
   	while ((item = list_getnext(iter)) != NULL)
	{
		c++;
	}

	return c;
}