![]() |
Quark Physics
1.0
2D Rigid and Soft Body Physics Engine
|
In QuarkPhysics, there is a QWorld object that manages all objects and ensures the continuation of all physics steps. You must first create a world. You can also configure this world and set its properties.
To update a physics step, you simply need to use the QWorld::Update method.
For more information you can refer to the QWorld class documentation.
To create a rigid body for our physics world, we need to create a QRigidBody object, which inherits from the QBody class. Additionally, to give the rigid body shape, we need to create a QMesh object and attach it to the body. Finally, we add the created QRigidBody object to our physics world using the QWorld::AddBody method.
Just like with rigid bodies, to create a soft body, we need to create a QSoftBody object. Then, we need to create a QMesh that defines the shape of our soft body and add it to the QSoftBody object. Finally, we add our new soft body to the physics world, i.e., QWorld.
For rigid body objects, only particles and the outer edges connecting them are sufficient. However, for soft body structures, you need additional internal particles and spring connections. In the QMesh class, while creating primitive shapes such as quads or regular polygons, you can form grid networks with spring connections inside these shapes. This explains why the class is named 'mesh' instead of a more conventional 'shape'-derived name.
Of course, the QMesh class not only provides methods for generating primitive shapes and their predefined network structures but also offers functionality for creating custom mesh structures. You can add particles with specific radii, define collision polygons, and add spring connections between particles. Additionally, you can create complex mesh files in JSON format using tools like QMesh Editor and define them in your QMesh classes at runtime.
If you want to connect two rigid bodies with various constraints, you can use QJoint objects. You should add the configured QJoint object to the physics world, i.e., QWorld.
QJoint objects not only connect two rigid bodies, but you can also set one of the bodies to nullptr and configure the anchor position of the joint to a position in the world, thereby connecting a rigid body to this point in space.
And yes, in the project's example scenes, you move rigid bodies by holding them with the mouse in this way.
Imagine you have two independent soft bodies and you want to create spring connections between them. QSpring allows you to apply distance constraints between two particles. QSpring objects are also used in the spring connections of soft bodies themselves. In short, QSpring is the only class that creates spring connections between particles. To use it, you first need to create a QSpring object and then add it to our physics world
If you want to apply a distance constraint between a particle and a point in space, similar to QJoint, you should create a QParticle, place it at a point in the world, and show it as one of the defined particles.
A good example of this is in the project's example scenes, where you drag the particles of soft bodies by holding them with the mouse.
Every object you add to the physics world, i.e., QWorld (such as QBody, QJoint, QSpring), will be deleted with its destructor when the QWorld object is destroyed. To safely remove objects added to the QWorld, use the QWorld::RemoveBody, QWorld::RemoveJoint, QWorld::RemoveSpring methods.
With this page, you have gained basic knowledge about using QuarkPhysics. For more details, you can review the API documentation, check the source code of the example scenes, or ask your questions on GitHub.