Many many changes
This commit is contained in:
parent
538930bd71
commit
083bc3c654
15
Ball.cpp
15
Ball.cpp
|
@ -25,20 +25,22 @@ Ball::Ball(const Point& _center, const Ground* _ground, double _min_height,
|
|||
}
|
||||
|
||||
void Ball::_compute_pos(double dt) {
|
||||
double height = (*ground)(Center.x, Center.z);
|
||||
if (bouncing) {
|
||||
Center.y = fmax(
|
||||
min_height,
|
||||
A + B * crt_time - (G_CTE / 2) * crt_time * crt_time + min_height
|
||||
min_height + height,
|
||||
A + B * crt_time - (G_CTE / 2) * crt_time * crt_time + min_height + height
|
||||
);
|
||||
} else {
|
||||
double n_time = crt_time - stop_bouncing;
|
||||
double min_rad = radius - min_height;
|
||||
Center.y = min_height + ((min_rad * (1.0 - exp(-n_time)) + min_rad )/2.) +
|
||||
(min_rad - ((min_rad* (1- exp(-n_time)) + min_rad)/2.)) * sin(5. *
|
||||
n_time);
|
||||
v_x *= 0.8;
|
||||
v_z *= 0.8;
|
||||
Center.y = height + min_height + ((min_rad * (1.0 - exp(-n_time)) + min_rad )/2.) +
|
||||
(min_rad - ((min_rad* (1- exp(-n_time)) + min_rad)/2.)) * sin(5. *
|
||||
n_time);
|
||||
}
|
||||
std::cout << (*this) << "\n";
|
||||
Center.x += dt * v_x;
|
||||
Center.z += dt * v_z;
|
||||
surface.update_center_pos(Center);
|
||||
|
@ -72,11 +74,12 @@ void Ball::_compute_v_z(Point normal) {
|
|||
}
|
||||
|
||||
void Ball::update_pos(double dt) {
|
||||
//double height = (*ground)(Center.x, Center.z);
|
||||
crt_time += dt;
|
||||
if ((bouncing) && (crt_time >= T)) {
|
||||
double old_t = T;
|
||||
double max_t;
|
||||
Point normal = surface.getNormalVector();
|
||||
Point normal = (*ground).get_normal(Center.x, Center.z);
|
||||
bounce_number += 1;
|
||||
_compute_U_n();
|
||||
_compute_A_n();
|
||||
|
|
|
@ -4,3 +4,7 @@
|
|||
double FlatGround::operator() (double, double) const {
|
||||
return 0. ;
|
||||
}
|
||||
|
||||
Point FlatGround::get_normal(double, double) const {
|
||||
return Point(0, 1, 0);
|
||||
}
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
#include "Ground.hpp"
|
||||
|
||||
class FlatGround : public Ground {
|
||||
double operator() (double, double) const;
|
||||
public:
|
||||
double operator() (double, double) const;
|
||||
Point get_normal(double x, double y) const;
|
||||
};
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
class Ground {
|
||||
public:
|
||||
virtual double operator() (double, double) const = 0;
|
||||
virtual Point get_normal(double x, double y) const = 0;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "GL/gl.h"
|
||||
|
||||
#include "GL/gl.h"
|
||||
|
||||
MarchingCubes::MarchingCubes(
|
||||
const ImplicitSurface& surface,
|
||||
const Cuboid& box,
|
||||
|
|
|
@ -7,3 +7,8 @@ double PerlinGround::operator() (double x, double z) const {
|
|||
return surface.noise(x, z);
|
||||
}
|
||||
|
||||
|
||||
Point PerlinGround::get_normal(double x, double z) const {
|
||||
const Point pt(x, surface.noise(x, z), z);
|
||||
return surface.normal_at(pt);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ class PerlinGround : public Ground {
|
|||
PerlinGround();
|
||||
PerlinGround(unsigned int seed);
|
||||
double operator() (double, double) const;
|
||||
Point get_normal(double x, double y) const;
|
||||
private:
|
||||
PerlinNoise surface;
|
||||
};
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
FlatGround* flat = new FlatGround();
|
||||
PerlinGround* flat = new PerlinGround();
|
||||
GlutRender& render = GlutRender::get_instance();
|
||||
render.init(&argc, argv, 640, 480, "Bouncing stuff");
|
||||
|
||||
|
|
11
spheroid.cpp
11
spheroid.cpp
|
@ -6,7 +6,7 @@
|
|||
#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),
|
||||
ImplicitSurface(_center), min_p(_min_p),
|
||||
init_p(_p), p(_p), q(_q), stiffness(0)
|
||||
{
|
||||
_compute_volume();
|
||||
|
@ -44,15 +44,6 @@ Cuboid Spheroid::max_bounding_box() const {
|
|||
return Cuboid(_bd1, _bd2);
|
||||
}
|
||||
|
||||
void Spheroid::check_perlin_collision(PerlinNoise perlin) {
|
||||
double height = perlin.noise(center.x, center.z);
|
||||
if ((center.y - p) <= height) {
|
||||
p = fmin(init_p, center.z- height );
|
||||
normal_vector = perlin.normal_vector(center.x, center.z);
|
||||
update_radius();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double Spheroid::operator() (double _x, double _y, double _z) const {
|
||||
return (pow(_x, 2) / pow(q, 2)
|
||||
|
|
|
@ -21,7 +21,6 @@ class Spheroid : public ImplicitSurface {
|
|||
void check_ground_collision(const Ground* ground);
|
||||
Cuboid max_bounding_box() const;
|
||||
void check_perlin_collision(PerlinNoise perlin);
|
||||
Point getNormalVector() const { return normal_vector;}
|
||||
double operator() (double _x, double _y, double _z) const;
|
||||
|
||||
virtual Point location_hint() const;
|
||||
|
@ -32,7 +31,6 @@ class Spheroid : public ImplicitSurface {
|
|||
* V is the volume. Extremely useful to have a constant volume in the
|
||||
* ball
|
||||
**/
|
||||
Point normal_vector;
|
||||
double min_p, init_p, p, q;
|
||||
size_t stiffness;
|
||||
double V;
|
||||
|
|
Loading…
Reference in New Issue