49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
/**
|
|
* Header file defining a ball.
|
|
* 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,
|
|
* 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.
|
|
**/
|
|
#pragma once
|
|
#include <cstddef>
|
|
#include "spheroid.hpp"
|
|
#include "FlatGround.hpp"
|
|
#include "PerlinGround.hpp"
|
|
|
|
#define G_CTE 9.81
|
|
|
|
class Ball {
|
|
private:
|
|
Point Center;
|
|
Spheroid surface;
|
|
const Ground* ground;
|
|
double radius;
|
|
double init_h;
|
|
double min_height;
|
|
size_t bounce_number;
|
|
double crt_time;
|
|
double A, B, U, T; // Coefficients for the physical model.
|
|
double v_x, v_z;
|
|
void _compute_pos(double dt);
|
|
void _compute_v_x(Point normal);
|
|
void _compute_v_z(Point normal);
|
|
void _compute_A_n();
|
|
void _compute_B_n();
|
|
void _compute_U_n();
|
|
void _compute_T_n();
|
|
public:
|
|
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;}
|
|
double accessT() const { return T;}
|
|
double access_crt_time() const { return crt_time;}
|
|
Spheroid* get_surface() { return &surface; }
|
|
};
|
|
|
|
std::ostream& operator << (std::ostream &out, Ball const& data);
|