From 8437ab875360e0af7abcd39c1cc6aa41e415cf1e Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 9 Mar 2020 15:57:23 +0000 Subject: [PATCH] Move ShapeType into the Shape object. --- source/include/cone.h | 2 +- source/include/cube.h | 2 +- source/include/cylinder.h | 2 +- source/include/plane.h | 2 +- source/include/shape.h | 35 +++++++++++++++++--------------- source/include/sphere.h | 2 +- source/shapes/csg.cpp | 2 +- source/shapes/group.cpp | 2 +- source/shapes/objfile.cpp | 2 +- source/shapes/smoothtriangle.cpp | 2 +- source/shapes/triangle.cpp | 2 +- 11 files changed, 29 insertions(+), 26 deletions(-) diff --git a/source/include/cone.h b/source/include/cone.h index 20aa223..412f0f0 100644 --- a/source/include/cone.h +++ b/source/include/cone.h @@ -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)); }; diff --git a/source/include/cube.h b/source/include/cube.h index 31ba770..e63df50 100644 --- a/source/include/cube.h +++ b/source/include/cube.h @@ -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); }; diff --git a/source/include/cylinder.h b/source/include/cylinder.h index c8455d3..46ad2e1 100644 --- a/source/include/cylinder.h +++ b/source/include/cylinder.h @@ -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)); }; diff --git a/source/include/plane.h b/source/include/plane.h index 278aa92..f5f5b60 100644 --- a/source/include/plane.h +++ b/source/include/plane.h @@ -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; }; }; diff --git a/source/include/shape.h b/source/include/shape.h index 42c68de..6c8f8c0 100644 --- a/source/include/shape.h +++ b/source/include/shape.h @@ -19,24 +19,25 @@ class Shape; #include #include -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); diff --git a/source/include/sphere.h b/source/include/sphere.h index da00c9e..999ce86 100644 --- a/source/include/sphere.h +++ b/source/include/sphere.h @@ -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 */ diff --git a/source/shapes/csg.cpp b/source/shapes/csg.cpp index dcea4c5..40d950d 100644 --- a/source/shapes/csg.cpp +++ b/source/shapes/csg.cpp @@ -13,7 +13,7 @@ #include -CSG::CSG(OperationType operation, Shape *left, Shape *right) : Shape(SHAPE_CSG), operation(operation), left(left), right(right) +CSG::CSG(OperationType operation, Shape *left, Shape *right) : Shape(Shape::CSG), operation(operation), left(left), right(right) { stats.addCsg(); diff --git a/source/shapes/group.cpp b/source/shapes/group.cpp index 2839e18..1e5cf23 100644 --- a/source/shapes/group.cpp +++ b/source/shapes/group.cpp @@ -14,7 +14,7 @@ #define MIN_ALLOC (2) -Group::Group() : Shape(SHAPE_GROUP) +Group::Group(const char *name) : Shape(Shape::GROUP) { stats.addGroup(); this->allocatedObjectCount = MIN_ALLOC; diff --git a/source/shapes/objfile.cpp b/source/shapes/objfile.cpp index a9c3811..6df1dac 100644 --- a/source/shapes/objfile.cpp +++ b/source/shapes/objfile.cpp @@ -22,7 +22,7 @@ #define MIN_ALLOC (2) #define DEFAULT_GROUP (0) -OBJFile::OBJFile() : Shape(SHAPE_OBJFILE), ignoredLines(0) +OBJFile::OBJFile() : Shape(Shape::OBJFILE), ignoredLines(0) { stats.addOBJFile(); diff --git a/source/shapes/smoothtriangle.cpp b/source/shapes/smoothtriangle.cpp index 9991d80..4d34a3e 100644 --- a/source/shapes/smoothtriangle.cpp +++ b/source/shapes/smoothtriangle.cpp @@ -16,7 +16,7 @@ SmoothTriangle::SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3) : Triangle(p1, p2, p3), n1(n1), n2(n2), n3(n3) { - this->type = SHAPE_SMOOTHTRIANGLE; + this->type = Shape::SMOOTHTRIANGLE; stats.addSmoothTriangle(); } diff --git a/source/shapes/triangle.cpp b/source/shapes/triangle.cpp index 01f7a1d..ee43659 100644 --- a/source/shapes/triangle.cpp +++ b/source/shapes/triangle.cpp @@ -12,7 +12,7 @@ #include #include -Triangle::Triangle(Point p1, Point p2, Point p3) : Shape(SHAPE_TRIANGLE), p1(p1), p2(p2), p3(p3) +Triangle::Triangle(Point p1, Point p2, Point p3) : Shape(Shape::TRIANGLE), p1(p1), p2(p2), p3(p3) { stats.addTriangle();