diff --git a/main_bounce.cpp b/main_bounce.cpp index c4fc771..3edefc1 100644 --- a/main_bounce.cpp +++ b/main_bounce.cpp @@ -12,9 +12,14 @@ int main(int argc, char** argv) { GlutRender& render = GlutRender::get_instance(); render.init(&argc, argv, 640, 480, "Bouncing stuff"); - Ball ball(Point(0, 0, 10), 0, .25, 1, 1); + Ball ball(Point(0, 10, 0), 0.25, 0.25, 0, 1, 1); + + Cuboid bbox = ball.get_surface()->max_bounding_box(); + printf("%.2lf %.2lf %.2lf | %.2lf %.2lf %.2lf\n", + bbox.low(0), bbox.low(1), bbox.low(2), + bbox.high(0), bbox.high(1), bbox.high(2)); render.add_surface(ball.get_surface(), - Cuboid(Point(-2, -2, -2), Point(2, 2, 2))); + ball.get_surface()->max_bounding_box()); render.set_idle_func(periodic_update); init_periodic_static(&ball); diff --git a/periodic_updates.cpp b/periodic_updates.cpp index b38b54e..e29fc40 100644 --- a/periodic_updates.cpp +++ b/periodic_updates.cpp @@ -1,24 +1,38 @@ #include "periodic_updates.hpp" #include +#include #include static Ball* _ball = nullptr; -static clock_t _last_time = 0; - -double time_of_clocks(clock_t time) { - return ((double)time) / ((double)CLOCKS_PER_SEC); -} +static std::chrono::time_point + _last_time, _init_clocks; void init_periodic_static(Ball* ball) { - _last_time = clock(); + _last_time = std::chrono::steady_clock::now(); + _init_clocks = std::chrono::steady_clock::now(); _ball = ball; } -void periodic_update() { - clock_t now = clock(); - _ball->update_pos(time_of_clocks(now - _last_time)); - _last_time = now; +double ellapsed_double( + std::chrono::time_point beg, + std::chrono::time_point end) +{ + std::chrono::duration ellapsed_db = end - beg; + return ellapsed_db.count(); +} +void periodic_update() { + auto now = std::chrono::steady_clock::now(); + _ball->update_pos(ellapsed_double(_last_time, now)); + + fprintf(stderr, "dt = %lf, tot = %lf; center: %.2lf, %.2lf, %.2lf\n", + ellapsed_double(_last_time, now), + ellapsed_double(_init_clocks, now), + _ball->getCenter().x, + _ball->getCenter().y, + _ball->getCenter().z); + + _last_time = now; glutPostRedisplay(); } diff --git a/render/GlutRender.cpp b/render/GlutRender.cpp index 7c05f27..cedf0c5 100644 --- a/render/GlutRender.cpp +++ b/render/GlutRender.cpp @@ -103,8 +103,8 @@ void GlutRender::display() { // Camera position and orientation glLoadIdentity(); //glTranslatef(1., 2., -10.); - gluLookAt(0, 0, -10, - 0, 0, 10, + gluLookAt(0, 5, -20, + 0, 5, 0, 0, 1, 0); for(Mesh* mesh: meshes) { diff --git a/spheroid.cpp b/spheroid.cpp index f766838..65b5c0c 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -52,7 +52,7 @@ void Spheroid::check_vertical_plan_collision(double& abscissa) { } Cuboid Spheroid::max_bounding_box() const { - double max_radius = sqrt((3/4) * V / PI / min_p); + double max_radius = sqrt((3./4.) * V / PI / min_p); double max_height = init_p; Point _bd1(max_radius, max_radius, max_height); Point _bd2(-max_radius, -max_radius, -max_height);