Started working on boundingboxes.

This commit is contained in:
Godzil
2020-02-24 18:03:25 +00:00
parent d1965caf8d
commit 3011544e8f
13 changed files with 114 additions and 3 deletions

View File

@@ -122,3 +122,13 @@ Tuple Cone::localNormalAt(Tuple point)
}
return Vector(point.x, y, point.z);
}
BoundingBox Cone::getBounds()
{
BoundingBox ret;
ret.min = this->objectToWorld(Point(-1, this->minCap, -1));
ret.max = this->objectToWorld(Point(1, this->maxCap, 1));
return ret;
}

View File

@@ -107,3 +107,13 @@ Tuple Cylinder::localNormalAt(Tuple point)
return Vector(point.x, 0, point.z);
}
BoundingBox Cylinder::getBounds()
{
BoundingBox ret;
ret.min = this->objectToWorld(Point(-1, this->minCap, -1));
ret.max = this->objectToWorld(Point(1, this->maxCap, 1));
return ret;
}

View File

@@ -70,4 +70,31 @@ void Group::addObject(Shape *s)
bool Group::isEmpty()
{
return (this->objectCount == 0);
}
BoundingBox Group::getBounds()
{
BoundingBox ret;
if (this->objectCount > 0)
{
ret.min = Point(INFINITY, INFINITY, INFINITY);
ret.max = Point(-INFINITY, -INFINITY, -INFINITY);
int i;
for(i = 0; i < this->objectCount; i++)
{
BoundingBox obj = this->objectList[i]->getBounds();
if (ret.min.x > obj.min.x) { ret.min.x = obj.min.x; }
if (ret.min.y > obj.min.y) { ret.min.y = obj.min.y; }
if (ret.min.z > obj.min.z) { ret.min.z = obj.min.z; }
if (ret.max.x < obj.max.x) { ret.max.x = obj.max.x; }
if (ret.max.y < obj.max.y) { ret.max.y = obj.max.y; }
if (ret.max.z < obj.max.z) { ret.max.z = obj.max.z; }
}
}
return ret;
}

View File

@@ -33,4 +33,14 @@ Intersect Plane::localIntersect(Ray r)
Tuple Plane::localNormalAt(Tuple point)
{
return Vector(0, 1, 0);
}
BoundingBox Plane::getBounds()
{
BoundingBox ret;
ret.min = this->objectToWorld(Point(-INFINITY, 0-getEpsilon(), -INFINITY));
ret.max = this->objectToWorld(Point(INFINITY, 0+getEpsilon(), INFINITY));
return ret;
}

View File

@@ -65,3 +65,12 @@ void Shape::setTransform(Matrix transform)
this->localTransformMatrix = transform;
this->updateTransform();
}
BoundingBox Shape::getBounds()
{
BoundingBox ret;
ret.min = this->objectToWorld(Point(-1, -1, -1));
ret.max = this->objectToWorld(Point(1, 1, 1));
return ret;
}