src/container.cc
branchpyrit
changeset 28 ffe83ca074f3
parent 24 d0d76e8a5203
child 34 28f6e8b9d5d1
equal deleted inserted replaced
27:e9bb83c2b8b9 28:ffe83ca074f3
     1 #include "common.h"
     1 #include "common.h"
     2 #include "container.h"
     2 #include "container.h"
     3 
     3 
     4 void Container::addShape(Shape* aShape)
     4 void Container::addShape(Shape* aShape)
     5 {
     5 {
     6         shapes.push_back(aShape);
     6 	shapes.push_back(aShape);
     7         if (shapes.size() == 0) {
     7 	if (shapes.size() == 0) {
     8                 /* initialize bounding box */
     8 		/* initialize bounding box */
     9                 bbox = aShape->get_bbox();
     9 		bbox = aShape->get_bbox();
    10         } else {
    10 	} else {
    11                 /* adjust bounding box */
    11 		/* adjust bounding box */
    12                 BBox shapebb = aShape->get_bbox();
    12 		BBox shapebb = aShape->get_bbox();
    13                 if (shapebb.L.x < bbox.L.x)  bbox.L.x = shapebb.L.x;
    13 		if (shapebb.L.x < bbox.L.x)  bbox.L.x = shapebb.L.x;
    14                 if (shapebb.L.y < bbox.L.y)  bbox.L.y = shapebb.L.y;
    14 		if (shapebb.L.y < bbox.L.y)  bbox.L.y = shapebb.L.y;
    15                 if (shapebb.L.z < bbox.L.z)  bbox.L.z = shapebb.L.z;
    15 		if (shapebb.L.z < bbox.L.z)  bbox.L.z = shapebb.L.z;
    16                 if (shapebb.H.x > bbox.H.x)  bbox.H.x = shapebb.H.x;
    16 		if (shapebb.H.x > bbox.H.x)  bbox.H.x = shapebb.H.x;
    17                 if (shapebb.H.y > bbox.H.y)  bbox.H.y = shapebb.H.y;
    17 		if (shapebb.H.y > bbox.H.y)  bbox.H.y = shapebb.H.y;
    18                 if (shapebb.H.z > bbox.H.z)  bbox.H.z = shapebb.H.z;
    18 		if (shapebb.H.z > bbox.H.z)  bbox.H.z = shapebb.H.z;
    19         }
    19 	}
    20 };
    20 };
    21 
    21 
    22 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    22 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    23         Float &nearest_distance)
    23         Float &nearest_distance)
    24 {
    24 {
    25         Shape *nearest_shape = NULL;
    25 	Shape *nearest_shape = NULL;
    26         ShapeList::iterator shape;
    26 	ShapeList::iterator shape;
    27         for (shape = shapes.begin(); shape != shapes.end(); shape++)
    27 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    28                 if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    28 		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    29                         nearest_shape = *shape;
    29 			nearest_shape = *shape;
    30         return nearest_shape;
    30 	return nearest_shape;
    31 }
    31 }