Skip to main content

Crate jelly_physics

Crate jelly_physics 

Source
Expand description

2D soft body physics engine based on point masses.

Bodies are rings of point masses joined by force-based springs; ropes are chains of point masses joined by position-based distance constraints (Rope).

Structs§

Aabb
Axis-aligned bounding box.
Body
A soft body: a closed ring of consecutive points in World::points plus its derived state.
BodyId
Stable handle of a Body in World::bodies. It stays valid when other bodies are removed.
BodyJoint
A spring tying a chassis point to a body’s center.
Contact
A point of one body found inside another body, with the data needed to push it out.
Grab
State (World::grab) of the point currently held by the mouse (or touch).
Material
How two materials behave when bodies made of them touch.
PointMass
Everything in JellyPhysics is made of point masses: a position, a velocity, a force and a mass. No rotation, no shape. Forces are summed each step.
Rope
A chain of point masses joined by position-based distance constraints.
RopeAnchor
Ties a rope node to an existing point in World::points, usually a point of a Body.
RopeId
Stable handle of a Rope in World::ropes. It stays valid when other ropes are removed.
Settings
Simulation parameters and settings
Spring
A soft body is PointMass values joined by Springs. Each spring wants to stay at its rest length: stretch it and it pulls the ends together, squash it and it pushes them apart. A damper slows the ends’ relative motion along the spring so it doesn’t wobble forever.
World
The simulation world: points, springs, bodies, contacts, joints and settings.

Functions§

closest_edge
Finds the ring edge closest to point and returns it as a Contact (with point left unset). first is the index of the ring’s first point in World::points.
make_rectangle
Builds an axis-aligned rectangle (4 vertices) centered at center with size w x h.
make_regular_polygon
Builds a regular polygon approximating a circle centered at center with radius r. n is clamped to at least 3 so the result is always a valid polygon.
make_rounded_rectangle
Builds a rectangle whose corners are beveled (cropped) at 45 degrees, i.e. an octagon, centered at center with size w x h. The cut size scales with the shorter side.
mean_velocity
Returns the mean PointMass::velocity of the points.
nearest_point
Returns the index of the nearest World::points entry to at within max_dist, or None if none is close enough.
point_in_polygon
Returns true if point is inside the polygon formed by the ring of PointMass values (ray casting).
polygon_area
Signed area of the polygon (shoelace formula); positive for counter-clockwise order.
spring_force
Returns the force on a.