Download Now

    Reference Codebot.Physics.pas

    Part of the Codebot Render package

    Codebot.Physics assists in understanding and effectively using the Chipmunk2D physics library.

    It exposes the flat Chipmunk2D C style API as a collection of record types. These records directly correspond to the pointer types used by Chipmunk2D, such as cpSpace, cpBody, cpShape, cpConstraint, and cpArbiter. The records convert to and from the Chipmunk2D pointer types implicitly and can be freely interchanged with the functions of Codebot.Interop.Chipmunk2D without penalty.

    Using records in place of traditional class wrappers benefits the user in the following ways. Internally Chipmunk2D dynamically creates and manipulates both the state and relationships between its data structures. The records in this unit allow Chipmunk2D to manage all these things without duplicating them in Pascal.

    Additionally, records group logical concepts into distinct types. Most of the properties and methods on the records map neatly to the Chipmunk2D C style API. There are, however, some enhancements such as for...in enumerators which have been added to make programming more convenient.

    Consider the following Chipmunk2D C style API to create a circle body:

    cpBody* body = cpSpaceAddBody(space, cpBodyNew(0, 0));
    cpShape* circle = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
    cpShapeSetDensity(circle, 1);
    

    Using records this becomes:

    Space.NewBody.NewCircle(Radius);
    

    The above code follows exactly the same steps as the C approach, but it greatly simplifies the task of creating a viable circle body. It also does this without creating additional Pascal objects to intermediate this or other tasks. This style of simplification is repeated throughout this unit.

    As a further example, to list all shapes in a space you may write:

    for Shape in Space.Shapes do
    

    This is much easier to use when compared to the more cumbersome enumeration callbacks forced upon the user by the C API.

    Floating point values are single precision and vectors and matrices are the TVec2 and TMatrix2x3 types from Codebot.Geometry, the same as the static Chipmunk2D library linked by Codebot.Interop.Chipmunk2D.

    The Codebot.Physics unit wraps the Chipmunk2D physics library in records that are easier to use from Pascal.

    • TSpace is the simulated world.
    • TBody is a rigid body within a space.
    • TShape gives a body its shape, and comes in circle, segment, and polygon kinds.
    • TJoint connects two bodies, and comes in ten kinds.
    • TArbiter describes a collision between two shapes.

    Each record is the same pointer that Chipmunk2D uses, so the records convert freely to and from the routines of Codebot.Interop.Chipmunk2D, and nothing is duplicated in Pascal. The records add properties, methods such as Space.NewBody.NewCircle, and for in enumerators.

    The unit also includes routines that compute the moment, area, and centroid of shapes, and that build convex hulls and polylines.

    Items 424 items

    NameKindLine
    AreaForCirclefunction106
    AreaForPolygonfunction110
    AreaForSegmentfunction107
    bodyDynamicconstant133
    bodyKinematicconstant134
    bodyStaticconstant135
    BoolFlagsconstant80
    CentroidForPolygonfunction112
    ClosestPointOnSegmentfunction117
    collideGrabconstant87
    ConvexHullfunction115
    FilterAllconstant83
    MaskAllconstant81
    MaskToStrfunction90
    MatrixIdentityconstant79
    MomentForBoxfunction104, 105
    MomentForCirclefunction98, 99
    MomentForPolygonfunction101, 102
    MomentForSegmentfunction100
    NewSpacefunction1438
    shapeCircleconstant124
    shapePolygonconstant126
    shapeSegmentconstant125
    StrToMaskfunction92
    TArbiterrecord824
    Reffield826
    CallWildcardBeginAfunction863
    CallWildcardBeginBfunction864
    CallWildcardPostSolveAprocedure867
    CallWildcardPostSolveBprocedure868
    CallWildcardPreSolveAfunction865
    CallWildcardPreSolveBfunction866
    CallWildcardSeparateAprocedure869
    CallWildcardSeparateBprocedure870
    GetBodiesprocedure856
    GetShapesprocedure854
    Ignorefunction852
    Implicitoperator827, 828
    IsFirstContactfunction858
    IsNilfunction849
    IsRemovalfunction860
    ContactPointSetproperty882
    Countproperty884
    Depthproperty891
    Frictionproperty876
    Normalproperty886
    PointAproperty888
    PointBproperty889
    Restitutionproperty873
    SurfaceVelocityproperty878
    TotalImpulseproperty894
    TotalKineticEnergyproperty896
    UserDataproperty880
    TArbiterMethodprocedural900
    TBitmaskalias70
    TBodyrecord375
    Reffield377
    ApplyForceAtBodyprocedure457
    ApplyForceAtWorldprocedure455
    ApplyImpulseAtBodyprocedure461
    ApplyImpulseAtWorldprocedure459
    BodyToWorldfunction451
    Equaloperator380
    Freeprocedure418
    Implicitoperator378, 379
    IsNilfunction420
    IsSleepingfunction446
    NewBoxfunction431, 432, 433
    NewCirclefunction425, 427
    NewPolygonfunction435
    NewPolygonRawfunction438
    NewSegmentfunction429
    NotEqualoperator381
    Sleepprocedure442
    SleepWithGroupprocedure444
    UpdatePositionprocedure471
    UpdateVelocityprocedure468
    VelocityAtBodyfunction465
    VelocityAtWorldfunction463
    WakeUpprocedure449
    WorldToBodyfunction453
    Angleproperty490
    AngularVelocityproperty492
    CenterOfGravityproperty481
    Forceproperty488
    Kindproperty474
    KineticEnergyproperty499
    Massproperty477
    Momentproperty479
    Positionproperty483
    PositionFuncproperty503
    Rotationproperty497
    Shapeproperty505
    Shapesproperty509
    Torqueproperty495
    UserDataproperty507
    Velocityproperty485
    VelocityFuncproperty501
    TBodyHelperhelper1408
    EachArbiterprocedure1417, 1418
    Spacefunction1413
    Jointsproperty1420
    TBodyJointEnumeratorrecord809
    Createfunction815
    GetEnumeratorfunction818
    MoveNextfunction816
    Currentproperty817
    TBodyKindalias130
    TBodyShapeEnumeratorrecord360
    Createfunction366
    GetEnumeratorfunction369
    MoveNextfunction367
    Currentproperty368
    TCirclerecord146
    Reffield148
    Freeprocedure160
    Implicitoperator149, 150, 151, 152
    IsNilfunction162
    Reshapeprocedure164
    Offsetproperty168
    Radiusproperty166
    TCircleHelperhelper1286
    Basefunction1289
    TCollisionEventprocedural1152
    TCollisionEventsrecord1155
    OnBeginfield1158
    OnPostSolvefield1163
    OnPreSolvefield1161
    OnSeparatefield1165
    TCollisionFilterEventprocedural1150
    TCollisionHandleralias75
    TCollisionTypealias72
    TDampedRotarySpringJointrecord636
    Reffield638
    Implicitoperator639, 640
    Dampingproperty656
    RestAngleproperty652
    Stiffnessproperty654
    TorqueFuncproperty658
    TDampedRotarySpringJointHelperhelper1360
    Basefunction1363
    TDampedSpringJointrecord602
    Reffield604
    Implicitoperator605, 606
    Dampingproperty629
    ForceFuncproperty631
    PinAproperty622
    PinBproperty623
    RestLengthproperty625
    Stiffnessproperty627
    TDampedSpringJointHelperhelper1352
    Basefunction1355
    TGearJointrecord704
    Reffield706
    Implicitoperator707, 708
    Phaseproperty716
    Ratioproperty718
    TGearJointHelperhelper1384
    Basefunction1387
    TGrooveJointrecord580
    Reffield582
    Implicitoperator583, 584
    GrooveAproperty594
    GrooveBproperty595
    PinBproperty597
    TGrooveJointHelperhelper1344
    Basefunction1347
    TJointrecord738
    Reffield740
    AsDampedRotarySpringfunction778
    AsDampedSpringfunction777
    AsGearfunction781
    AsGroovefunction776
    AsMotorfunction782
    AsPinfunction773
    AsPivotfunction775
    AsRatchetfunction780
    AsRotaryLimitfunction779
    AsSlidefunction774
    Equaloperator743
    Freeprocedure767
    Implicitoperator741, 742
    IsGrabfunction771
    IsNilfunction769
    NotEqualoperator744
    Aproperty786
    Bproperty788
    CollideBodiesproperty790
    ErrorBiasproperty792
    Impulseproperty798
    Kindproperty784
    MaxBiasproperty794
    MaxForceproperty796
    PostSolveproperty802
    PreSolveproperty800
    UserDataproperty804
    TJointHelperhelper1400
    Spacefunction1403
    TJointKindenum140
    jointPinenum value140
    jointSlideenum value140
    jointPivotenum value140
    jointGrooveenum value140
    jointDampedSpringenum value140
    jointDampedRotarySpringenum value141
    jointRotaryLimitenum value141
    jointRatchetenum value141
    jointGearenum value141
    jointMotorenum value141
    jointCustomenum value142
    TMarchSampleprocedural1236
    TMotorJointrecord723
    Reffield725
    Implicitoperator726, 727
    Rateproperty733
    TMotorJointHelperhelper1392
    Basefunction1395
    TPinJointrecord514
    Reffield516
    Implicitoperator517, 518
    Distanceproperty531
    PinAproperty528
    PinBproperty529
    TPinJointHelperhelper1320
    Basefunction1323
    TPivotJointrecord561
    Reffield563
    Implicitoperator564, 565
    PinAproperty573
    PinBproperty574
    TPivotJointHelperhelper1336
    Basefunction1339
    TPolygonrecord208
    Reffield210
    Freeprocedure222
    Implicitoperator211, 212, 213, 214
    IsNilfunction224
    Reshapeprocedure226, 228
    ReshapeRawprocedure231
    Borderproperty233
    Vertproperty237
    VertCountproperty235
    TPolygonHelperhelper1302
    Basefunction1305
    TPolylinerecord1178
    Reffield1180
    Copyfunction1197
    Createfunction1191
    Freeprocedure1193
    Implicitoperator1181, 1182
    IsNilfunction1195
    SimplifyCurvesfunction1201
    SimplifyVertexesfunction1205
    ToArrayfunction1209
    ToConvexHullfunction1207
    Closedproperty1217
    Countproperty1211
    Vertproperty1213
    Vertsproperty1215
    TPolylineSetrecord1240
    Reffield1242
    AddSegmentprocedure1275
    ConvexDecompositionfunction1253
    Createfunction1250
    Freeprocedure1270
    GetEnumeratorfunction1277
    Implicitoperator1243, 1244
    IsNilfunction1272
    MarchHardfunction1264, 1267
    MarchSoftfunction1257, 1260
    Countproperty1279
    Lineproperty1281
    TPolylineSetEnumeratorrecord1222
    Createfunction1228
    MoveNextfunction1229
    Currentproperty1230
    TRatchetJointrecord681
    Reffield683
    Implicitoperator684, 685
    Angleproperty695
    Phaseproperty697
    Ratchetproperty699
    TRatchetJointHelperhelper1376
    Basefunction1379
    TRotaryLimitJointrecord663
    Reffield665
    Implicitoperator666, 667
    Maxproperty676
    Minproperty675
    TRotaryLimitJointHelperhelper1368
    Basefunction1371
    TSegmentrecord173
    Reffield175
    Freeprocedure190
    Implicitoperator176, 177, 178, 179
    IsNilfunction192
    Joinprocedure195
    Aproperty199
    Bproperty201
    Borderproperty197
    Normalproperty203
    TSegmentHelperhelper1294
    Basefunction1297
    TShaperecord242
    Reffield244
    AsCirclefunction287
    AsPolygonfunction288
    AsSegmentfunction289
    CacheBBfunction298
    Collidefunction296
    Equaloperator247
    Freeprocedure283
    Implicitoperator245, 246
    IsNilfunction285
    NotEqualoperator248
    PointQueryfunction292
    SegmentQueryfunction294
    Updatefunction300
    Areaproperty314
    BoundingBoxproperty318
    Categoryproperty350
    CenterOfGravityproperty316
    CollisionTypeproperty355
    Densityproperty310
    Elasticityproperty326
    Filterproperty345
    Frictionproperty329
    Groupproperty347
    Kindproperty304
    Maskproperty353
    Massproperty308
    Momentproperty312
    Nextproperty302
    Sensorproperty322
    SurfaceVelocityproperty332
    UserDataproperty334
    TShapeHelperhelper1310
    Bodyfunction1313
    Spacefunction1315
    TShapeKindalias121
    TSlideJointrecord536
    Reffield538
    Implicitoperator539, 540
    Maxproperty556
    Minproperty555
    PinAproperty552
    PinBproperty553
    TSlideJointHelperhelper1328
    Basefunction1331
    TSpacerecord952
    Reffield954
    Addfunction1058, 1059, 1060
    AddCollisionHandlerfunction1005
    AddDefaultCollisionHandlerfunction1009
    AddPostStepCallbackfunction1013
    AddWildcardHandlerfunction1007
    BoxQueryfunction1087
    Containsfunction1067, 1068, 1069
    DebugDrawprocedure1103
    Freeprocedure985
    Implicitoperator955, 956
    IsNilfunction987
    NewBodyfunction1025
    NewDampedRotarySpringfunction1047
    NewDampedSpringfunction1045
    NewGearfunction1051
    NewGroovefunction1044
    NewKinematicBodyfunction1028
    NewMotorfunction1053
    NewPinfunction1040
    NewPivotfunction1042, 1043
    NewRatchetfunction1050
    NewRotaryLimitfunction1049
    NewSlidefunction1041
    NewStaticBodyfunction1031
    PointQueryfunction1075
    PointQueryNearestfunction1078
    ReindexBodyprocedure1096
    ReindexShapeprocedure1095
    ReindexStaticprocedure1094
    ReleaseBodiesprocedure989
    ReleaseJointsprocedure991
    ReleaseObjectsprocedure995
    Removeprocedure1063, 1064, 1065
    SegmentQueryfunction1081
    SegmentQueryFirstfunction1084
    ShapeQueryfunction1089
    Stepprocedure997
    UseSpatialHashprocedure1099
    Bodiesproperty1135
    CollisionBiasproperty1123
    CollisionPersistenceproperty1125
    CollisionSlopproperty1121
    CurrentTimeStepproperty1127
    Dampingproperty1111
    Gravityproperty1113
    Groundproperty1106
    IdleSpeedThresholdproperty1116
    Iterationsproperty1108
    Jointsproperty1140
    Lockedproperty1129
    Shapesproperty1137
    SleepTimeThresholdproperty1119
    UserDataproperty1131
    TSpaceBodyEnumeratorrecord904
    Createfunction911
    GetEnumeratorfunction914
    MoveNextfunction912
    Currentproperty913
    TSpaceHelperhelper1425
    AddCollisionEventsfunction1428
    AddDefaultCollisionEventsfunction1434
    AddWildcardEventsfunction1431
    TSpaceJointEnumeratorrecord934
    Createfunction944
    GetEnumeratorfunction947
    MoveNextfunction945
    Currentproperty946
    TSpaceShapeEnumeratorrecord919
    Createfunction926
    GetEnumeratorfunction929
    MoveNextfunction927
    Currentproperty928
    VectZeroconstant78