Move ShapeType into the Shape object.
This commit is contained in:
@@ -29,7 +29,7 @@ public:
|
|||||||
double minCap;
|
double minCap;
|
||||||
double maxCap;
|
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();
|
BoundingBox getLocalBounds();
|
||||||
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ protected:
|
|||||||
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Cube() : Shape(SHAPE_CUBE) { stats.addCube(); };
|
Cube() : Shape(Shape::CUBE) { stats.addCube(); };
|
||||||
|
|
||||||
void dumpMe(FILE *fp);
|
void dumpMe(FILE *fp);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
double minCap;
|
double minCap;
|
||||||
double maxCap;
|
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();
|
BoundingBox getLocalBounds();
|
||||||
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ protected:
|
|||||||
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Plane() : Shape(SHAPE_PLANE) { stats.addPlane(); };
|
Plane() : Shape(Shape::PLANE) { stats.addPlane(); };
|
||||||
BoundingBox getLocalBounds();
|
BoundingBox getLocalBounds();
|
||||||
bool haveFiniteBounds() { return false; };
|
bool haveFiniteBounds() { return false; };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,24 +19,25 @@ class Shape;
|
|||||||
#include <material.h>
|
#include <material.h>
|
||||||
#include <boundingbox.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 */
|
/* Base class for all object that can be presented in the world */
|
||||||
class Shape
|
class Shape
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
enum ShapeType
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
SPHERE,
|
||||||
|
PLANE,
|
||||||
|
CUBE,
|
||||||
|
CYLINDER,
|
||||||
|
CONE,
|
||||||
|
GROUP,
|
||||||
|
TRIANGLE,
|
||||||
|
OBJFILE,
|
||||||
|
SMOOTHTRIANGLE,
|
||||||
|
CSG,
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ShapeType type;
|
ShapeType type;
|
||||||
Matrix localTransformMatrix;
|
Matrix localTransformMatrix;
|
||||||
@@ -56,7 +57,9 @@ public:
|
|||||||
bool materialSet;
|
bool materialSet;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Shape(ShapeType = SHAPE_NONE);
|
Shape(ShapeType = Shape::NONE);
|
||||||
|
|
||||||
|
ShapeType getType() { return this->type; };
|
||||||
|
|
||||||
virtual Intersect intersect(Ray r);
|
virtual Intersect intersect(Ray r);
|
||||||
Tuple normalAt(Tuple point, Intersection *hit = nullptr);
|
Tuple normalAt(Tuple point, Intersection *hit = nullptr);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ protected:
|
|||||||
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
||||||
|
|
||||||
public:
|
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 */
|
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <math_helper.h>
|
#include <math_helper.h>
|
||||||
|
|
||||||
|
|
||||||
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();
|
stats.addCsg();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define MIN_ALLOC (2)
|
#define MIN_ALLOC (2)
|
||||||
|
|
||||||
Group::Group() : Shape(SHAPE_GROUP)
|
Group::Group(const char *name) : Shape(Shape::GROUP)
|
||||||
{
|
{
|
||||||
stats.addGroup();
|
stats.addGroup();
|
||||||
this->allocatedObjectCount = MIN_ALLOC;
|
this->allocatedObjectCount = MIN_ALLOC;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#define MIN_ALLOC (2)
|
#define MIN_ALLOC (2)
|
||||||
#define DEFAULT_GROUP (0)
|
#define DEFAULT_GROUP (0)
|
||||||
|
|
||||||
OBJFile::OBJFile() : Shape(SHAPE_OBJFILE), ignoredLines(0)
|
OBJFile::OBJFile() : Shape(Shape::OBJFILE), ignoredLines(0)
|
||||||
{
|
{
|
||||||
stats.addOBJFile();
|
stats.addOBJFile();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
SmoothTriangle::SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3) : Triangle(p1, p2, p3),
|
SmoothTriangle::SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3) : Triangle(p1, p2, p3),
|
||||||
n1(n1), n2(n2), n3(n3)
|
n1(n1), n2(n2), n3(n3)
|
||||||
{
|
{
|
||||||
this->type = SHAPE_SMOOTHTRIANGLE;
|
this->type = Shape::SMOOTHTRIANGLE;
|
||||||
stats.addSmoothTriangle();
|
stats.addSmoothTriangle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <math_helper.h>
|
#include <math_helper.h>
|
||||||
#include <renderstat.h>
|
#include <renderstat.h>
|
||||||
|
|
||||||
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();
|
stats.addTriangle();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user