Start working on dumping the world (to a JSON file) for debug purposes.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <colour.h>
|
#include <colour.h>
|
||||||
#include <pattern.h>
|
#include <pattern.h>
|
||||||
#include <light.h>
|
#include <light.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class Shape;
|
class Shape;
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ public:
|
|||||||
double_equal(this->refractiveIndex, b.refractiveIndex) &&
|
double_equal(this->refractiveIndex, b.refractiveIndex) &&
|
||||||
(this->colour == b.colour); };
|
(this->colour == b.colour); };
|
||||||
bool operator!=(const Material &b) const { return !(*this == b); };
|
bool operator!=(const Material &b) const { return !(*this == b); };
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <colour.h>
|
#include <colour.h>
|
||||||
#include <tuple.h>
|
#include <tuple.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class Shape;
|
class Shape;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ public:
|
|||||||
Pattern(Colour a, Colour b);
|
Pattern(Colour a, Colour b);
|
||||||
|
|
||||||
virtual Colour patternAt(Tuple point) = 0;
|
virtual Colour patternAt(Tuple point) = 0;
|
||||||
|
virtual void dumpMe(FILE *fp);
|
||||||
|
|
||||||
void setTransform(Matrix transform);
|
void setTransform(Matrix transform);
|
||||||
Colour patternAtObject(Shape *object, Tuple point);
|
Colour patternAtObject(Shape *object, Tuple point);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
class Shape;
|
class Shape;
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
#include <tuple.h>
|
#include <tuple.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
@@ -63,6 +64,8 @@ public:
|
|||||||
|
|
||||||
virtual void updateTransform();
|
virtual void updateTransform();
|
||||||
|
|
||||||
|
virtual void dumpMe(FILE *fp);
|
||||||
|
|
||||||
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
||||||
Tuple objectToWorld(Tuple point) { return this->transformMatrix * point; };
|
Tuple objectToWorld(Tuple point) { return this->transformMatrix * point; };
|
||||||
Tuple normalToWorld(Tuple normalVector);
|
Tuple normalToWorld(Tuple normalVector);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <shape.h>
|
#include <shape.h>
|
||||||
#include <intersect.h>
|
#include <intersect.h>
|
||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,7 @@ public:
|
|||||||
|
|
||||||
Intersect intersect(Ray r);
|
Intersect intersect(Ray r);
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_WORLD_H */
|
#endif /* DORAYME_WORLD_H */
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ Matrix Matrix::transpose()
|
|||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
Matrix ret = Matrix(this->size);
|
Matrix ret = Matrix(this->size);
|
||||||
|
|
||||||
|
#pragma omp parallel for simd private(y, x)
|
||||||
for (y = 0 ; y < this->size ; y++)
|
for (y = 0 ; y < this->size ; y++)
|
||||||
{
|
{
|
||||||
for (x = 0 ; x < this->size ; x++)
|
for (x = 0 ; x < this->size ; x++)
|
||||||
@@ -139,6 +141,7 @@ Matrix Matrix::submatrix(int row, int column)
|
|||||||
int i, j;
|
int i, j;
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
Matrix ret = Matrix(this->size - 1);
|
Matrix ret = Matrix(this->size - 1);
|
||||||
|
|
||||||
for (i = 0 ; i < this->size ; i++)
|
for (i = 0 ; i < this->size ; i++)
|
||||||
{
|
{
|
||||||
if (i == row)
|
if (i == row)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <pattern.h>
|
#include <pattern.h>
|
||||||
#include <shape.h>
|
#include <shape.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
Pattern::Pattern(Colour a, Colour b): a(a), b(b)
|
Pattern::Pattern(Colour a, Colour b): a(a), b(b)
|
||||||
{
|
{
|
||||||
@@ -28,4 +29,10 @@ void Pattern::setTransform(Matrix transform)
|
|||||||
{
|
{
|
||||||
this->transformMatrix = transform;
|
this->transformMatrix = transform;
|
||||||
this->inverseTransform = transform.inverse();
|
this->inverseTransform = transform.inverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pattern::dumpMe(FILE *fp)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"Colour A\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", this->a.x, this->a.y, this->a.z);
|
||||||
|
fprintf(fp, "\"Colour B\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", this->b.x, this->b.y, this->b.z);
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
#ifndef DORAYME_CHECKERSPATTERN_H
|
#ifndef DORAYME_CHECKERSPATTERN_H
|
||||||
#define DORAYME_CHECKERSPATTERN_H
|
#define DORAYME_CHECKERSPATTERN_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class CheckersPattern : public Pattern
|
class CheckersPattern : public Pattern
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -20,6 +22,12 @@ public:
|
|||||||
|
|
||||||
return (fmod(value, 2) == 0)?this->a:this->b;
|
return (fmod(value, 2) == 0)?this->a:this->b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp) {
|
||||||
|
fprintf(fp, "\"Type\": \"Checkers\",\n");
|
||||||
|
Pattern::dumpMe(fp);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_CHECKERSPATTERN_H */
|
#endif /* DORAYME_CHECKERSPATTERN_H */
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#define DORAYME_GRADIENTPATTERN_H
|
#define DORAYME_GRADIENTPATTERN_H
|
||||||
|
|
||||||
#include <pattern.h>
|
#include <pattern.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class GradientPattern : public Pattern
|
class GradientPattern : public Pattern
|
||||||
{
|
{
|
||||||
@@ -25,6 +26,12 @@ public:
|
|||||||
|
|
||||||
return Colour(ret.x, ret.y, ret.z);
|
return Colour(ret.x, ret.y, ret.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp) {
|
||||||
|
fprintf(fp, "\"Type\": \"Gradient\",\n");
|
||||||
|
Pattern::dumpMe(fp);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_GRADIENTPATTERN_H */
|
#endif /* DORAYME_GRADIENTPATTERN_H */
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ public:
|
|||||||
|
|
||||||
return (fmod(value, 2) == 0)?this->a:this->b;
|
return (fmod(value, 2) == 0)?this->a:this->b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp) {
|
||||||
|
fprintf(fp, "\"Type\": \"Ring\"\n");
|
||||||
|
Pattern::dumpMe(fp);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ public:
|
|||||||
}
|
}
|
||||||
return this->b;
|
return this->b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp) {
|
||||||
|
fprintf(fp, "\"Type\": \"Strip\",\n");
|
||||||
|
Pattern::dumpMe(fp);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_STRIPPATTERN_H */
|
#endif /* DORAYME_STRIPPATTERN_H */
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ public:
|
|||||||
{
|
{
|
||||||
return Colour(point.x, point.y, point.z);
|
return Colour(point.x, point.y, point.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp) {
|
||||||
|
fprintf(fp, "\"Type\": \"Test\",\n");
|
||||||
|
Pattern::dumpMe(fp);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_TESTPATTERN_H */
|
#endif /* DORAYME_TESTPATTERN_H */
|
||||||
|
|||||||
@@ -66,4 +66,23 @@ Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple norma
|
|||||||
finalColour = emissiveColour + ambientColour + diffuseColour + specularColour;
|
finalColour = emissiveColour + ambientColour + diffuseColour + specularColour;
|
||||||
|
|
||||||
return Colour(finalColour.x, finalColour.y, finalColour.z);
|
return Colour(finalColour.x, finalColour.y, finalColour.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Material::dumpMe(FILE *fp)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"Colour\": {\"red\": %f, \"green\": %f, \"blue\": %f},\n", this->colour.x, this->colour.y, this->colour.z);
|
||||||
|
fprintf(fp, "\"Ambient\": %f,\n", this->ambient);
|
||||||
|
fprintf(fp, "\"Diffuse\": %f,\n", this->diffuse);
|
||||||
|
fprintf(fp, "\"Specular\": %f,\n", this->specular);
|
||||||
|
fprintf(fp, "\"Shininess\": %f,\n", this->shininess);
|
||||||
|
fprintf(fp, "\"Reflective\": %f,\n", this->reflective);
|
||||||
|
fprintf(fp, "\"Transparency\": %f,\n", this->transparency);
|
||||||
|
fprintf(fp, "\"Emissive\": %f,\n", this->emissive);
|
||||||
|
fprintf(fp, "\"RefractiveIndex\": %f,\n", this->refractiveIndex);
|
||||||
|
if (this->pattern)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"Pattern\": {\n", this->emissive);
|
||||||
|
this->pattern->dumpMe(fp);
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -73,4 +73,12 @@ BoundingBox Shape::getBounds()
|
|||||||
ret.min = this->objectToWorld(Point(-1, -1, -1));
|
ret.min = this->objectToWorld(Point(-1, -1, -1));
|
||||||
ret.max = this->objectToWorld(Point(1, 1, 1));
|
ret.max = this->objectToWorld(Point(1, 1, 1));
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shape::dumpMe(FILE *fp)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"Material\": {\n");
|
||||||
|
this->material.dumpMe(fp);
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow);
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <world.h>
|
#include <world.h>
|
||||||
#include <light.h>
|
#include <light.h>
|
||||||
#include <shape.h>
|
#include <shape.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MIN_ALLOC (2)
|
#define MIN_ALLOC (2)
|
||||||
|
|
||||||
@@ -197,4 +199,32 @@ Colour World::refractedColour(Computation comps, uint32_t depthCount)
|
|||||||
Tuple hitColour = this->colourAt(refractedRay, depthCount - 1) * comps.material->transparency;
|
Tuple hitColour = this->colourAt(refractedRay, depthCount - 1) * comps.material->transparency;
|
||||||
|
|
||||||
return Colour(hitColour.x, hitColour.y, hitColour.z);
|
return Colour(hitColour.x, hitColour.y, hitColour.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::dumpMe(FILE *fp)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
/* JSON Opening */
|
||||||
|
fprintf(fp, "{\n");
|
||||||
|
|
||||||
|
fprintf(fp, "\"Lights\": {\n");
|
||||||
|
for(i = 0; i < this->lightCount; i++)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"%d\": {\n", i);
|
||||||
|
//this->lightList[i]->dumpMe(fp);
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
}
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
/* JSON Closing */
|
||||||
|
fprintf(fp, "}\n");
|
||||||
}
|
}
|
||||||
@@ -228,6 +228,15 @@ int main()
|
|||||||
|
|
||||||
/* ----------------------------- */
|
/* ----------------------------- */
|
||||||
|
|
||||||
|
FILE *fpOut = fopen("christmas_worlddump.json", "wt");
|
||||||
|
if (fpOut)
|
||||||
|
{
|
||||||
|
w.dumpMe(fpOut);
|
||||||
|
fclose(fpOut);
|
||||||
|
}
|
||||||
|
/* ----------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/* Set the camera */
|
/* Set the camera */
|
||||||
Camera camera = Camera(40, 30, 1.047);
|
Camera camera = Camera(40, 30, 1.047);
|
||||||
camera.setTransform(viewTransform(Point(0, 0, -4),
|
camera.setTransform(viewTransform(Point(0, 0, -4),
|
||||||
|
|||||||
Reference in New Issue
Block a user