Move ShapeType into the Shape object.

This commit is contained in:
Godzil
2020-03-09 15:57:23 +00:00
parent d514219ae6
commit 8437ab8753
11 changed files with 29 additions and 26 deletions

View File

@@ -29,7 +29,7 @@ public:
double minCap;
double maxCap;
Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) { stats.addCone(); };
Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(Shape::CONE) { stats.addCone(); };
BoundingBox getLocalBounds();
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };

View File

@@ -24,7 +24,7 @@ protected:
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:
Cube() : Shape(SHAPE_CUBE) { stats.addCube(); };
Cube() : Shape(Shape::CUBE) { stats.addCube(); };
void dumpMe(FILE *fp);
};

View File

@@ -30,7 +30,7 @@ public:
double minCap;
double maxCap;
Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CYLINDER) { stats.addCylinder(); };
Cylinder() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(Shape::CYLINDER) { stats.addCylinder(); };
BoundingBox getLocalBounds();
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };

View File

@@ -18,7 +18,7 @@ protected:
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:
Plane() : Shape(SHAPE_PLANE) { stats.addPlane(); };
Plane() : Shape(Shape::PLANE) { stats.addPlane(); };
BoundingBox getLocalBounds();
bool haveFiniteBounds() { return false; };
};

View File

@@ -19,24 +19,25 @@ class Shape;
#include <material.h>
#include <boundingbox.h>
enum ShapeType
{
SHAPE_NONE,
SHAPE_SPHERE,
SHAPE_PLANE,
SHAPE_CUBE,
SHAPE_CYLINDER,
SHAPE_CONE,
SHAPE_GROUP,
SHAPE_TRIANGLE,
SHAPE_OBJFILE,
SHAPE_SMOOTHTRIANGLE,
SHAPE_CSG,
};
/* Base class for all object that can be presented in the world */
class Shape
{
public:
enum ShapeType
{
NONE,
SPHERE,
PLANE,
CUBE,
CYLINDER,
CONE,
GROUP,
TRIANGLE,
OBJFILE,
SMOOTHTRIANGLE,
CSG,
};
protected:
ShapeType type;
Matrix localTransformMatrix;
@@ -56,7 +57,9 @@ public:
bool materialSet;
public:
Shape(ShapeType = SHAPE_NONE);
Shape(ShapeType = Shape::NONE);
ShapeType getType() { return this->type; };
virtual Intersect intersect(Ray r);
Tuple normalAt(Tuple point, Intersection *hit = nullptr);

View File

@@ -22,7 +22,7 @@ protected:
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
public:
Sphere() : Shape(SHAPE_SPHERE) { stats.addSphere(); };
Sphere() : Shape(Shape::SPHERE) { stats.addSphere(); };
/* All sphere are at (0, 0, 0) and radius 1 in the object space */