Working on groups
This commit is contained in:
@@ -15,10 +15,11 @@
|
||||
|
||||
Shape::Shape(ShapeType type)
|
||||
{
|
||||
this->parent = nullptr;
|
||||
this->dropShadow = true;
|
||||
this->type = type;
|
||||
this->transformMatrix = Matrix4().identity();
|
||||
this->inverseTransform = this->transformMatrix.inverse();
|
||||
this->localTransformMatrix = Matrix4().identity();
|
||||
this->updateTransform();
|
||||
}
|
||||
|
||||
Intersect Shape::intersect(Ray r)
|
||||
@@ -32,7 +33,7 @@ Tuple Shape::normalAt(Tuple point)
|
||||
|
||||
Tuple local_normal = this->localNormalAt(local_point);
|
||||
|
||||
Tuple world_normal = this->inverseTransform.transpose() * local_normal;
|
||||
Tuple world_normal = this->transposedInverseTransform * local_normal;
|
||||
|
||||
/* W may get wrong, so hack it. This is perfectly normal as we are using a 4x4 matrix instead of a 3x3 */
|
||||
world_normal.w = 0;
|
||||
@@ -40,8 +41,20 @@ Tuple Shape::normalAt(Tuple point)
|
||||
return world_normal.normalise();
|
||||
}
|
||||
|
||||
void Shape::updateTransform()
|
||||
{
|
||||
this->transformMatrix = this->localTransformMatrix;
|
||||
if (this->parent != nullptr)
|
||||
{
|
||||
this->transformMatrix = this->parent->transformMatrix * this->transformMatrix;
|
||||
}
|
||||
|
||||
this->inverseTransform = this->transformMatrix.inverse();
|
||||
this->transposedInverseTransform = this->inverseTransform.transpose();
|
||||
}
|
||||
|
||||
void Shape::setTransform(Matrix transform)
|
||||
{
|
||||
this->transformMatrix = transform;
|
||||
this->inverseTransform = transform.inverse();
|
||||
this->localTransformMatrix = transform;
|
||||
this->updateTransform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user