Integrate Perlin noise switch
Also make Perlin noise ground wider and less ugly
This commit is contained in:
parent
b208cc237e
commit
eaa730f5dc
3 changed files with 42 additions and 15 deletions
|
@ -2,6 +2,8 @@
|
||||||
* bouncing implicit-surface defined sphere.
|
* bouncing implicit-surface defined sphere.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "render/GlutRender.hpp"
|
#include "render/GlutRender.hpp"
|
||||||
#include "Ball.hpp"
|
#include "Ball.hpp"
|
||||||
#include "FlatGround.hpp"
|
#include "FlatGround.hpp"
|
||||||
|
@ -11,26 +13,45 @@
|
||||||
#include "periodic_updates.hpp"
|
#include "periodic_updates.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
bool perlin = false;
|
||||||
|
for(int pos=1; pos < argc; ++pos) {
|
||||||
|
if(strcmp(argv[pos], "-perlin") == 0)
|
||||||
|
perlin = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last minute switch, this code is ugly, please close your eyes until
|
||||||
|
// stated otherwise.
|
||||||
|
PerlinGround perlin_ground;
|
||||||
|
FlatGround flat_ground;
|
||||||
|
GroundFlatMesh ground_mesh(Point(0., 0., 0.), 0.05);
|
||||||
|
Ground* ball_ground = nullptr;
|
||||||
|
if(perlin)
|
||||||
|
ball_ground = &perlin_ground;
|
||||||
|
else
|
||||||
|
ball_ground = &flat_ground;
|
||||||
|
// You can open your eyes, now.
|
||||||
|
|
||||||
PerlinGround* flat = new PerlinGround();
|
|
||||||
GlutRender& render = GlutRender::get_instance();
|
GlutRender& render = GlutRender::get_instance();
|
||||||
render.init(&argc, argv, 640, 480, "Bouncing stuff");
|
render.init(&argc, argv, 640, 480, "Bouncing stuff");
|
||||||
|
|
||||||
Ball ball(Point(0, 5, 0), flat, 0.55, -.5, -.7, 1, 1);
|
Ball ball(Point(0, 5, 0), ball_ground, 0.55, -.5, -.7, 1, 1);
|
||||||
ball.get_surface()->set_color(Color(1., 0., 0.));
|
ball.get_surface()->set_color(Color(1., 0., 0.));
|
||||||
|
|
||||||
Cuboid bbox = ball.get_surface()->max_bounding_box();
|
Cuboid bbox = ball.get_surface()->max_bounding_box();
|
||||||
Cuboid bbox_2(Point(-2, -1, -2), Point(2,1,2));
|
Cuboid bbox_2(Point(-20, -2, -20), Point(20,2,20));
|
||||||
printf("%.2lf %.2lf %.2lf | %.2lf %.2lf %.2lf\n",
|
printf("%.2lf %.2lf %.2lf | %.2lf %.2lf %.2lf\n",
|
||||||
bbox.low(0), bbox.low(1), bbox.low(2),
|
bbox.low(0), bbox.low(1), bbox.low(2),
|
||||||
bbox.high(0), bbox.high(1), bbox.high(2));
|
bbox.high(0), bbox.high(1), bbox.high(2));
|
||||||
render.add_surface(ball.get_surface(), bbox);
|
render.add_surface(ball.get_surface(), bbox);
|
||||||
render.add_surface(flat->get_surface(), bbox_2);
|
|
||||||
|
|
||||||
|
if(perlin) {
|
||||||
GroundFlatMesh ground(Point(0., 0., 0.), 0.05);
|
perlin_ground.get_surface()->set_color(Color(0.13, 0.82, 0.21));
|
||||||
ground.get_mesh()->set_color(Color(0.13, 0.82, 0.21));
|
render.add_surface(perlin_ground.get_surface(), bbox_2, 1);
|
||||||
render.add_mesh(ground.get_mesh());
|
}
|
||||||
|
else {
|
||||||
|
ground_mesh.get_mesh()->set_color(Color(0.13, 0.82, 0.21));
|
||||||
|
render.add_mesh(ground_mesh.get_mesh());
|
||||||
|
}
|
||||||
|
|
||||||
render.set_idle_func(periodic_update);
|
render.set_idle_func(periodic_update);
|
||||||
init_periodic_static(&ball);
|
init_periodic_static(&ball);
|
||||||
|
|
|
@ -74,12 +74,14 @@ void GlutRender::remove_mesh(Mesh* mesh) {
|
||||||
meshes.erase(mesh);
|
meshes.erase(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::add_surface(ImplicitSurface* surf, const Cuboid& box) {
|
void GlutRender::add_surface(ImplicitSurface* surf, const Cuboid& box,
|
||||||
surfaces.insert(SurfaceDetails(surf, box));
|
double resolution)
|
||||||
|
{
|
||||||
|
surfaces.insert(SurfaceDetails(surf, box, resolution));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::remove_surface(ImplicitSurface* surf) {
|
void GlutRender::remove_surface(ImplicitSurface* surf) {
|
||||||
surfaces.erase(SurfaceDetails(surf, Cuboid::empty()));
|
surfaces.erase(SurfaceDetails(surf, Cuboid::empty(), 0.1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::run() {
|
void GlutRender::run() {
|
||||||
|
@ -190,7 +192,8 @@ void GlutRender::display() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const SurfaceDetails& surface: surfaces) {
|
for(const SurfaceDetails& surface: surfaces) {
|
||||||
Mesh mesh = MarchingCubes(*surface.surface, surface.box)
|
Mesh mesh = MarchingCubes(*surface.surface, surface.box,
|
||||||
|
surface.resolution)
|
||||||
.add_hint(surface.surface->location_hint())
|
.add_hint(surface.surface->location_hint())
|
||||||
();
|
();
|
||||||
display_mesh(mesh);
|
display_mesh(mesh);
|
||||||
|
|
|
@ -18,7 +18,8 @@ class GlutRender {
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void add_mesh(Mesh* mesh);
|
void add_mesh(Mesh* mesh);
|
||||||
void remove_mesh(Mesh* mesh);
|
void remove_mesh(Mesh* mesh);
|
||||||
void add_surface(ImplicitSurface* surf, const Cuboid& box);
|
void add_surface(ImplicitSurface* surf, const Cuboid& box,
|
||||||
|
double resolution=0.1);
|
||||||
void remove_surface(ImplicitSurface* surf);
|
void remove_surface(ImplicitSurface* surf);
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
@ -26,11 +27,13 @@ class GlutRender {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SurfaceDetails {
|
struct SurfaceDetails {
|
||||||
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box):
|
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box,
|
||||||
surface(surf), box(box) {}
|
double resolution):
|
||||||
|
surface(surf), box(box), resolution(resolution) {}
|
||||||
|
|
||||||
ImplicitSurface* surface;
|
ImplicitSurface* surface;
|
||||||
Cuboid box;
|
Cuboid box;
|
||||||
|
double resolution;
|
||||||
|
|
||||||
bool operator<(const SurfaceDetails& oth) const {
|
bool operator<(const SurfaceDetails& oth) const {
|
||||||
return surface < oth.surface;
|
return surface < oth.surface;
|
||||||
|
|
Loading…
Reference in a new issue