Handling of bounces for perlin noise surfaces
This commit is contained in:
parent
0987290111
commit
f2f6e9cb76
2 changed files with 11 additions and 8 deletions
15
Ball.cpp
15
Ball.cpp
|
@ -41,24 +41,27 @@ void Ball::_compute_U_n() {
|
||||||
U *= 0.5;
|
U *= 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::_compute_v_x() {
|
void Ball::_compute_v_x(Point normal) {
|
||||||
v_x *= 0.5;
|
double factor = normal.x / (4*(normal.x + normal.y));
|
||||||
|
v_x *= (0.5 + factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::_compute_v_y() {
|
void Ball::_compute_v_y(Point normal) {
|
||||||
v_y *= 0.5;
|
double factor = normal.x / (4*(normal.x + normal.y));
|
||||||
|
v_y *= (0.5 + factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::update_pos(double dt) {
|
void Ball::update_pos(double dt) {
|
||||||
crt_time += dt;
|
crt_time += dt;
|
||||||
if (crt_time >= T) {
|
if (crt_time >= T) {
|
||||||
|
Point normal = surface.getNormalVector();
|
||||||
bounce_number += 1;
|
bounce_number += 1;
|
||||||
_compute_U_n();
|
_compute_U_n();
|
||||||
_compute_A_n();
|
_compute_A_n();
|
||||||
_compute_B_n();
|
_compute_B_n();
|
||||||
_compute_T_n();
|
_compute_T_n();
|
||||||
_compute_v_x();
|
_compute_v_x(normal);
|
||||||
_compute_v_y();
|
_compute_v_y(normal);
|
||||||
std::cout << "New bounce :";
|
std::cout << "New bounce :";
|
||||||
std::cout << "U:" << U << ":";
|
std::cout << "U:" << U << ":";
|
||||||
std::cout << "A:" << A << ":";
|
std::cout << "A:" << A << ":";
|
||||||
|
|
4
Ball.hpp
4
Ball.hpp
|
@ -26,8 +26,8 @@ class Ball {
|
||||||
double A, B, U, T; // Coefficients for the physical model.
|
double A, B, U, T; // Coefficients for the physical model.
|
||||||
double v_x, v_y;
|
double v_x, v_y;
|
||||||
void _compute_pos(double dt);
|
void _compute_pos(double dt);
|
||||||
void _compute_v_x();
|
void _compute_v_x(Point normal);
|
||||||
void _compute_v_y();
|
void _compute_v_y(Point normal);
|
||||||
void _compute_A_n();
|
void _compute_A_n();
|
||||||
void _compute_B_n();
|
void _compute_B_n();
|
||||||
void _compute_U_n();
|
void _compute_U_n();
|
||||||
|
|
Loading…
Reference in a new issue