Write a physics engine lesson plan
Build a 2D physics engine in C++ on an ESP32-C3: vectors, time steps, integration, collisions, springs, friction and rigid bodies, ending in a tilt-driven marble sandbox.
Objectives and materials
By the end, students can
- Vectors, fixed time steps, and why the order of two lines keeps a moon in orbit.
- Impulses that keep momentum, and the force law behind every rope and shock absorber.
- Stick and slip on a rolling deck, then bodies that turn as well as move.
- An MPU6050 tips a tray of marbles: the whole engine in one loop.
Materials for the whole unit
- Accelerometer and gyroscope, MPU6050
- ESP32-C3-DevKitM-1
- Full-size breadboard
- TFT display, 240x320
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Motion
Vectors, fixed time steps, and why the order of two lines keeps a moon in orbit.
| Lesson | Time | What students do |
|---|---|---|
| Vectors and time stepsWrite a 2D vector type with real C++ operators, move a probe through space one fixed time step at a time, and keep physics on its own clock. | 45 min |
|
| IntegrationDrop a ball and put two moons in orbit, and watch the order of two lines decide between a stable orbit and a moon spiraling off into space. | 55 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- TFT display, 240x320
Check for understanding
Each student finishes "Integration" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Smaller steps".
Hits and springs
Impulses that keep momentum, and the force law behind every rope and shock absorber.
| Lesson | Time | What students do |
|---|---|---|
| CollisionsDetect overlapping asteroids, push them apart, and bounce them with an impulse that keeps momentum exactly, and energy as much as restitution allows. | 45 min |
|
| SpringsHooke's law and a damper: measure a spring's period against theory, find critical damping, and hang a swinging tether of eight masses from a station. | 55 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- TFT display, 240x320
Check for understanding
Each student finishes "Springs" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Critical damping".
Friction and rigid bodies
Stick and slip on a rolling deck, then bodies that turn as well as move.
| Lesson | Time | What students do |
|---|---|---|
| FrictionSlide a crate to a stop, find the angle where static friction lets go, and ride a cargo crate on the deck of a ship rolling in a swell. | 55 min |
|
| Rigid bodiesGive a body an angle and a spin: moment of inertia, torque from an off-center kick, and contact impulses that make a solar panel tumble and settle. | 45 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- TFT display, 240x320
Check for understanding
Each student finishes "Rigid bodies" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Move the kick".
Boss
An MPU6050 tips a tray of marbles: the whole engine in one loop.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a tilt-driven sandboxTilt the board and a tray of marbles rolls downhill: an MPU6050 sets gravity, and integration, collisions, restitution and rolling do the rest. | 55 min |
|
Materials
- Accelerometer and gyroscope, MPU6050
- ESP32-C3-DevKitM-1
- Full-size breadboard
- TFT display, 240x320
Check for understanding
Each student finishes "Boss: a tilt-driven sandbox" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "More marbles".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.