Trying to make the dump a bit more usefull and slightly less cluttered
This commit is contained in:
@@ -23,6 +23,8 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3);
|
SmoothTriangle(Point p1, Point p2, Point p3, Vector n1, Vector n2, Vector n3);
|
||||||
|
|
||||||
|
void dumpMe(FILE *fp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_SMOOTHTRIANGLE_H */
|
#endif /* DORAYME_SMOOTHTRIANGLE_H */
|
||||||
|
|||||||
@@ -214,7 +214,20 @@ void OBJFile::dumpMe(FILE * fp)
|
|||||||
fprintf(fp, "\"Objects\": {\n");
|
fprintf(fp, "\"Objects\": {\n");
|
||||||
this->baseGroup->dumpMe(fp);
|
this->baseGroup->dumpMe(fp);
|
||||||
fprintf(fp, "},\n");
|
fprintf(fp, "},\n");
|
||||||
|
fprintf(fp, "\"Vertices\": {\n");
|
||||||
|
for(i = 1; i < this->vertexCount + 1; i++)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"v[%d]\": { \"x\": %f, \"y\": %f, \"z\": %f },\n", i,
|
||||||
|
this->vertices(i).x, this->vertices(i).y, this->vertices(i).z);
|
||||||
|
}
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
fprintf(fp, "\"NormalVertices\": {\n");
|
||||||
|
for(i = 1; i < this->vertexNormalCount + 1; i++)
|
||||||
|
{
|
||||||
|
fprintf(fp, "\"vn[%d]\": { \"x\": %f, \"y\": %f, \"z\": %f },\n", i,
|
||||||
|
this->verticesNormal(i).x, this->verticesNormal(i).y, this->verticesNormal(i).z);
|
||||||
|
}
|
||||||
|
fprintf(fp, "},\n");
|
||||||
Shape::dumpMe(fp);
|
Shape::dumpMe(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,12 @@ BoundingBox Shape::getBounds()
|
|||||||
|
|
||||||
void Shape::dumpMe(FILE *fp)
|
void Shape::dumpMe(FILE *fp)
|
||||||
{
|
{
|
||||||
fprintf(fp, "\"Material\": {\n");
|
if (this->materialSet)
|
||||||
this->material.dumpMe(fp);
|
{
|
||||||
fprintf(fp, "},\n");
|
fprintf(fp, "\"Material\": {\n");
|
||||||
|
this->material.dumpMe(fp);
|
||||||
|
fprintf(fp, "},\n");
|
||||||
|
}
|
||||||
fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow);
|
fprintf(fp, "\"DropShadow\": %d,\n", this->dropShadow);
|
||||||
fprintf(fp, "\"BoundingBox\": {\n");
|
fprintf(fp, "\"BoundingBox\": {\n");
|
||||||
this->getBounds().dumpMe(fp);
|
this->getBounds().dumpMe(fp);
|
||||||
|
|||||||
@@ -26,3 +26,17 @@ Tuple SmoothTriangle::localNormalAt(Tuple point, Intersection *hit)
|
|||||||
this->n3 * hit->v +
|
this->n3 * hit->v +
|
||||||
this->n1 * (1 - hit->u - hit->v)).normalise();
|
this->n1 * (1 - hit->u - hit->v)).normalise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SmoothTriangle::dumpMe(FILE *fp)
|
||||||
|
{
|
||||||
|
Tuple t = this->n1;
|
||||||
|
fprintf(fp, "\"n1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
|
t = this->n2;
|
||||||
|
fprintf(fp, "\"n2\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
|
t = this->n3;
|
||||||
|
fprintf(fp, "\"n3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
|
Triangle::dumpMe(fp);
|
||||||
|
}
|
||||||
@@ -73,6 +73,8 @@ BoundingBox Triangle::getLocalBounds()
|
|||||||
void Triangle::dumpMe(FILE *fp)
|
void Triangle::dumpMe(FILE *fp)
|
||||||
{
|
{
|
||||||
fprintf(fp, "\"Type\": \"Triangle\",\n");
|
fprintf(fp, "\"Type\": \"Triangle\",\n");
|
||||||
|
|
||||||
|
/* World points*/
|
||||||
Tuple t = this->transformMatrix * this->p1;
|
Tuple t = this->transformMatrix * this->p1;
|
||||||
fprintf(fp, "\"p1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
fprintf(fp, "\"p1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
t.x, t.y, t.z);
|
t.x, t.y, t.z);
|
||||||
@@ -82,5 +84,16 @@ void Triangle::dumpMe(FILE *fp)
|
|||||||
t = this->transformMatrix * this->p3;
|
t = this->transformMatrix * this->p3;
|
||||||
fprintf(fp, "\"p3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
fprintf(fp, "\"p3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
t.x, t.y, t.z);
|
t.x, t.y, t.z);
|
||||||
|
|
||||||
|
/* Local points */
|
||||||
|
t = this->p1;
|
||||||
|
fprintf(fp, "\"lp1\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
|
t = this->p2;
|
||||||
|
fprintf(fp, "\"lp2\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
|
t = this->p3;
|
||||||
|
fprintf(fp, "\"lp3\": { \"x\": %f, \"y\": %f, \"z\": %f}, \n",
|
||||||
|
t.x, t.y, t.z);
|
||||||
Shape::dumpMe(fp);
|
Shape::dumpMe(fp);
|
||||||
}
|
}
|
||||||
@@ -36,44 +36,56 @@ int main()
|
|||||||
/* ----------------------------- */
|
/* ----------------------------- */
|
||||||
|
|
||||||
/* Floor */
|
/* Floor */
|
||||||
Plane p = Plane();
|
Material planesMaterial = Material();
|
||||||
CheckersPattern checkered = CheckersPattern(Colour(0.35, 0.35, 0.35), Colour(0.4, 0.4, 0.4));
|
CheckersPattern checkered = CheckersPattern(Colour(0.35, 0.35, 0.35), Colour(0.4, 0.4, 0.4));
|
||||||
p.material.pattern = &checkered;
|
planesMaterial.pattern = &checkered;
|
||||||
p.material.ambient = 1;
|
planesMaterial.ambient = 1;
|
||||||
p.material.diffuse = 0;
|
planesMaterial.diffuse = 0;
|
||||||
p.material.specular = 0;
|
planesMaterial.specular = 0;
|
||||||
|
|
||||||
|
|
||||||
|
Plane p = Plane();
|
||||||
|
p.setMaterial(planesMaterial);
|
||||||
p.material.reflective = 0.1;
|
p.material.reflective = 0.1;
|
||||||
w.addObject(&p);
|
w.addObject(&p);
|
||||||
|
|
||||||
Plane p2 = Plane();
|
Plane p2 = Plane();
|
||||||
p2.setTransform(translation(0, 0, -10) * rotationX(M_PI/2));
|
p2.setTransform(translation(0, 0, -10) * rotationX(M_PI/2));
|
||||||
p2.material.pattern = &checkered;
|
p2.setMaterial(planesMaterial);
|
||||||
p2.material.ambient = 1;
|
|
||||||
p2.material.diffuse = 0;
|
|
||||||
p2.material.specular = 0;
|
|
||||||
w.addObject(&p2);
|
w.addObject(&p2);
|
||||||
|
|
||||||
|
Material lowPoly = Material();
|
||||||
|
lowPoly.colour = Colour(1, 0.3, 0.2);
|
||||||
|
lowPoly.shininess = 5;
|
||||||
|
lowPoly.specular = 0.4;
|
||||||
|
|
||||||
OBJFile teapot = OBJFile("teapot-low.obj");
|
OBJFile teapot = OBJFile("teapot-low.obj");
|
||||||
teapot.setTransform(translation(7, 0, 3) * rotationY(M_PI*23/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
|
teapot.setTransform(translation(7, 0, 3) * rotationY(M_PI*23/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
|
||||||
teapot.material.colour = Colour(1, 0.3, 0.2);
|
teapot.setMaterial(lowPoly);
|
||||||
teapot.material.shininess = 5;
|
w.addObject(teapot.getBaseGroup());
|
||||||
teapot.material.specular = 0.4;
|
|
||||||
w.addObject(&teapot);
|
FILE *fpOut = fopen("lowpoly_teapot.json", "wt");
|
||||||
|
if (fpOut)
|
||||||
|
{
|
||||||
|
teapot.dumpMe(fpOut);
|
||||||
|
fclose(fpOut);
|
||||||
|
}
|
||||||
|
|
||||||
OBJFile teapot2 = OBJFile("teapot-lowtri.obj");
|
OBJFile teapot2 = OBJFile("teapot-lowtri.obj");
|
||||||
teapot2.setTransform(translation(-7, 0, 3) * rotationY(-M_PI*46/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
|
teapot2.setTransform(translation(-7, 0, 3) * rotationY(-M_PI*46/22) * rotationX(-M_PI/2) * scaling(0.3, 0.3, 0.3));
|
||||||
teapot2.material.colour = Colour(1, 0.3, 0.2);
|
teapot2.setMaterial(lowPoly);;
|
||||||
teapot2.material.shininess = 5;
|
w.addObject(teapot2.getBaseGroup());
|
||||||
teapot2.material.specular = 0.4;
|
|
||||||
w.addObject(&teapot2);
|
Material highPoly = Material();
|
||||||
|
highPoly.colour = Colour(0.3, 1, 0.2);
|
||||||
|
highPoly.shininess = 5;
|
||||||
|
highPoly.specular = 0.4;
|
||||||
|
highPoly.reflective = 0.5;
|
||||||
|
|
||||||
OBJFile teapot3= OBJFile("teapot.obj");
|
OBJFile teapot3= OBJFile("teapot.obj");
|
||||||
teapot3.setTransform(translation(0, 0, -5) * rotationY(-M_PI) * rotationX(-M_PI/2) * scaling(0.4, 0.4, 0.4));
|
teapot3.setTransform(translation(0, 0, -5) * rotationY(-M_PI) * rotationX(-M_PI/2) * scaling(0.4, 0.4, 0.4));
|
||||||
teapot3.material.colour = Colour(0.3, 1, 0.2);
|
teapot3.setMaterial(highPoly);
|
||||||
teapot3.material.shininess = 5;
|
w.addObject(teapot3.getBaseGroup());
|
||||||
teapot3.material.specular = 0.4;
|
|
||||||
teapot3.material.reflective = 0.5;
|
|
||||||
w.addObject(&teapot3);
|
|
||||||
|
|
||||||
/* ----------------------------- */
|
/* ----------------------------- */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user