
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.
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.