Add locking mechanism to prevent updating transform/parent

This commit is contained in:
Godzil
2020-03-10 13:55:27 +00:00
parent 5da0c10182
commit 441d758845
9 changed files with 95 additions and 7 deletions

View File

@@ -15,12 +15,14 @@
Shape::Shape(ShapeType type)
{
this->locked = false;
this->parent = nullptr;
this->dropShadow = true;
this->type = type;
this->localTransformMatrix = Matrix4().identity();
this->updateTransform();
this->materialSet = false;
this->updateTransform();
}
Intersect Shape::intersect(Ray r)
@@ -51,6 +53,8 @@ Tuple Shape::normalAt(Tuple point, Intersection *hit)
void Shape::updateTransform()
{
if (this->locked) return;
this->transformMatrix = this->localTransformMatrix;
if (this->parent != nullptr)
{
@@ -63,6 +67,8 @@ void Shape::updateTransform()
void Shape::setTransform(Matrix transform)
{
if (this->locked) return;
this->localTransformMatrix = transform;
this->updateTransform();
}