src/container.cc
branchpyrit
changeset 74 09aedbf5f95f
parent 72 7c3f38dff082
child 78 9569e9f35374
equal deleted inserted replaced
73:a5127346fbcd 74:09aedbf5f95f
    27 #include "common.h"
    27 #include "common.h"
    28 #include "container.h"
    28 #include "container.h"
    29 
    29 
    30 void Container::addShape(Shape* aShape)
    30 void Container::addShape(Shape* aShape)
    31 {
    31 {
       
    32 	const Float e = 10*Eps;
    32 	shapes.push_back(aShape);
    33 	shapes.push_back(aShape);
    33 	if (shapes.size() == 0) {
    34 	if (shapes.size() == 0) {
    34 		/* initialize bounding box */
    35 		/* initialize bounding box */
    35 		bbox = aShape->get_bbox();
    36 		bbox = aShape->get_bbox();
    36 		Vector3 eps(Eps,Eps,Eps);
    37 		const Vector3 E(e, e, e);
    37 		bbox = BBox(bbox.L - eps, bbox.H + eps);
    38 		bbox = BBox(bbox.L - E, bbox.H + E);
    38 	} else {
    39 	} else {
    39 		/* adjust bounding box */
    40 		/* adjust bounding box */
    40 		BBox shapebb = aShape->get_bbox();
    41 		BBox shapebb = aShape->get_bbox();
    41 		if (shapebb.L.x - Eps < bbox.L.x)  bbox.L.x = shapebb.L.x - Eps;
    42 		if (shapebb.L.x - e < bbox.L.x)  bbox.L.x = shapebb.L.x - e;
    42 		if (shapebb.L.y - Eps < bbox.L.y)  bbox.L.y = shapebb.L.y - Eps;
    43 		if (shapebb.L.y - e < bbox.L.y)  bbox.L.y = shapebb.L.y - e;
    43 		if (shapebb.L.z - Eps < bbox.L.z)  bbox.L.z = shapebb.L.z - Eps;
    44 		if (shapebb.L.z - e < bbox.L.z)  bbox.L.z = shapebb.L.z - e;
    44 		if (shapebb.H.x + Eps > bbox.H.x)  bbox.H.x = shapebb.H.x + Eps;
    45 		if (shapebb.H.x + e > bbox.H.x)  bbox.H.x = shapebb.H.x + e;
    45 		if (shapebb.H.y + Eps > bbox.H.y)  bbox.H.y = shapebb.H.y + Eps;
    46 		if (shapebb.H.y + e > bbox.H.y)  bbox.H.y = shapebb.H.y + e;
    46 		if (shapebb.H.z + Eps > bbox.H.z)  bbox.H.z = shapebb.H.z + Eps;
    47 		if (shapebb.H.z + e > bbox.H.z)  bbox.H.z = shapebb.H.z + e;
    47 	}
    48 	}
    48 };
    49 };
    49 
    50 
    50 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    51 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    51         Float &nearest_distance)
    52         Float &nearest_distance)