Enhance slightly the scene (floor + background)
This commit is contained in:
parent
3e3ec57bb5
commit
3bf61a7409
6 changed files with 80 additions and 11 deletions
5
Ball.cpp
5
Ball.cpp
|
@ -42,7 +42,6 @@ void Ball::_compute_pos(double dt) {
|
||||||
}
|
}
|
||||||
Center.x += dt * v_x;
|
Center.x += dt * v_x;
|
||||||
Center.z += dt * v_z;
|
Center.z += dt * v_z;
|
||||||
std::cout << (*this) <<"\n";
|
|
||||||
surface.update_center_pos(Center);
|
surface.update_center_pos(Center);
|
||||||
surface.check_ground_collision(ground);
|
surface.check_ground_collision(ground);
|
||||||
}
|
}
|
||||||
|
@ -89,10 +88,6 @@ void Ball::_compute_parameters() {
|
||||||
_compute_v_x(normal);
|
_compute_v_x(normal);
|
||||||
_compute_v_z(normal);
|
_compute_v_z(normal);
|
||||||
min_height = fmin(radius, min_height + 0.2 * (radius - min_height));
|
min_height = fmin(radius, min_height + 0.2 * (radius - min_height));
|
||||||
std::cout << "U:" << U << "\n";
|
|
||||||
std::cout << "B:" << B << "\n";
|
|
||||||
std::cout << "A:" << A << "\n";
|
|
||||||
std::cout << "T:" << T << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::update_pos(double dt) {
|
void Ball::update_pos(double dt) {
|
||||||
|
|
45
GroundFlatMesh.cpp
Normal file
45
GroundFlatMesh.cpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include "GroundFlatMesh.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
const int GroundFlatMesh::MIN_I = -40;
|
||||||
|
const int GroundFlatMesh::MAX_I = 100;
|
||||||
|
const int GroundFlatMesh::MIN_J = -40;
|
||||||
|
const int GroundFlatMesh::MAX_J = 100;
|
||||||
|
|
||||||
|
GroundFlatMesh::GroundFlatMesh(const Point& center, double decay_speed)
|
||||||
|
: center(center), decay_speed(decay_speed)
|
||||||
|
{
|
||||||
|
std::vector<std::vector<size_t> > vertice_at(MAX_I - MIN_I + 1,
|
||||||
|
std::vector<size_t>(MAX_J - MIN_J + 1));
|
||||||
|
|
||||||
|
for(int i=MIN_I; i < MAX_I + 1; ++i) {
|
||||||
|
for(int j=MIN_J; j < MAX_J + 1; ++j) {
|
||||||
|
vertice_at[i - MIN_I][j - MIN_J] =
|
||||||
|
output.add_vertice(
|
||||||
|
tile_position(i, j),
|
||||||
|
Point(0., 1., 0.));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=MIN_I; i < MAX_I; ++i) {
|
||||||
|
for(int j=MIN_J; j < MAX_J; ++j) {
|
||||||
|
output.add_face(Face(
|
||||||
|
vertice_at[i - MIN_I][j - MIN_J],
|
||||||
|
vertice_at[i - MIN_I][j + 1 - MIN_J],
|
||||||
|
vertice_at[i + 1 - MIN_I][j + 1 - MIN_J]));
|
||||||
|
output.add_face(Face(
|
||||||
|
vertice_at[i - MIN_I][j - MIN_J],
|
||||||
|
vertice_at[i + 1 - MIN_I][j + 1 - MIN_J],
|
||||||
|
vertice_at[i + 1- MIN_I][j - MIN_J]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double GroundFlatMesh::ith_dist(int i) const {
|
||||||
|
return ((i < 0) ? -1 : 1) * decay_speed * i * i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point GroundFlatMesh::tile_position(int i, int j) const {
|
||||||
|
return Point(ith_dist(i), 0., ith_dist(j));
|
||||||
|
}
|
20
GroundFlatMesh.hpp
Normal file
20
GroundFlatMesh.hpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Mesh.hpp"
|
||||||
|
|
||||||
|
class GroundFlatMesh {
|
||||||
|
public:
|
||||||
|
GroundFlatMesh(const Point& center, double decay_speed);
|
||||||
|
|
||||||
|
Mesh* get_mesh() { return &output; }
|
||||||
|
|
||||||
|
private: //meth
|
||||||
|
double ith_dist(int i) const;
|
||||||
|
Point tile_position(int i, int j) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const int MIN_I, MAX_I, MIN_J, MAX_J;
|
||||||
|
Mesh output;
|
||||||
|
const Point& center;
|
||||||
|
double decay_speed;
|
||||||
|
};
|
1
Makefile
1
Makefile
|
@ -19,6 +19,7 @@ OBJS=Implicit.o \
|
||||||
MarchingCubes.o \
|
MarchingCubes.o \
|
||||||
_gen/marching_cubes_data.o \
|
_gen/marching_cubes_data.o \
|
||||||
periodic_updates.o \
|
periodic_updates.o \
|
||||||
|
GroundFlatMesh.o \
|
||||||
tests/TestImplicitSphere.o \
|
tests/TestImplicitSphere.o \
|
||||||
render/GlutRender.o
|
render/GlutRender.o
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "Ball.hpp"
|
#include "Ball.hpp"
|
||||||
#include "FlatGround.hpp"
|
#include "FlatGround.hpp"
|
||||||
#include "MarchingCubes.hpp"
|
#include "MarchingCubes.hpp"
|
||||||
|
#include "GroundFlatMesh.hpp"
|
||||||
|
|
||||||
#include "periodic_updates.hpp"
|
#include "periodic_updates.hpp"
|
||||||
|
|
||||||
|
@ -15,7 +16,8 @@ int main(int argc, char** argv) {
|
||||||
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.75, -0.5, -0.7, 1, 1);
|
Ball ball(Point(0, 5, 0), flat, 0.55, -.5, -.7, 1, 1);
|
||||||
|
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(-2, -1, -2), Point(2,1,2));
|
||||||
|
@ -24,6 +26,11 @@ int main(int argc, char** argv) {
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
|
GroundFlatMesh ground(Point(0., 0., 0.), 0.05);
|
||||||
|
ground.get_mesh()->set_color(Color(0.13, 0.82, 0.21));
|
||||||
|
render.add_mesh(ground.get_mesh());
|
||||||
|
|
||||||
render.set_idle_func(periodic_update);
|
render.set_idle_func(periodic_update);
|
||||||
init_periodic_static(&ball);
|
init_periodic_static(&ball);
|
||||||
render.run();
|
render.run();
|
||||||
|
|
|
@ -31,10 +31,10 @@ void GlutRender::init(int* argc, char** argv,
|
||||||
glutReshapeFunc(reshape_handle);
|
glutReshapeFunc(reshape_handle);
|
||||||
|
|
||||||
// ==== Lighting ====
|
// ==== Lighting ====
|
||||||
GLfloat light0_pos[] = {10., 15., 10.};
|
GLfloat light0_pos[] = {30., 35., 20., 0.};
|
||||||
GLfloat light0_ambient[] = {0., 0., 0., 1.};
|
GLfloat light0_ambient[] = {0., 0., 0., 1.};
|
||||||
GLfloat light0_diffuse[] = {1., 1., .65, 1.};
|
GLfloat light0_diffuse[] = {1., 1., .85, 1.};
|
||||||
GLfloat light0_specular[] = {5., 5., .33, 1.};
|
GLfloat light0_specular[] = {5., 5., .43, 1.};
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
|
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
|
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
||||||
|
@ -47,15 +47,16 @@ void GlutRender::init(int* argc, char** argv,
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
glShadeModel(GL_SMOOTH); // Enable smooth shading
|
glShadeModel(GL_SMOOTH); // Enable smooth shading
|
||||||
|
|
||||||
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
GLfloat material_specular[] = {1., 1., 1., 1.};
|
GLfloat material_specular[] = {1., 1., 1., 1.};
|
||||||
GLfloat material_emission[] = {0., 0., 0., 1.};
|
GLfloat material_emission[] = {0., 0., 0., 1.};
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
// ==== Misc ====
|
// ==== Misc ====
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Background color
|
//glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Background color
|
||||||
|
glClearColor(0.15f, 0.08f, 0.5f, 1.0f); // Background color
|
||||||
glClearDepth(1.0f); // Set background depth to farthest
|
glClearDepth(1.0f); // Set background depth to farthest
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue