Skip to main content

Conceptual Understanding

Before diving into the api, it is important to know how the library really comes together and do what its supposed to do. The library uses methods of Verlet Integration and Convex Hull Collisions (Separating Axis Theorem) to simulate physics. I have detailed the math and working of both of those methods on the Devforum and Github with code snippets! If you'd want to explore more about them, go through the following links!

Back to Nature2D. The library is divided into different segments. The core, which is the Engine. The physics based classes, which are the RigidBodies, Constraints and Points, utilities which consists of non inclusive modules to help render constraints and points on the screen and global constant values.

Engine

The Engine or the core of the library handles all the RigidBodies, constraints and points. It's responsible for the simulation of these elements and handling all tasks related to the library. Physics is simulated at a fixed rate of 60hz with the following structure of tasks:

  • Update rigid bodies.
  • Detect rigid body collisions.
    • Process collision response with given number of collision iterations.
  • Update points.
  • Update constraints.
  • Render rigid bodies.
  • Render points.
  • Render constraints.

Point

Points are what make the rigid bodies behave like real world entities! Points are responsible for the movement of the RigidBodies and Constraints! These points have a velocity and acceleration that make them move around a canvas! These points are not rendered on the screen by default and it is advisable to keep it that way. Points don't need to be created manually unless creating custom Constraints. By default points are handled by the core (Engine) itself!

Constraint

Constraints keep two points together in place and maintain uniform distance between the two! Constraints and Points together join to keep a RigidBody in place hence making both Points and Constraints a vital part of the library. Custom constraints such as Ropes, Rods, Bridges and chains can also be made! Points of two rigid bodies can be connected with constraints, two individual points can also be connected with constraints to form Ropes etc. Nature2D supports 3 kinds of constraints as of now - Ropes, Rods and Springs.

RigidBody

RigidBodies are formed by Constraints, Points and UI Elements! These RigidBodies are highly flexible to meet all your use cases! RigidBodies can be customized and custom physical properties can be defined for them. By default they abide by the universal physical properties of the engine.


This introduction should give you a brief understanding of how everything works. Continue reading furthur by clicking links above or exploring the API, examples and placefiles!