src/container.cc
branchpyrit
changeset 78 9569e9f35374
parent 74 09aedbf5f95f
child 82 930a2d3ecaed
equal deleted inserted replaced
77:dbe8438d5dca 78:9569e9f35374
    24  * THE SOFTWARE.
    24  * THE SOFTWARE.
    25  */
    25  */
    26 
    26 
    27 #include "common.h"
    27 #include "common.h"
    28 #include "container.h"
    28 #include "container.h"
       
    29 #include "serialize.h"
    29 
    30 
    30 void Container::addShape(Shape* aShape)
    31 void Container::addShape(Shape* aShape)
    31 {
    32 {
    32 	const Float e = 10*Eps;
    33 	const Float e = Eps;
    33 	shapes.push_back(aShape);
       
    34 	if (shapes.size() == 0) {
    34 	if (shapes.size() == 0) {
    35 		/* initialize bounding box */
    35 		/* initialize bounding box */
    36 		bbox = aShape->get_bbox();
    36 		bbox = aShape->get_bbox();
    37 		const Vector3 E(e, e, e);
    37 		const Vector3 E(e, e, e);
    38 		bbox = BBox(bbox.L - E, bbox.H + E);
    38 		bbox = BBox(bbox.L - E, bbox.H + E);
    44 		if (shapebb.L.z - e < bbox.L.z)  bbox.L.z = shapebb.L.z - e;
    44 		if (shapebb.L.z - e < bbox.L.z)  bbox.L.z = shapebb.L.z - e;
    45 		if (shapebb.H.x + e > bbox.H.x)  bbox.H.x = shapebb.H.x + e;
    45 		if (shapebb.H.x + e > bbox.H.x)  bbox.H.x = shapebb.H.x + e;
    46 		if (shapebb.H.y + e > bbox.H.y)  bbox.H.y = shapebb.H.y + e;
    46 		if (shapebb.H.y + e > bbox.H.y)  bbox.H.y = shapebb.H.y + e;
    47 		if (shapebb.H.z + e > bbox.H.z)  bbox.H.z = shapebb.H.z + e;
    47 		if (shapebb.H.z + e > bbox.H.z)  bbox.H.z = shapebb.H.z + e;
    48 	}
    48 	}
       
    49 	shapes.push_back(aShape);
    49 };
    50 };
    50 
    51 
    51 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    52 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    52         Float &nearest_distance)
    53         Float &nearest_distance)
    53 {
    54 {
    56 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    57 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    57 		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    58 		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    58 			nearest_shape = *shape;
    59 			nearest_shape = *shape;
    59 	return nearest_shape;
    60 	return nearest_shape;
    60 }
    61 }
       
    62 
       
    63 ostream & Container::dump(ostream &st)
       
    64 {
       
    65 	st << "(container," << shapes.size();
       
    66 	ShapeList::iterator shape;
       
    67 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
       
    68 	{
       
    69 		int idx;
       
    70 		if (!shape_index.get(*shape, idx))
       
    71 			st << "," << **shape;
       
    72 	}
       
    73 	return st << ")";
       
    74 }