Bouncing nearly works'

This commit is contained in:
Rémi Oudin 2018-02-13 01:02:58 +01:00
parent 0bae04d802
commit e3d913fd61
3 changed files with 11 additions and 8 deletions

View file

@ -24,6 +24,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);
}
void Ball::_compute_T_n() {
@ -48,7 +49,7 @@ void Ball::_compute_v_x(Point normal) {
}
void Ball::_compute_v_z(Point normal) {
double factor = normal.x / (4*(normal.x + normal.z));
double factor = normal.z / (4*(normal.x + normal.z));
v_z *= (0.5 + factor);
}

View file

@ -3,6 +3,7 @@
**/
#include "spheroid.hpp"
#include <iostream>
Spheroid::Spheroid(const Point& _center, double _min_p, double _p, double _q) :
ImplicitSurface(_center), normal_vector(Point(0,0,1)), min_p(_min_p),
@ -18,11 +19,11 @@ void Spheroid::_compute_volume() {
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);
q = (3./4.) * V / PI / (p*p);
}
@ -30,10 +31,11 @@ void Spheroid::update_center_pos(Point& _center) {
center = _center;
}
void Spheroid::check_horizontal_plan_collision(double& height) {
if ((center.y - p) <= height) {
void Spheroid::check_horizontal_plan_collision(double height) {
if (((center.y - p) <= height) || (p <= init_p)) {
p = fmin(init_p, center.y-height);
update_radius();
std::cout << "p:" << p << "q:" << q << '\n';
}
}
@ -71,6 +73,6 @@ void Spheroid::check_perlin_collision(PerlinNoise perlin) {
double Spheroid::operator() (double _x, double _y, double _z) const {
return (pow(_x, 2) / pow(q, 2)
+ pow(_y, 2) / pow(q, 2)
+ pow(_z, 2) / pow(p, 2) -1);
+ pow(_y, 2) / pow(p, 2)
+ pow(_z, 2) / pow(q, 2) -1);
}

View file

@ -17,7 +17,7 @@ class Spheroid : public ImplicitSurface {
void update_center_pos(Point& _center);
void update_radius();
void update_height();
void check_horizontal_plan_collision(double& height);
void check_horizontal_plan_collision(double height);
void check_vertical_plan_collision(double& abscissa);
Cuboid max_bounding_box() const;
void check_perlin_collision(PerlinNoise perlin);