Continuing working on dumping the world

This commit is contained in:
Godzil
2020-02-28 09:29:09 +00:00
parent 8ceb68fdff
commit b4ae737b40
19 changed files with 164 additions and 22 deletions

View File

@@ -10,6 +10,7 @@
#define DORAYME_BOUNDINGBOX_H #define DORAYME_BOUNDINGBOX_H
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
struct BoundingBox struct BoundingBox
{ {
@@ -118,6 +119,16 @@ public:
return false; 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 */ #endif /* DORAYME_BOUNDINGBOX_H */

View File

@@ -13,6 +13,7 @@
#include <ray.h> #include <ray.h>
#include <intersect.h> #include <intersect.h>
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
class Cone : public Shape { class Cone : public Shape {
protected: protected:
@@ -31,6 +32,8 @@ public:
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 getBounds(); BoundingBox getBounds();
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
void dumpMe(FILE *fp);
}; };
#endif /* DORAYME_CONE_H */ #endif /* DORAYME_CONE_H */

View File

@@ -13,6 +13,7 @@
#include <ray.h> #include <ray.h>
#include <intersect.h> #include <intersect.h>
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
class Cube : public Shape { class Cube : public Shape {
private: private:
@@ -24,6 +25,8 @@ private:
public: public:
Cube() : Shape(SHAPE_CUBE) { stats.addCube(); }; Cube() : Shape(SHAPE_CUBE) { stats.addCube(); };
void dumpMe(FILE *fp);
}; };
#endif /* DORAYME_CUBE_H */ #endif /* DORAYME_CUBE_H */

View File

@@ -13,6 +13,7 @@
#include <ray.h> #include <ray.h>
#include <intersect.h> #include <intersect.h>
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
class Cylinder : public Shape { class Cylinder : public Shape {
private: private:
@@ -32,6 +33,8 @@ public:
BoundingBox getBounds(); BoundingBox getBounds();
bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); }; bool haveFiniteBounds() { return !(isinf(this->minCap) || isinf(this->maxCap)); };
void dumpMe(FILE *fp);
}; };
#endif //DORAYME_CYLINDER_H #endif //DORAYME_CYLINDER_H

View File

@@ -10,6 +10,7 @@
#define DORAYME_GROUP_H #define DORAYME_GROUP_H
#include <shape.h> #include <shape.h>
#include <stdio.h>
/* TODO: Add a way to force(?) material from group to be applied on childs */ /* TODO: Add a way to force(?) material from group to be applied on childs */
@@ -43,6 +44,8 @@ public:
void updateTransform(); void updateTransform();
Group(); Group();
void dumpMe(FILE * fp);
}; };
#endif /* DORAYME_GROUP_H */ #endif /* DORAYME_GROUP_H */

View File

@@ -12,6 +12,7 @@
#include <tuple.h> #include <tuple.h>
#include <colour.h> #include <colour.h>
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
enum LightType enum LightType
{ {
@@ -33,6 +34,8 @@ public:
bool operator==(const Light &b) const { return this->intensity == b.intensity && bool operator==(const Light &b) const { return this->intensity == b.intensity &&
this->position == b.position && this->position == b.position &&
this->type == b.type; }; this->type == b.type; };
void dumpMe(FILE *fp);
}; };
#endif /* DORAYME_LIGHT_H */ #endif /* DORAYME_LIGHT_H */

View File

@@ -68,27 +68,27 @@ public:
void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARay<count) { this->maxIntersectOnARay = count; } }; void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARay<count) { this->maxIntersectOnARay = count; } };
void printStats() { void printStats() {
printf("Rendering statistics:\n"); printf("Rendering statistics:\n");
printf("Cones : %ld\n", this->coneCount); printf("Cones : %lld\n", this->coneCount);
printf("Cubes : %ld\n", this->cubeCount); printf("Cubes : %lld\n", this->cubeCount);
printf("Cylinders : %ld\n", this->cylinderCount); printf("Cylinders : %lld\n", this->cylinderCount);
printf("Groups : %ld\n", this->groupCount); printf("Groups : %lld\n", this->groupCount);
printf("Lights : %ld\n", this->lightCount); printf("Lights : %lld\n", this->lightCount);
printf("Planes : %ld\n", this->planeCount); printf("Planes : %lld\n", this->planeCount);
printf("Spheres : %ld\n", this->sphereCount); printf("Spheres : %lld\n", this->sphereCount);
printf("Triangles : %ld\n", this->triangleCount); printf("Triangles : %lld\n", this->triangleCount);
printf("==================================================\n"); printf("==================================================\n");
printf("Pixel rendered : %ld\n", this->pixelCount); printf("Pixel rendered : %lld\n", this->pixelCount);
printf("Ray casted : %ld\n", this->rayCount); printf("Ray casted : %lld\n", this->rayCount);
printf("Light Ray casted : %ld\n", this->lightRayEmitedCount); printf("Light Ray casted : %lld\n", this->lightRayEmitedCount);
printf("Reflection ray casted : %ld\n", this->reflectionRayCount); printf("Reflection ray casted : %lld\n", this->reflectionRayCount);
printf("Refraction ray casted : %ld\n", this->refractedRayCount); printf("Refraction ray casted : %lld\n", this->refractedRayCount);
printf("Intersect object created: %ld\n", this->intersectCount); printf("Intersect object created: %lld\n", this->intersectCount);
printf("Intersection created : %ld\n", this->intersectionCount); printf("Intersection created : %lld\n", this->intersectionCount);
printf("Malloc called : %ld\n", this->mallocCallCount); printf("Malloc called : %lld\n", this->mallocCallCount);
printf("Realloc called : %ld\n", this->reallocCallCount); printf("Realloc called : %lld\n", this->reallocCallCount);
printf("Bounding box missed : %ld\n", this->discardedIntersectCount); printf("Bounding box missed : %lld\n", this->discardedIntersectCount);
printf("Min depth atteined : %ld\n", this->maxDepthAttained); printf("Min depth atteined : %lld\n", this->maxDepthAttained);
printf("Max intersect count : %ld\n", this->maxIntersectOnARay); printf("Max intersect count : %lld\n", this->maxIntersectOnARay);
printf("==================================================\n"); printf("==================================================\n");
}; };
}; };

View File

@@ -13,6 +13,7 @@
#include <ray.h> #include <ray.h>
#include <intersect.h> #include <intersect.h>
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h>
class Sphere : public Shape class Sphere : public Shape
{ {
@@ -23,6 +24,9 @@ protected:
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 */
void dumpMe(FILE *fp);
}; };
/* Mostly for test purposes */ /* Mostly for test purposes */

View File

@@ -10,6 +10,7 @@
#define DORAYME_TRIANGLE_H #define DORAYME_TRIANGLE_H
#include <shape.h> #include <shape.h>
#include <stdio.h>
class Triangle : public Shape class Triangle : public Shape
{ {
@@ -25,6 +26,8 @@ public:
Triangle(Point p1, Point p2, Point p3); Triangle(Point p1, Point p2, Point p3);
BoundingBox getBounds(); BoundingBox getBounds();
void dumpMe(FILE *fp);
}; };
#endif /* DORAYME_TRIANGLE_H */ #endif /* DORAYME_TRIANGLE_H */

View File

@@ -138,3 +138,16 @@ BoundingBox Cone::getBounds()
return ret; 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);
}

View File

@@ -74,3 +74,15 @@ Tuple Cube::localNormalAt(Tuple point)
return Vector(0, 0, point.z); 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);
}

View File

@@ -120,3 +120,16 @@ BoundingBox Cylinder::getBounds()
return ret; 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);
}

View File

@@ -166,3 +166,33 @@ void Group::updateTransform()
*/ */
this->updateBoundingBox(); 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);
}

View File

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

View File

@@ -81,7 +81,7 @@ void Material::dumpMe(FILE *fp)
fprintf(fp, "\"RefractiveIndex\": %f,\n", this->refractiveIndex); fprintf(fp, "\"RefractiveIndex\": %f,\n", this->refractiveIndex);
if (this->pattern) if (this->pattern)
{ {
fprintf(fp, "\"Pattern\": {\n", this->emissive); fprintf(fp, "\"Pattern\": {\n");
this->pattern->dumpMe(fp); this->pattern->dumpMe(fp);
fprintf(fp, "},\n"); fprintf(fp, "},\n");
} }

View File

@@ -81,4 +81,7 @@ void Shape::dumpMe(FILE *fp)
this->material.dumpMe(fp); this->material.dumpMe(fp);
fprintf(fp, "},\n"); fprintf(fp, "},\n");
fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow); fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow);
fprintf(fp, "\"BoundingBox\": {\n");
this->getBounds().dumpMe(fp);
fprintf(fp, "},\n");
} }

View File

@@ -39,3 +39,15 @@ Tuple Sphere::localNormalAt(Tuple point)
{ {
return (point - Point(0, 0, 0)).normalise(); 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);
}

View File

@@ -72,3 +72,18 @@ BoundingBox Triangle::getBounds()
return ret; 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);
}

View File

@@ -211,7 +211,7 @@ void World::dumpMe(FILE *fp)
for(i = 0; i < this->lightCount; i++) for(i = 0; i < this->lightCount; i++)
{ {
fprintf(fp, "\"%d\": {\n", i); fprintf(fp, "\"%d\": {\n", i);
//this->lightList[i]->dumpMe(fp); this->lightList[i]->dumpMe(fp);
fprintf(fp, "},\n"); fprintf(fp, "},\n");
} }
fprintf(fp, "},\n"); fprintf(fp, "},\n");