Browse Source

Continuing working on dumping the world

Godzil 4 years ago
parent
commit
b4ae737b40

+ 11 - 0
source/include/boundingbox.h

@@ -10,6 +10,7 @@
 #define DORAYME_BOUNDINGBOX_H
 
 #include <renderstat.h>
+#include <stdio.h>
 
 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 */

+ 3 - 0
source/include/cone.h

@@ -13,6 +13,7 @@
 #include <ray.h>
 #include <intersect.h>
 #include <renderstat.h>
+#include <stdio.h>
 
 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 */

+ 3 - 0
source/include/cube.h

@@ -13,6 +13,7 @@
 #include <ray.h>
 #include <intersect.h>
 #include <renderstat.h>
+#include <stdio.h>
 
 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 */

+ 3 - 0
source/include/cylinder.h

@@ -13,6 +13,7 @@
 #include <ray.h>
 #include <intersect.h>
 #include <renderstat.h>
+#include <stdio.h>
 
 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

+ 3 - 0
source/include/group.h

@@ -10,6 +10,7 @@
 #define DORAYME_GROUP_H
 
 #include <shape.h>
+#include <stdio.h>
 
 /* 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 */

+ 3 - 0
source/include/light.h

@@ -12,6 +12,7 @@
 #include <tuple.h>
 #include <colour.h>
 #include <renderstat.h>
+#include <stdio.h>
 
 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 */

+ 20 - 20
source/include/renderstat.h

@@ -68,27 +68,27 @@ public:
     void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARay<count) { this->maxIntersectOnARay = 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");
     };
 };

+ 4 - 0
source/include/sphere.h

@@ -13,6 +13,7 @@
 #include <ray.h>
 #include <intersect.h>
 #include <renderstat.h>
+#include <stdio.h>
 
 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 */

+ 3 - 0
source/include/triangle.h

@@ -10,6 +10,7 @@
 #define DORAYME_TRIANGLE_H
 
 #include <shape.h>
+#include <stdio.h>
 
 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 */

+ 13 - 0
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);
 }

+ 12 - 0
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);
 }

+ 13 - 0
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);
 }

+ 30 - 0
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);
 }

+ 11 - 0
source/shapes/light.cpp

@@ -6,3 +6,14 @@
  *  Copyright (c) 2020 986-Studio.
  *
  */
+#include <stdio.h>
+#include <light.h>
+
+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");
+}

+ 1 - 1
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");
     }

+ 3 - 0
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");
 }

+ 12 - 0
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);
 }

+ 15 - 0
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);
 }

+ 1 - 1
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");