src/container.cc
author Radek Brich <radek.brich@devl.cz>
Sun, 09 Dec 2007 15:01:51 +0100
branchpyrit
changeset 33 83d0200d4c09
parent 28 ffe83ca074f3
child 34 28f6e8b9d5d1
permissions -rw-r--r--
make over-sampling work together with sub-sampling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#include "common.h"
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
#include "container.h"
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
void Container::addShape(Shape* aShape)
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
     6
	shapes.push_back(aShape);
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
     7
	if (shapes.size() == 0) {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
     8
		/* initialize bounding box */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
     9
		bbox = aShape->get_bbox();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    10
	} else {
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    11
		/* adjust bounding box */
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    12
		BBox shapebb = aShape->get_bbox();
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    13
		if (shapebb.L.x < bbox.L.x)  bbox.L.x = shapebb.L.x;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    14
		if (shapebb.L.y < bbox.L.y)  bbox.L.y = shapebb.L.y;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    15
		if (shapebb.L.z < bbox.L.z)  bbox.L.z = shapebb.L.z;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    16
		if (shapebb.H.x > bbox.H.x)  bbox.H.x = shapebb.H.x;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    17
		if (shapebb.H.y > bbox.H.y)  bbox.H.y = shapebb.H.y;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    18
		if (shapebb.H.z > bbox.H.z)  bbox.H.z = shapebb.H.z;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    19
	}
24
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
};
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        Float &nearest_distance)
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
{
28
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    25
	Shape *nearest_shape = NULL;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    26
	ShapeList::iterator shape;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    27
	for (shape = shapes.begin(); shape != shapes.end(); shape++)
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    28
		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    29
			nearest_shape = *shape;
ffe83ca074f3 smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    30
	return nearest_shape;
24
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
}