A (not so) advanced physics engine created for the love of the game (and to cheat in physics class). It’s coded in C++ so it should be efficient-ish. This is also my first ever C++ project.
A (not so) advanced physics engine created for the love of the game (and to cheat in physics class). It’s coded in C++ so it should be efficient-ish. This is also my first ever C++ project.
I got collision to work!!!!!! After fighting with my terrible pixel → meter & meter → pixel conversion code, I finally got object-surface collision working. I started adding friction as well. Once friction works, I’m planning on trying to allow for sloped surfaces and rigid body tilts. I might take a break from normal Newtonian physics and try some space physics (or maybe fluid dynamics :0). I still need to decide if I want to make this into a physics library or just a simulator.
Log in to leave a comment
I setup the CollisionManager class to hold a list of all the rigid bodies and surfaces, and detect collision. I currently have an AABB (axis-aligned bounding box) overlap check to detect when rectangles overlap. I will improve this later so rigid bodies can rotate. I updated the physics calculation to scale correctly to pixels. I also added a material system to store restitution and friction. I left a nod to my physics teacher (CHUCK_D_CUBEEEEEEE).
Log in to leave a comment
I set up the backbone of the engine. I coded a Vec2 struct that can do the needed vector math (+, -, *, /, dot product, etc.), and used that to create a RigidBody2d class. The class allowed for the simulation of simple forces and velocities. I did not have any way to display this, so after failing to use OpenGL, I switched to the simpler SFML library. With it, I coded a RigidBodyRectangle to handle display (and soon collision detection). After that was working, I tested different simulations. I realized that to add more features, I needed surfaces and collision, so I added Surface2d and SurfaceRectangle classes. These are the same as RigidBody2d’s, except they don’t have velocity or netForce. I also setup a m/s -> px/s scale and delta time.
Log in to leave a comment