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

38
source/include/group.h Normal file
View File

@@ -0,0 +1,38 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Group header
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#ifndef DORAYME_GROUP_H
#define DORAYME_GROUP_H
#include <shape.h>
class Group : public Shape
{
private:
uint32_t allocatedObjectCount;
Shape* *objectList;
uint32_t objectCount;
protected:
Intersect localIntersect(Ray r);
Tuple localNormalAt(Tuple point);
public:
bool isEmpty();
void addObject(Shape *s);
Shape *operator[](const int p) { return this->objectList[p]; }
Intersect intersect(Ray r);
Group();
};
#endif /* DORAYME_GROUP_H */

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); };

View File

@@ -15,7 +15,7 @@
class Sphere : public Shape
{
private:
protected:
Intersect localIntersect(Ray r);
Tuple localNormalAt(Tuple point);