P2 Introduction
P2 is a JavaScript-based HTML5 2D physics engine, like box2d, nape and other physical engines, P2 integrates a variety of complex physical formulas and algorithms, can help us easily to achieve collision, rebound and other physical phenomena simulation.
Learning materials
P2 API
Understanding HTML5 Physics Engine P2
Element Introduction
World, this is a simulated physical world in which all rigid bodies and constraints are created and put in.
Body (rigid body), which is an infinitely hard object. Therefore, the distance between any two points on this object is considered to be fixed. The body (rigid body) has its own parameters for setting the position, mass, and speed, and the shape of the rigid body is determined by the shapes created by shape.
Shape, a geometric shape, can be a rectangle, a circle, and so on.
Constraint (constraint), Constraint is a physical connector that controls the degree of freedom of a rigid body. In the 3d World, objects have 6 degrees of freedom (3 translational coordinates and 3 rotational coordinates). In the 2d world, objects have only 3 degrees of freedom (2 translational coordinates and one rotational coordinate). As we all know, the human world is 3d, so our home door should have 6 degrees of freedom, but because the door on one side by the door hinge fixed on the wall, it lost another 5 degrees of freedom, can only follow the door hinge this axis rotation. The door hinge is equivalent to a constraint (constraint).
Contact constraint, which is a special constraint that prevents infiltration overlap between rigid bodies and simulates friction and elasticity. You do not need to create this constraint and the system will automatically create it.
Solver (Solver), the Solver (solver) of the physical world is dedicated to handling constraints.
(not to be continued ...) )
P2.js Physics Engine Learning