Working on groups

This commit is contained in:
Godzil
2020-02-24 09:25:52 +00:00
parent 80f59efa43
commit 7c794f0496
8 changed files with 272 additions and 9 deletions

View File

@@ -25,6 +25,8 @@ enum ShapeType
SHAPE_CUBE,
SHAPE_CYLINDER,
SHAPE_CONE,
SHAPE_GROUP,
};
/* Base class for all object that can be presented in the world */
@@ -32,16 +34,19 @@ class Shape
{
private:
ShapeType type;
private:
Matrix localTransformMatrix;
protected:
virtual Intersect localIntersect(Ray r) = 0;
virtual Tuple localNormalAt(Tuple point) = 0;
public:
Matrix transformMatrix;
Matrix inverseTransform;
Matrix transposedInverseTransform;
Material material;
bool dropShadow;
Shape *parent;
public:
Shape(ShapeType = SHAPE_NONE);
@@ -49,6 +54,12 @@ public:
Intersect intersect(Ray r);
Tuple normalAt(Tuple point);
//virtual Bounds getBounds();
void updateTransform();
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
Tuple normalToWorld(Tuple normalVector) { return (this->transposedInverseTransform * normalVector).normalise(); };
void setTransform(Matrix transform);
void setMaterial(Material material) { this->material = material; };
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };