Reference Codebot.Render.Scenes.Physics.pas
Part of the Codebot Render package
The Codebot.Render.Scenes.Physics unit gives you TPhysicsScene, a widget scene that runs a Chipmunk2D space, which you reach through its Space property. The space is stepped every PhysicsStep seconds on the step thread of the host, which starts after your scene is created, so you can build your world in Initialize without locking it.
Physics is simulated in studio coordinates, a fixed area of 1920 by 1080 that is scaled to fill your scene, so your simulation behaves the same at any size. GenerateStudioWalls adds walls around the studio, PointToStudio converts a point of the scene, and DrawPhysics draws the shapes, bodies, and joints. You can override DrawCustomBody, DrawCustomShape, and DrawCustomJoint to draw some of them yourself. When GrabBodies is True, the user can drag bodies with the left mouse button.
The space is shared by the step thread and the render thread. Override Simulate to run your own code on each step with the space locked, and outside of Simulate wrap any code that uses the space in Lock and Unlock. DrawPhysics and the mouse handling do this for you. Paused stops the simulation, and ResetSpace starts over with an empty space.
Items 30 items
| Name | Kind | Line |
|---|---|---|
| GrabAcceleration | constant | 38 |
| PhysicsStep | constant | 35 |
| StudioHeight | constant | 33 |
| StudioWidth | constant | 32 |
| TPhysicsScene | class | 58 |
| DoMouseDown | procedure | 102 |
| DoMouseMove | procedure | 103 |
| DoMouseUp | procedure | 104 |
| DrawCustomBody | function | 84 |
| DrawCustomJoint | function | 86 |
| DrawCustomShape | function | 85 |
| DrawPhysics | procedure | 90 |
| Finalize | procedure | 97 |
| GenerateStudioWalls | procedure | 82 |
| Initialize | procedure | 96 |
| Lock | procedure | 113 |
| PointToStudio | function | 76 |
| ReleaseGrab | procedure | 111 |
| ResetSpace | procedure | 108 |
| ScaleToStudio | procedure | 78 |
| ShapeNearPoint | function | 80 |
| Simulate | procedure | 73 |
| Step | procedure | 101 |
| StepInterval | function | 99 |
| Unlock | procedure | 115 |
| GrabBodies | property | 93 |
| GrabCentered | property | 94 |
| GrabJoint | property | 92 |
| Paused | property | 117 |
| Space | property | 91 |