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

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

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

View File

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

View File

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

View File

@@ -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);
}

View File

@@ -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);
}