Integration of the grounds
This commit is contained in:
parent
d484a18da5
commit
15ee31c30e
7 changed files with 24 additions and 29 deletions
7
Ball.cpp
7
Ball.cpp
|
@ -5,10 +5,11 @@
|
||||||
bool bouncing = true;
|
bool bouncing = true;
|
||||||
double stop_bouncing;
|
double stop_bouncing;
|
||||||
|
|
||||||
Ball::Ball(const Point& _center, double _min_height, double _v_x, double _v_z,
|
Ball::Ball(const Point& _center, const Ground* _ground, double _min_height,
|
||||||
double _p, double _q) :
|
double _v_x, double _v_z, double _p, double _q) :
|
||||||
Center(_center),
|
Center(_center),
|
||||||
surface(_center, _min_height, _p, _q),
|
surface(_center, _min_height, _p, _q),
|
||||||
|
ground(_ground),
|
||||||
radius(_p),
|
radius(_p),
|
||||||
init_h(_center.y),
|
init_h(_center.y),
|
||||||
min_height(_min_height),
|
min_height(_min_height),
|
||||||
|
@ -41,7 +42,7 @@ 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;
|
||||||
surface.update_center_pos(Center);
|
surface.update_center_pos(Center);
|
||||||
surface.check_horizontal_plan_collision(0.0);
|
surface.check_ground_collision(ground);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::_compute_T_n() {
|
void Ball::_compute_T_n() {
|
||||||
|
|
5
Ball.hpp
5
Ball.hpp
|
@ -12,6 +12,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "spheroid.hpp"
|
#include "spheroid.hpp"
|
||||||
|
#include "FlatGround.hpp"
|
||||||
|
#include "PerlinGround.hpp"
|
||||||
|
|
||||||
#define G_CTE 9.81
|
#define G_CTE 9.81
|
||||||
|
|
||||||
|
@ -19,6 +21,7 @@ class Ball {
|
||||||
private:
|
private:
|
||||||
Point Center;
|
Point Center;
|
||||||
Spheroid surface;
|
Spheroid surface;
|
||||||
|
const Ground* ground;
|
||||||
double radius;
|
double radius;
|
||||||
double init_h;
|
double init_h;
|
||||||
double min_height;
|
double min_height;
|
||||||
|
@ -34,7 +37,7 @@ class Ball {
|
||||||
void _compute_U_n();
|
void _compute_U_n();
|
||||||
void _compute_T_n();
|
void _compute_T_n();
|
||||||
public:
|
public:
|
||||||
Ball(const Point& _center, double _min_height, double _v_x,
|
Ball(const Point& _center, const Ground* ground, double _min_height, double _v_x,
|
||||||
double _v_z, double p, double q);
|
double _v_z, double p, double q);
|
||||||
void update_pos(double dt);
|
void update_pos(double dt);
|
||||||
Point getCenter() const {return Center;}
|
Point getCenter() const {return Center;}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Perlin Noise implementation for the ground (header file)
|
* Perlin Noise implementation for the ground (header file)
|
||||||
**/
|
**/
|
||||||
|
#pragma once
|
||||||
#include "Implicit.hpp"
|
#include "Implicit.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
|
@ -5,13 +5,16 @@
|
||||||
#include "Ball.hpp"
|
#include "Ball.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "FlatGround.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int i;
|
int i;
|
||||||
Point center(0,10,0);
|
Point center(0,10,0);
|
||||||
Ball ball(center, 0, 0.25, 0, 1, 1);
|
FlatGround* flat = new FlatGround();
|
||||||
|
|
||||||
|
Ball ball(center,flat, 0, 0.25, 0, 1, 1);
|
||||||
for(i=0; i< 10000; i++) {
|
for(i=0; i< 10000; i++) {
|
||||||
ball.update_pos(0.001);
|
ball.update_pos(0.001);
|
||||||
cout << ball << "\n";
|
cout << ball << "\n";
|
||||||
|
|
|
@ -4,15 +4,18 @@
|
||||||
|
|
||||||
#include "render/GlutRender.hpp"
|
#include "render/GlutRender.hpp"
|
||||||
#include "Ball.hpp"
|
#include "Ball.hpp"
|
||||||
|
#include "FlatGround.hpp"
|
||||||
#include "MarchingCubes.hpp"
|
#include "MarchingCubes.hpp"
|
||||||
|
|
||||||
#include "periodic_updates.hpp"
|
#include "periodic_updates.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
FlatGround* flat = new FlatGround();
|
||||||
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), 0.75, -.5, -.7, 1, 1);
|
Ball ball(Point(0, 5, 0), flat, 0.75, -0.5, -0.7, 1, 1);
|
||||||
|
|
||||||
Cuboid bbox = ball.get_surface()->max_bounding_box();
|
Cuboid bbox = ball.get_surface()->max_bounding_box();
|
||||||
printf("%.2lf %.2lf %.2lf | %.2lf %.2lf %.2lf\n",
|
printf("%.2lf %.2lf %.2lf | %.2lf %.2lf %.2lf\n",
|
||||||
|
|
20
spheroid.cpp
20
spheroid.cpp
|
@ -22,35 +22,19 @@ void Spheroid::update_radius() {
|
||||||
q = sqrt((3./4.) * V / PI / p);
|
q = sqrt((3./4.) * V / PI / p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spheroid::update_height() {
|
|
||||||
q = (3./4.) * V / PI / (p*p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Spheroid::update_center_pos(Point& _center) {
|
void Spheroid::update_center_pos(Point& _center) {
|
||||||
center = _center;
|
center = _center;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spheroid::check_horizontal_plan_collision(double height) {
|
void Spheroid::check_ground_collision(const Ground* ground) {
|
||||||
|
double height = (*ground)(center.x, center.z);
|
||||||
if (((center.y -p) <= height) || (p < init_p)) {
|
if (((center.y -p) <= height) || (p < init_p)) {
|
||||||
p = fmin(init_p, center.y - height);
|
p = fmin(init_p, center.y - height);
|
||||||
update_radius();
|
update_radius();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spheroid::check_vertical_plan_collision(double& abscissa) {
|
|
||||||
if (center.x <= abscissa) {
|
|
||||||
if ((center.x + q) >= abscissa) {
|
|
||||||
q = abscissa - center.x;
|
|
||||||
update_height();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((center.x - q) <= abscissa) {
|
|
||||||
q = center.x - abscissa;
|
|
||||||
update_height();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Cuboid Spheroid::max_bounding_box() const {
|
Cuboid Spheroid::max_bounding_box() const {
|
||||||
double max_radius = sqrt((3./4.) * V / PI / min_p);
|
double max_radius = sqrt((3./4.) * V / PI / min_p);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "Implicit.hpp"
|
#include "Implicit.hpp"
|
||||||
#include "common_structures.hpp"
|
#include "common_structures.hpp"
|
||||||
#include "PerlinNoise.hpp"
|
#include "PerlinNoise.hpp"
|
||||||
|
#include "FlatGround.hpp"
|
||||||
|
#include "PerlinGround.hpp"
|
||||||
|
|
||||||
const double PI = 3.141592653589793;
|
const double PI = 3.141592653589793;
|
||||||
|
|
||||||
|
@ -16,9 +18,7 @@ class Spheroid : public ImplicitSurface {
|
||||||
Spheroid(const Point& _center, double _min_p, double _p, double _q);
|
Spheroid(const Point& _center, double _min_p, double _p, double _q);
|
||||||
void update_center_pos(Point& _center);
|
void update_center_pos(Point& _center);
|
||||||
void update_radius();
|
void update_radius();
|
||||||
void update_height();
|
void check_ground_collision(const Ground* ground);
|
||||||
void check_horizontal_plan_collision(double height);
|
|
||||||
void check_vertical_plan_collision(double& abscissa);
|
|
||||||
Cuboid max_bounding_box() const;
|
Cuboid max_bounding_box() const;
|
||||||
void check_perlin_collision(PerlinNoise perlin);
|
void check_perlin_collision(PerlinNoise perlin);
|
||||||
Point getNormalVector() const { return normal_vector;}
|
Point getNormalVector() const { return normal_vector;}
|
||||||
|
|
Loading…
Reference in a new issue