From b4ae737b4079df425f80f5e930570cad98189ce7 Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 28 Feb 2020 09:29:09 +0000 Subject: [PATCH] Continuing working on dumping the world --- source/include/boundingbox.h | 11 ++++++++++ source/include/cone.h | 3 +++ source/include/cube.h | 3 +++ source/include/cylinder.h | 3 +++ source/include/group.h | 3 +++ source/include/light.h | 3 +++ source/include/renderstat.h | 40 ++++++++++++++++++------------------ source/include/sphere.h | 4 ++++ source/include/triangle.h | 3 +++ source/shapes/cone.cpp | 13 ++++++++++++ source/shapes/cube.cpp | 12 +++++++++++ source/shapes/cylinder.cpp | 13 ++++++++++++ source/shapes/group.cpp | 30 +++++++++++++++++++++++++++ source/shapes/light.cpp | 11 ++++++++++ source/shapes/material.cpp | 2 +- source/shapes/shape.cpp | 3 +++ source/shapes/sphere.cpp | 12 +++++++++++ source/shapes/triangle.cpp | 15 ++++++++++++++ source/world.cpp | 2 +- 19 files changed, 164 insertions(+), 22 deletions(-) diff --git a/source/include/boundingbox.h b/source/include/boundingbox.h index f78df56..940d67d 100644 --- a/source/include/boundingbox.h +++ b/source/include/boundingbox.h @@ -10,6 +10,7 @@ #define DORAYME_BOUNDINGBOX_H #include +#include struct BoundingBox { @@ -118,6 +119,16 @@ public: return false; } + void dumpMe(FILE *fp) + { + Tuple t = this->min; + fprintf(fp, "\"min\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->max; + fprintf(fp, "\"max\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + } + }; #endif /* DORAYME_BOUNDINGBOX_H */ diff --git a/source/include/cone.h b/source/include/cone.h index 38f7aa3..9a3e707 100644 --- a/source/include/cone.h +++ b/source/include/cone.h @@ -13,6 +13,7 @@ #include #include #include +#include class Cone : public Shape { protected: @@ -31,6 +32,8 @@ public: Cone() : minCap(-INFINITY), maxCap(INFINITY), isClosed(false), Shape(SHAPE_CONE) { stats.addCone(); }; BoundingBox getBounds(); bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; + + void dumpMe(FILE *fp); }; #endif /* DORAYME_CONE_H */ diff --git a/source/include/cube.h b/source/include/cube.h index be8c360..b3f85da 100644 --- a/source/include/cube.h +++ b/source/include/cube.h @@ -13,6 +13,7 @@ #include #include #include +#include class Cube : public Shape { private: @@ -24,6 +25,8 @@ private: public: Cube() : Shape(SHAPE_CUBE) { stats.addCube(); }; + + void dumpMe(FILE *fp); }; #endif /* DORAYME_CUBE_H */ diff --git a/source/include/cylinder.h b/source/include/cylinder.h index ea8ca27..2cee64e 100644 --- a/source/include/cylinder.h +++ b/source/include/cylinder.h @@ -13,6 +13,7 @@ #include #include #include +#include class Cylinder : public Shape { private: @@ -32,6 +33,8 @@ public: BoundingBox getBounds(); bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; + + void dumpMe(FILE *fp); }; #endif //DORAYME_CYLINDER_H diff --git a/source/include/group.h b/source/include/group.h index c115c6b..dcbfd8b 100644 --- a/source/include/group.h +++ b/source/include/group.h @@ -10,6 +10,7 @@ #define DORAYME_GROUP_H #include +#include /* TODO: Add a way to force(?) material from group to be applied on childs */ @@ -43,6 +44,8 @@ public: void updateTransform(); Group(); + + void dumpMe(FILE * fp); }; #endif /* DORAYME_GROUP_H */ diff --git a/source/include/light.h b/source/include/light.h index 1e32a17..a555fa2 100644 --- a/source/include/light.h +++ b/source/include/light.h @@ -12,6 +12,7 @@ #include #include #include +#include enum LightType { @@ -33,6 +34,8 @@ public: bool operator==(const Light &b) const { return this->intensity == b.intensity && this->position == b.position && this->type == b.type; }; + + void dumpMe(FILE *fp); }; #endif /* DORAYME_LIGHT_H */ diff --git a/source/include/renderstat.h b/source/include/renderstat.h index 3792e53..accfda3 100644 --- a/source/include/renderstat.h +++ b/source/include/renderstat.h @@ -68,27 +68,27 @@ public: void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARaymaxIntersectOnARay = count; } }; void printStats() { printf("Rendering statistics:\n"); - printf("Cones : %ld\n", this->coneCount); - printf("Cubes : %ld\n", this->cubeCount); - printf("Cylinders : %ld\n", this->cylinderCount); - printf("Groups : %ld\n", this->groupCount); - printf("Lights : %ld\n", this->lightCount); - printf("Planes : %ld\n", this->planeCount); - printf("Spheres : %ld\n", this->sphereCount); - printf("Triangles : %ld\n", this->triangleCount); + printf("Cones : %lld\n", this->coneCount); + printf("Cubes : %lld\n", this->cubeCount); + printf("Cylinders : %lld\n", this->cylinderCount); + printf("Groups : %lld\n", this->groupCount); + printf("Lights : %lld\n", this->lightCount); + printf("Planes : %lld\n", this->planeCount); + printf("Spheres : %lld\n", this->sphereCount); + printf("Triangles : %lld\n", this->triangleCount); printf("==================================================\n"); - printf("Pixel rendered : %ld\n", this->pixelCount); - printf("Ray casted : %ld\n", this->rayCount); - printf("Light Ray casted : %ld\n", this->lightRayEmitedCount); - printf("Reflection ray casted : %ld\n", this->reflectionRayCount); - printf("Refraction ray casted : %ld\n", this->refractedRayCount); - printf("Intersect object created: %ld\n", this->intersectCount); - printf("Intersection created : %ld\n", this->intersectionCount); - printf("Malloc called : %ld\n", this->mallocCallCount); - printf("Realloc called : %ld\n", this->reallocCallCount); - printf("Bounding box missed : %ld\n", this->discardedIntersectCount); - printf("Min depth atteined : %ld\n", this->maxDepthAttained); - printf("Max intersect count : %ld\n", this->maxIntersectOnARay); + printf("Pixel rendered : %lld\n", this->pixelCount); + printf("Ray casted : %lld\n", this->rayCount); + printf("Light Ray casted : %lld\n", this->lightRayEmitedCount); + printf("Reflection ray casted : %lld\n", this->reflectionRayCount); + printf("Refraction ray casted : %lld\n", this->refractedRayCount); + printf("Intersect object created: %lld\n", this->intersectCount); + printf("Intersection created : %lld\n", this->intersectionCount); + printf("Malloc called : %lld\n", this->mallocCallCount); + printf("Realloc called : %lld\n", this->reallocCallCount); + printf("Bounding box missed : %lld\n", this->discardedIntersectCount); + printf("Min depth atteined : %lld\n", this->maxDepthAttained); + printf("Max intersect count : %lld\n", this->maxIntersectOnARay); printf("==================================================\n"); }; }; diff --git a/source/include/sphere.h b/source/include/sphere.h index b812f53..cf69822 100644 --- a/source/include/sphere.h +++ b/source/include/sphere.h @@ -13,6 +13,7 @@ #include #include #include +#include class Sphere : public Shape { @@ -23,6 +24,9 @@ protected: public: Sphere() : Shape(SHAPE_SPHERE) { stats.addSphere(); }; /* All sphere are at (0, 0, 0) and radius 1 in the object space */ + + + void dumpMe(FILE *fp); }; /* Mostly for test purposes */ diff --git a/source/include/triangle.h b/source/include/triangle.h index 2514ffd..7c0862f 100644 --- a/source/include/triangle.h +++ b/source/include/triangle.h @@ -10,6 +10,7 @@ #define DORAYME_TRIANGLE_H #include +#include class Triangle : public Shape { @@ -25,6 +26,8 @@ public: Triangle(Point p1, Point p2, Point p3); BoundingBox getBounds(); + void dumpMe(FILE *fp); + }; #endif /* DORAYME_TRIANGLE_H */ diff --git a/source/shapes/cone.cpp b/source/shapes/cone.cpp index b0fec00..dd9a660 100644 --- a/source/shapes/cone.cpp +++ b/source/shapes/cone.cpp @@ -137,4 +137,17 @@ BoundingBox Cone::getBounds() ret.max.fixPoint(); return ret; +} + +void Cone::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Type\": \"Cylinder\",\n"); + Tuple t = this->transformMatrix * Point(0, 0, 0); + fprintf(fp, "\"pseudocenter\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * Point(0, this->minCap, 0); + fprintf(fp, "\"min\": %f, \n", t.y); + t = this->transformMatrix * Point(1, this->maxCap, 1); + fprintf(fp, "\"max\": %f, \n", t.y); + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/shapes/cube.cpp b/source/shapes/cube.cpp index 27ccfe2..6ee6fa7 100644 --- a/source/shapes/cube.cpp +++ b/source/shapes/cube.cpp @@ -73,4 +73,16 @@ Tuple Cube::localNormalAt(Tuple point) } return Vector(0, 0, point.z); +} + +void Cube::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Type\": \"Cube\",\n"); + Tuple t = this->transformMatrix * Point(0, 0, 0); + fprintf(fp, "\"center\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * Point(1, 1, 1); + fprintf(fp, "\"corner\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/shapes/cylinder.cpp b/source/shapes/cylinder.cpp index e7735d6..8a6800e 100644 --- a/source/shapes/cylinder.cpp +++ b/source/shapes/cylinder.cpp @@ -119,4 +119,17 @@ BoundingBox Cylinder::getBounds() ret.max.fixPoint(); return ret; +} + +void Cylinder::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Type\": \"Cylinder\",\n"); + Tuple t = this->transformMatrix * Point(0, 0, 0); + fprintf(fp, "\"pseudocenter\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * Point(0, this->minCap, 0); + fprintf(fp, "\"min\": %f, \n", t.y); + t = this->transformMatrix * Point(1, this->maxCap, 1); + fprintf(fp, "\"max\": %f, \n", t.y); + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/shapes/group.cpp b/source/shapes/group.cpp index ffa4b8a..10b3c8b 100644 --- a/source/shapes/group.cpp +++ b/source/shapes/group.cpp @@ -165,4 +165,34 @@ void Group::updateTransform() * bounding box */ this->updateBoundingBox(); +} + +void Group::dumpMe(FILE *fp) +{ + int i; + fprintf(fp, "\"Type\": \"Group\",\n"); + if (this->objectCount > 0) + { + fprintf(fp, "\"Objects\": {\n"); + for(i = 0; i < this->objectCount; i++) + { + fprintf(fp, "\"%d\": {\n", i); + this->objectList[i]->dumpMe(fp); + fprintf(fp, "},\n"); + } + fprintf(fp, "},\n"); + } + + if (this->unboxableObjectCount > 0) + { + fprintf(fp, "\"UnboxableObjects\": {\n"); + for(i = 0; i < this->objectCount; i++) + { + fprintf(fp, "\"%d\": {\n", i); + this->objectList[i]->dumpMe(fp); + fprintf(fp, "},\n"); + } + fprintf(fp, "},\n"); + } + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/shapes/light.cpp b/source/shapes/light.cpp index c873a40..a9c079d 100644 --- a/source/shapes/light.cpp +++ b/source/shapes/light.cpp @@ -6,3 +6,14 @@ * Copyright (c) 2020 986-Studio. * */ +#include +#include + +void Light::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Colour\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", + this->intensity.x, this->intensity.y, this->intensity.z); + fprintf(fp, "\"Position\": {\"x\": %f, \"y\": %f, \"z\":%f},\n", + this->position.x, this->position.y, this->position.z); + fprintf(fp, "\"Type\": \"PointLight\",\n"); +} \ No newline at end of file diff --git a/source/shapes/material.cpp b/source/shapes/material.cpp index cbcdd3e..db274a8 100644 --- a/source/shapes/material.cpp +++ b/source/shapes/material.cpp @@ -81,7 +81,7 @@ void Material::dumpMe(FILE *fp) fprintf(fp, "\"RefractiveIndex\": %f,\n", this->refractiveIndex); if (this->pattern) { - fprintf(fp, "\"Pattern\": {\n", this->emissive); + fprintf(fp, "\"Pattern\": {\n"); this->pattern->dumpMe(fp); fprintf(fp, "},\n"); } diff --git a/source/shapes/shape.cpp b/source/shapes/shape.cpp index 862e2a2..2b09e0f 100644 --- a/source/shapes/shape.cpp +++ b/source/shapes/shape.cpp @@ -81,4 +81,7 @@ void Shape::dumpMe(FILE *fp) this->material.dumpMe(fp); fprintf(fp, "},\n"); fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow); + fprintf(fp, "\"BoundingBox\": {\n"); + this->getBounds().dumpMe(fp); + fprintf(fp, "},\n"); } \ No newline at end of file diff --git a/source/shapes/sphere.cpp b/source/shapes/sphere.cpp index fabede7..b294fc6 100644 --- a/source/shapes/sphere.cpp +++ b/source/shapes/sphere.cpp @@ -38,4 +38,16 @@ Intersect Sphere::localIntersect(Ray r) Tuple Sphere::localNormalAt(Tuple point) { return (point - Point(0, 0, 0)).normalise(); +} + +void Sphere::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Type\": \"Sphere\",\n"); + Tuple t = this->transformMatrix * Point(0, 0, 0); + fprintf(fp, "\"center\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * Point(1, 1, 1); + fprintf(fp, "\"radius\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/shapes/triangle.cpp b/source/shapes/triangle.cpp index a0a9d8e..22c5c18 100644 --- a/source/shapes/triangle.cpp +++ b/source/shapes/triangle.cpp @@ -71,4 +71,19 @@ BoundingBox Triangle::getBounds() ret.max = this->objectToWorld(ret.max); return ret; +} + +void Triangle::dumpMe(FILE *fp) +{ + fprintf(fp, "\"Type\": \"Triangle\",\n"); + Tuple t = this->transformMatrix * this->p1; + fprintf(fp, "\"p1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * this->p2; + fprintf(fp, "\"p2\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + t = this->transformMatrix * this->p3; + fprintf(fp, "\"p3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n", + t.x, t.y, t.z); + Shape::dumpMe(fp); } \ No newline at end of file diff --git a/source/world.cpp b/source/world.cpp index a098225..ef62108 100644 --- a/source/world.cpp +++ b/source/world.cpp @@ -211,7 +211,7 @@ void World::dumpMe(FILE *fp) for(i = 0; i < this->lightCount; i++) { fprintf(fp, "\"%d\": {\n", i); - //this->lightList[i]->dumpMe(fp); + this->lightList[i]->dumpMe(fp); fprintf(fp, "},\n"); } fprintf(fp, "},\n");