diff --git a/Makefile b/Makefile index 9452c5f..d02f502 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ OBJS=Implicit.o \ util/ObjParser.o \ MarchingCubes.o \ _gen/marching_cubes_data.o \ + tests/TestImplicitSphere.o \ render/GlutRender.o all: $(TARGETS:=.bin) diff --git a/main_test_sphere.cpp b/main_test_sphere.cpp new file mode 100644 index 0000000..61fb823 --- /dev/null +++ b/main_test_sphere.cpp @@ -0,0 +1,33 @@ +/** An entry-point file using render/GlutRender as a renderer, displaying a + * simple sphere. + **/ + +#include "render/GlutRender.hpp" +#include "util/ObjParser.hpp" +#include "tests/TestImplicitSphere.hpp" +#include "Mesh.hpp" +#include "MarchingCubes.hpp" + +int main(int argc, char** argv) { + GlutRender& render = GlutRender::get_instance(); + render.init(&argc, argv, 640, 480, "Bouncing stuff"); + + TestImplicitSphere sph1(Point(2.5, -1, 0), 1); + TestImplicitSphere sph2(Point(-4, 0.5, 0), 1.4); + Mesh m_sph1 = MarchingCubes(sph1, + Cuboid(Point(1, -2, -2), Point(3, 0, 2)))(); + Mesh m_sph2 = MarchingCubes(sph2, + Cuboid(Point(-6, -2, -2), Point(2, 3, 2)))(); + render.add_mesh(&m_sph1); + render.add_mesh(&m_sph2); + + puts("=== All set! ==="); + + printf("Sph1 has %ld vertices, %ld faces.\n", + m_sph1.get_vertices().size(), + m_sph1.get_faces().size()); + + render.run(); + + return 0; +} diff --git a/tests/TestImplicitSphere.cpp b/tests/TestImplicitSphere.cpp new file mode 100644 index 0000000..575dc56 --- /dev/null +++ b/tests/TestImplicitSphere.cpp @@ -0,0 +1,9 @@ +#include "TestImplicitSphere.hpp" + +double TestImplicitSphere::operator()(double x, double y, double z) const { + auto sq = [](double x) { return x*x; }; + return - (sq(center.x - x) + + sq(center.y - y) + + sq(center.z - z)) + + sq(radius); +} diff --git a/tests/TestImplicitSphere.hpp b/tests/TestImplicitSphere.hpp new file mode 100644 index 0000000..09b1fb9 --- /dev/null +++ b/tests/TestImplicitSphere.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "../Implicit.hpp" + +class TestImplicitSphere: public ImplicitSurface { + public: + TestImplicitSphere(const Point& center, double r): + center(center), radius(r) {} + virtual double operator()(double x, double y, double z) const; + + private: + Point center; + double radius; +};