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