Download Now
Forums

    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

    NameKindLine
    GrabAccelerationconstant38
    PhysicsStepconstant35
    StudioHeightconstant33
    StudioWidthconstant32
    TPhysicsSceneclass58
    DoMouseDownprocedure102
    DoMouseMoveprocedure103
    DoMouseUpprocedure104
    DrawCustomBodyfunction84
    DrawCustomJointfunction86
    DrawCustomShapefunction85
    DrawPhysicsprocedure90
    Finalizeprocedure97
    GenerateStudioWallsprocedure82
    Initializeprocedure96
    Lockprocedure113
    PointToStudiofunction76
    ReleaseGrabprocedure111
    ResetSpaceprocedure108
    ScaleToStudioprocedure78
    ShapeNearPointfunction80
    Simulateprocedure73
    Stepprocedure101
    StepIntervalfunction99
    Unlockprocedure115
    GrabBodiesproperty93
    GrabCenteredproperty94
    GrabJointproperty92
    Pausedproperty117
    Spaceproperty91