And CSG! \o/
Still working on a nice scene for it.
This commit is contained in:
52
source/include/csg.h
Normal file
52
source/include/csg.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* CSG header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_CSG_H
|
||||
#define DORAYME_CSG_H
|
||||
|
||||
#include <shape.h>
|
||||
|
||||
class CSG : public Shape
|
||||
{
|
||||
public:
|
||||
enum OperationType
|
||||
{
|
||||
UNION,
|
||||
DIFFERENCE,
|
||||
INTERSECTION
|
||||
};
|
||||
|
||||
protected:
|
||||
Shape *left;
|
||||
Shape *right;
|
||||
OperationType operation;
|
||||
BoundingBox bounds;
|
||||
|
||||
protected:
|
||||
Intersect localIntersect(Ray r);
|
||||
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
|
||||
BoundingBox getLocalBounds();
|
||||
|
||||
bool intersectionAllowed(bool leftHit, bool inLeft, bool inRight);
|
||||
|
||||
Intersect filterIntersections(Intersect &xs);
|
||||
|
||||
void updateBoundingBox();
|
||||
BoundingBox getBounds();
|
||||
|
||||
public:
|
||||
CSG(OperationType operation, Shape *left, Shape *right);
|
||||
|
||||
bool includes(Shape *b);
|
||||
|
||||
void updateTransform();
|
||||
|
||||
void dumpMe(FILE *fp);
|
||||
};
|
||||
|
||||
#endif /* DORAYME_CSG_H */
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
void updateBoundingBox();
|
||||
void updateTransform();
|
||||
|
||||
bool includes(Shape *b);
|
||||
|
||||
Group();
|
||||
|
||||
void dumpMe(FILE * fp);
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
BoundingBox getLocalBounds();
|
||||
BoundingBox getBounds();
|
||||
|
||||
bool includes(Shape *b);
|
||||
|
||||
void updateBoundingBox();
|
||||
void updateTransform();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ private:
|
||||
uint64_t triangleCount; /* Total number of triangle */
|
||||
uint64_t smoothTriangleCount; /* Total number of smooth triangle */
|
||||
uint64_t objfileCount; /* Total number of OBJ File */
|
||||
uint64_t csgCount; /* Total number of CSG */
|
||||
|
||||
uint64_t pixelCount; /* Total number of rendered pixels */
|
||||
uint64_t rayCount; /* Total number of rays */
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
RenderStats() : coneCount(0), cylinderCount(0), cubeCount(0), groupCount(0), lightCount(0), planeCount(0), sphereCount(0), triangleCount(0),
|
||||
pixelCount(0), rayCount(0), lightRayEmitedCount(0), reflectionRayCount(0), refractedRayCount(0),
|
||||
intersectCount(0), intersectionCount(0), reallocCallCount(0), mallocCallCount(0), smoothTriangleCount(0),
|
||||
discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0), objfileCount(0) {};
|
||||
discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0), objfileCount(0), csgCount(0) {};
|
||||
#ifdef RENDER_STATS
|
||||
void addCone();
|
||||
void addCylinder();
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
void addLight();
|
||||
void addPlane();
|
||||
void addSphere();
|
||||
void addCsg();
|
||||
void addOBJFile();
|
||||
void addTriangle();
|
||||
void addSmoothTriangle();
|
||||
@@ -90,7 +92,8 @@ public:
|
||||
static void addMalloc() {};
|
||||
static void addRealloc() {};
|
||||
static void setMaxIntersect(uint32_t count) {};
|
||||
static void void RenderStats::addOBJFile() {};
|
||||
static void addOBJFile() {};
|
||||
static void addCsg() {};
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ enum ShapeType
|
||||
SHAPE_TRIANGLE,
|
||||
SHAPE_OBJFILE,
|
||||
SHAPE_SMOOTHTRIANGLE,
|
||||
SHAPE_CSG,
|
||||
};
|
||||
|
||||
/* Base class for all object that can be presented in the world */
|
||||
@@ -58,7 +59,6 @@ public:
|
||||
Shape(ShapeType = SHAPE_NONE);
|
||||
|
||||
virtual Intersect intersect(Ray r);
|
||||
virtual Intersect intersectOOB(Ray r) { return this->intersect(r); };
|
||||
Tuple normalAt(Tuple point, Intersection *hit = nullptr);
|
||||
|
||||
/* Bounding box points are always world value */
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
virtual void updateTransform();
|
||||
|
||||
virtual bool includes(Shape *b) { return this == b; };
|
||||
|
||||
virtual void dumpMe(FILE *fp);
|
||||
|
||||
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
||||
@@ -75,9 +77,9 @@ public:
|
||||
Tuple normalToWorld(Tuple normalVector);
|
||||
|
||||
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); };
|
||||
Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
|
||||
void setMaterial(Material material) { this->material = material; this->materialSet = true; };
|
||||
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
|
||||
Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
|
||||
|
||||
bool operator==(const Shape &b) const { return this->material == b.material &&
|
||||
this->type == b.type &&
|
||||
|
||||
Reference in New Issue
Block a user