Group should work now.

This commit is contained in:
Godzil
2020-02-24 17:25:54 +00:00
parent 7c794f0496
commit 7bbe5e843b
5 changed files with 40 additions and 10 deletions

View File

@@ -58,7 +58,7 @@ public:
void updateTransform();
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
Tuple normalToWorld(Tuple normalVector) { return (this->transposedInverseTransform * normalVector).normalise(); };
Tuple normalToWorld(Tuple normalVector);
void setTransform(Matrix transform);
void setMaterial(Material material) { this->material = material; };

View File

@@ -24,6 +24,7 @@ Intersect::Intersect()
Intersect::~Intersect()
{
/* Free stuff */
free(this->list);
}
void Intersect::add(Intersection i)

View File

@@ -18,7 +18,7 @@ Pattern::Pattern(Colour a, Colour b): a(a), b(b)
Colour Pattern::patternAtObject(Shape *object, Tuple worldPoint)
{
Tuple objectPoint = object->inverseTransform * worldPoint;
Tuple objectPoint = object->worldToObject(worldPoint);
Tuple patternPoint = this->inverseTransform * objectPoint;
return this->patternAt(patternPoint);

View File

@@ -27,18 +27,25 @@ Intersect Shape::intersect(Ray r)
return this->localIntersect(this->invTransform(r));
};
Tuple Shape::normalAt(Tuple point)
Tuple Shape::normalToWorld(Tuple normalVector)
{
Tuple local_point = this->inverseTransform * point;
Tuple local_normal = this->localNormalAt(local_point);
Tuple world_normal = this->transposedInverseTransform * local_normal;
Tuple world_normal = this->transposedInverseTransform * normalVector;
/* 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;
return world_normal.normalise();
};
Tuple Shape::normalAt(Tuple point)
{
Tuple local_point = this->worldToObject(point);
Tuple local_normal = this->localNormalAt(local_point);
Tuple world_normal = this->normalToWorld(local_normal);
return world_normal;
}
void Shape::updateTransform()