
Explore time sampling and graphics theory for simulating a bouncing ball under gravity, including coefficient of restitution 0.8 and velocity updates in SDL rendering on an 800 by 600 screen.
Compute velocity and displacement of a ball under gravity in C++ using coefficient of restitution, dt, and floor distance; implement up and down with a switch for SDL rendering.
Refactor the program into an object-oriented ball class with center position, radius, velocity, and an update and draw circle methods for gravity and bounce, using 100 pixels per meter.
Code a 2d ball bounce under gravity in c++ and sdl, using velocity x/y and position x/y in meters, converting to pixels for rendering, and handling wall collisions with restitution.
Learn how to implement ball motion in the XY plane by converting meters to pixels with ppm, updating center coordinates, and enforcing wall boundaries with restitution until the ball settles.
Solving interesting problems and implementing them in C++ is a good way to learn the C++ language.
In this course, we understand the Physics and theory behind the motion of the Ball falling under gravity. We understand the equations for velocity and displacement of the ball at different intervals of time. Then we programmatically sample the time and render the position of the ball, calculated using above equations.
We use SDL graphics library to visualize the simulation.
Structure of the course:
1. Theory and Physics behind Ball fall and bounce under gravity
2. Program to calculate velocity and displacement of the ball
3. SDL graphics programming in C++
4. Final simulation program in C++
Different C++ & programming concepts used during software development:
classes, public & private variables, functions, constructors, compilation and running with g++, SDL graphics library (-lSDL2)
SDL graphics functions used: SDL_CreateWindow, SDL_CreateRenderer, SDL_SetRenderDrawColor, SDL_RenderClear, SDL_RenderPresent, etc. draw circle using 'midpoint circle algorithm'.
Future enhancements Possible: Multiple balls falling under gravity using multiple threads in C++, option to change the gravity to simulate different planets, Ball falling at an angle.
Applications of simulation: educational tool to learn physics or mathematics concepts visually, Product design or engineering R&D in aerodynamic, fluid dynamics, etc.