mpri-graphics-project/Ball.hpp

51 lines
1.6 KiB
C++
Raw Normal View History

2018-02-07 15:08:16 +01:00
/**
* 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
2018-02-11 22:42:15 +01:00
* 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.
2018-02-07 15:08:16 +01:00
**/
2018-02-12 01:11:23 +01:00
#pragma once
2018-02-07 15:08:16 +01:00
#include <cstddef>
#include "spheroid.hpp"
2018-02-13 17:05:49 +01:00
#include "FlatGround.hpp"
#include "PerlinGround.hpp"
2018-02-07 15:08:16 +01:00
#define G_CTE 9.81
class Ball {
private:
Point Center;
Spheroid surface;
2018-02-13 17:05:49 +01:00
const Ground* ground;
double radius;
2018-02-07 15:08:16 +01:00
double init_h;
double min_height;
2018-02-07 15:08:16 +01:00
size_t bounce_number;
double crt_time;
double A, B, U, T; // Coefficients for the physical model.
2018-02-12 18:32:58 +01:00
double v_x, v_z;
2018-02-11 22:42:15 +01:00
void _compute_pos(double dt);
2018-02-13 21:06:44 +01:00
void _compute_parameters();
void _compute_v_x(Point normal);
2018-02-12 18:32:58 +01:00
void _compute_v_z(Point normal);
2018-02-07 15:08:16 +01:00
void _compute_A_n();
void _compute_B_n();
void _compute_U_n();
void _compute_T_n();
public:
2018-02-13 17:05:49 +01:00
Ball(const Point& _center, const Ground* ground, double _min_height, double _v_x,
2018-02-12 18:45:35 +01:00
double _v_z, double p, double q);
2018-02-07 15:08:16 +01:00
void update_pos(double dt);
2018-02-12 01:11:23 +01:00
Point getCenter() const {return Center;}
2018-02-12 10:21:49 +01:00
double accessT() const { return T;}
double access_crt_time() const { return crt_time;}
2018-02-12 18:40:05 +01:00
Spheroid* get_surface() { return &surface; }
2018-02-07 15:08:16 +01:00
};
2018-02-12 01:11:23 +01:00
std::ostream& operator << (std::ostream &out, Ball const& data);