Fix an issue with groups, and add Chapter 14 example!
This commit is contained in:
@@ -37,10 +37,10 @@ public:
|
||||
Shape *operator[](const int p) { return this->objectList[p]; }
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
|
||||
BoundingBox getBounds();
|
||||
|
||||
void updateBoundingBox();
|
||||
void updateTransform();
|
||||
|
||||
Group();
|
||||
};
|
||||
|
||||
@@ -61,7 +61,8 @@ public:
|
||||
virtual BoundingBox getBounds();
|
||||
virtual bool haveFiniteBounds() { return true; };
|
||||
|
||||
void updateTransform();
|
||||
virtual void updateTransform();
|
||||
|
||||
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
||||
Tuple objectToWorld(Tuple point) { return this->transformMatrix * point; };
|
||||
Tuple normalToWorld(Tuple normalVector);
|
||||
|
||||
@@ -136,4 +136,32 @@ void Group::updateBoundingBox()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Group::updateTransform()
|
||||
{
|
||||
int i;
|
||||
|
||||
Shape::updateTransform();
|
||||
if (this->objectCount > 0)
|
||||
{
|
||||
for (i = 0 ; i < this->objectCount ; i++)
|
||||
{
|
||||
this->objectList[i]->updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
/* We are force to do them all the time */
|
||||
if (this->unboxableObjectCount > 0)
|
||||
{
|
||||
for(i = 0; i < this->unboxableObjectCount; i++)
|
||||
{
|
||||
this->unboxableObjectList[i]->updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
/* Once the full stack being notified of the changes, let's update the
|
||||
* bounding box
|
||||
*/
|
||||
this->updateBoundingBox();
|
||||
}
|
||||
Reference in New Issue
Block a user