-
Notifications
You must be signed in to change notification settings - Fork 5
Home
There are three distinct layers of components that make up the SFPhysics system.
- The lowest layer are the bounds objects. Bounds objects have a location and a size and are capable of calculating collision results with other bounds object. There are two types of bounds objects defined by SFPhysics: Circular Bounds and Axis Aligned Bounding Boxes (AABB). Locations are always placed at the center of the bounds.
- The next layer is the Physics Body. A physics body wraps a bounds object and adds a current velocity of motion, a collision restitution (how much force is returned in a collision) a mass and a way to apply an impulse to the object. A Physics Body may be dynamic or static. Static merely means that, in a collision, the object has effectively infinite mass and will not move. (What Unity 3D calls a "kinematic" object.) Static objects may still be moved freely by external code.
- The highest level in the physics system is the World. The world holds the list of all physics bodies currently active and handles movement and collision of those bodies.
AABBs and BoundingCircles as positioned by setting the screen position of their center, which is their center of mass. SFML however psoitions objects based on their top left corner. In order to provide a uniform positioning system, the SFML drawables are wrapped in objects that expose a "setCenter" method for positioning. This is converted to top left coordinates internally.
The "center" of a CenteredCircle and CenteredRectangle is the pixel at their geometric center. The center of a Sprite is the pixel at the center of the texture rectangle that is being displayed(it may be the whole texture or only a sub portion. See SFML docs for more about that.) The "center" of a CenteredConvexPloygon is currently the local origin (0,0). This may be changed in the future to a true center of mass.
A Physics Shape object wraps a centered drawable and a physics body together and keeps the SFML object tracking the location of its bounds. There are Physics Shape objects for all of the SFML primitive drawables: PhysicsRectangle, PhysicsCircle, PhysicsSprite and PhysicsConvexPolygon. Physics Shapes are the highest level of the API and what developers are most likely to directly interface with. A Physics Shape is placed in the world by using its PhysicsShape::getBody() method to get a PhysicsBody to submit to the World for processing. A Physics shape is drawn by using its PhysicsShape::getShape() method to retrieve an SFML drawable.
IMPORTANT: Physics Shapes have their own setSize() and setCenter() calls. It is important that the programmer uses these to manually adjust the size or position of the physics body and centered shape together, and does not try to use the position and size setting methods on either the physics body or centered shape directly unless the intent is to desynchronize them.