Horizontal bounces.
This commit is contained in:
parent
22e24258cd
commit
80f0e96acf
2 changed files with 21 additions and 8 deletions
17
Ball.cpp
17
Ball.cpp
|
@ -1,7 +1,7 @@
|
|||
#include "Ball.hpp"
|
||||
#include <cmath>
|
||||
|
||||
Ball::Ball(Point& _center, double _p, double _q) :
|
||||
Ball::Ball(Point& _center, double _v_x, double _p, double _q) :
|
||||
Center(_center),
|
||||
surface(_center, _p, _q),
|
||||
init_h(_center.z),
|
||||
|
@ -10,12 +10,14 @@ Ball::Ball(Point& _center, double _p, double _q) :
|
|||
A(_center.z),
|
||||
B(0),
|
||||
U(sqrt(2 * G_CTE * _center.z)),
|
||||
T(0)
|
||||
T(0),
|
||||
v_x(_v_x)
|
||||
{
|
||||
}
|
||||
|
||||
void Ball::_compute_pos() {
|
||||
Center.x = A + B * crt_time - (G_CTE / 2) * crt_time * crt_time;
|
||||
void Ball::_compute_pos(double dt) {
|
||||
Center.z = A + B * crt_time - (G_CTE / 2) * crt_time * crt_time;
|
||||
Center.x += dt * v_x;
|
||||
surface.update_center_pos(Center);
|
||||
}
|
||||
|
||||
|
@ -35,6 +37,10 @@ void Ball::_compute_U_n() {
|
|||
U *= 1/2;
|
||||
}
|
||||
|
||||
void Ball::_compute_v_x() {
|
||||
v_x *= 1/2;
|
||||
}
|
||||
|
||||
void Ball::update_pos(double dt) {
|
||||
crt_time += dt;
|
||||
if (crt_time >= T) {
|
||||
|
@ -42,6 +48,7 @@ void Ball::update_pos(double dt) {
|
|||
_compute_U_n();
|
||||
_compute_A_n();
|
||||
_compute_B_n();
|
||||
_compute_v_x();
|
||||
}
|
||||
_compute_pos();
|
||||
_compute_pos(dt);
|
||||
}
|
||||
|
|
12
Ball.hpp
12
Ball.hpp
|
@ -3,7 +3,11 @@
|
|||
* A ball is the kind of real object, with a physical model, and the implicit
|
||||
* surface.
|
||||
* The physical model is strongly inspired from
|
||||
* http://www.physics-online.info/book1/chapt1/sect1a/problem1a-12/Problem1A-12.htm
|
||||
* http://www.physics-online.info/book1/chapt1/sect1a/problem1a-12/Problem1A-12.htm,
|
||||
* apart for the x-axis drift.
|
||||
* For this one, the assumption done is that the speed is divided by two at
|
||||
* each bounce, which is a reasonable assumption since it is the same for the
|
||||
* vertical bounces.
|
||||
**/
|
||||
|
||||
#include <cstddef>
|
||||
|
@ -19,12 +23,14 @@ class Ball {
|
|||
size_t bounce_number;
|
||||
double crt_time;
|
||||
double A, B, U, T; // Coefficients for the physical model.
|
||||
void _compute_pos();
|
||||
double v_x;
|
||||
void _compute_pos(double dt);
|
||||
void _compute_v_x();
|
||||
void _compute_A_n();
|
||||
void _compute_B_n();
|
||||
void _compute_U_n();
|
||||
void _compute_T_n();
|
||||
public:
|
||||
Ball(Point& _center, double p, double q);
|
||||
Ball(Point& _center, double _v_x, double p, double q);
|
||||
void update_pos(double dt);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue