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
| Name | Kind | Line |
|---|---|---|
| AreaForCircle | function | 106 |
| AreaForPolygon | function | 110 |
| AreaForSegment | function | 107 |
| bodyDynamic | constant | 133 |
| bodyKinematic | constant | 134 |
| bodyStatic | constant | 135 |
| BoolFlags | constant | 80 |
| CentroidForPolygon | function | 112 |
| ClosestPointOnSegment | function | 117 |
| collideGrab | constant | 87 |
| ConvexHull | function | 115 |
| FilterAll | constant | 83 |
| MaskAll | constant | 81 |
| MaskToStr | function | 90 |
| MatrixIdentity | constant | 79 |
| MomentForBox | function | 104, 105 |
| MomentForCircle | function | 98, 99 |
| MomentForPolygon | function | 101, 102 |
| MomentForSegment | function | 100 |
| NewSpace | function | 1438 |
| shapeCircle | constant | 124 |
| shapePolygon | constant | 126 |
| shapeSegment | constant | 125 |
| StrToMask | function | 92 |
| TArbiter | record | 824 |
| Ref | field | 826 |
| CallWildcardBeginA | function | 863 |
| CallWildcardBeginB | function | 864 |
| CallWildcardPostSolveA | procedure | 867 |
| CallWildcardPostSolveB | procedure | 868 |
| CallWildcardPreSolveA | function | 865 |
| CallWildcardPreSolveB | function | 866 |
| CallWildcardSeparateA | procedure | 869 |
| CallWildcardSeparateB | procedure | 870 |
| GetBodies | procedure | 856 |
| GetShapes | procedure | 854 |
| Ignore | function | 852 |
| Implicit | operator | 827, 828 |
| IsFirstContact | function | 858 |
| IsNil | function | 849 |
| IsRemoval | function | 860 |
| ContactPointSet | property | 882 |
| Count | property | 884 |
| Depth | property | 891 |
| Friction | property | 876 |
| Normal | property | 886 |
| PointA | property | 888 |
| PointB | property | 889 |
| Restitution | property | 873 |
| SurfaceVelocity | property | 878 |
| TotalImpulse | property | 894 |
| TotalKineticEnergy | property | 896 |
| UserData | property | 880 |
| TArbiterMethod | procedural | 900 |
| TBitmask | alias | 70 |
| TBody | record | 375 |
| Ref | field | 377 |
| ApplyForceAtBody | procedure | 457 |
| ApplyForceAtWorld | procedure | 455 |
| ApplyImpulseAtBody | procedure | 461 |
| ApplyImpulseAtWorld | procedure | 459 |
| BodyToWorld | function | 451 |
| Equal | operator | 380 |
| Free | procedure | 418 |
| Implicit | operator | 378, 379 |
| IsNil | function | 420 |
| IsSleeping | function | 446 |
| NewBox | function | 431, 432, 433 |
| NewCircle | function | 425, 427 |
| NewPolygon | function | 435 |
| NewPolygonRaw | function | 438 |
| NewSegment | function | 429 |
| NotEqual | operator | 381 |
| Sleep | procedure | 442 |
| SleepWithGroup | procedure | 444 |
| UpdatePosition | procedure | 471 |
| UpdateVelocity | procedure | 468 |
| VelocityAtBody | function | 465 |
| VelocityAtWorld | function | 463 |
| WakeUp | procedure | 449 |
| WorldToBody | function | 453 |
| Angle | property | 490 |
| AngularVelocity | property | 492 |
| CenterOfGravity | property | 481 |
| Force | property | 488 |
| Kind | property | 474 |
| KineticEnergy | property | 499 |
| Mass | property | 477 |
| Moment | property | 479 |
| Position | property | 483 |
| PositionFunc | property | 503 |
| Rotation | property | 497 |
| Shape | property | 505 |
| Shapes | property | 509 |
| Torque | property | 495 |
| UserData | property | 507 |
| Velocity | property | 485 |
| VelocityFunc | property | 501 |
| TBodyHelper | helper | 1408 |
| EachArbiter | procedure | 1417, 1418 |
| Space | function | 1413 |
| Joints | property | 1420 |
| TBodyJointEnumerator | record | 809 |
| Create | function | 815 |
| GetEnumerator | function | 818 |
| MoveNext | function | 816 |
| Current | property | 817 |
| TBodyKind | alias | 130 |
| TBodyShapeEnumerator | record | 360 |
| Create | function | 366 |
| GetEnumerator | function | 369 |
| MoveNext | function | 367 |
| Current | property | 368 |
| TCircle | record | 146 |
| Ref | field | 148 |
| Free | procedure | 160 |
| Implicit | operator | 149, 150, 151, 152 |
| IsNil | function | 162 |
| Reshape | procedure | 164 |
| Offset | property | 168 |
| Radius | property | 166 |
| TCircleHelper | helper | 1286 |
| Base | function | 1289 |
| TCollisionEvent | procedural | 1152 |
| TCollisionEvents | record | 1155 |
| OnBegin | field | 1158 |
| OnPostSolve | field | 1163 |
| OnPreSolve | field | 1161 |
| OnSeparate | field | 1165 |
| TCollisionFilterEvent | procedural | 1150 |
| TCollisionHandler | alias | 75 |
| TCollisionType | alias | 72 |
| TDampedRotarySpringJoint | record | 636 |
| Ref | field | 638 |
| Implicit | operator | 639, 640 |
| Damping | property | 656 |
| RestAngle | property | 652 |
| Stiffness | property | 654 |
| TorqueFunc | property | 658 |
| TDampedRotarySpringJointHelper | helper | 1360 |
| Base | function | 1363 |
| TDampedSpringJoint | record | 602 |
| Ref | field | 604 |
| Implicit | operator | 605, 606 |
| Damping | property | 629 |
| ForceFunc | property | 631 |
| PinA | property | 622 |
| PinB | property | 623 |
| RestLength | property | 625 |
| Stiffness | property | 627 |
| TDampedSpringJointHelper | helper | 1352 |
| Base | function | 1355 |
| TGearJoint | record | 704 |
| Ref | field | 706 |
| Implicit | operator | 707, 708 |
| Phase | property | 716 |
| Ratio | property | 718 |
| TGearJointHelper | helper | 1384 |
| Base | function | 1387 |
| TGrooveJoint | record | 580 |
| Ref | field | 582 |
| Implicit | operator | 583, 584 |
| GrooveA | property | 594 |
| GrooveB | property | 595 |
| PinB | property | 597 |
| TGrooveJointHelper | helper | 1344 |
| Base | function | 1347 |
| TJoint | record | 738 |
| Ref | field | 740 |
| AsDampedRotarySpring | function | 778 |
| AsDampedSpring | function | 777 |
| AsGear | function | 781 |
| AsGroove | function | 776 |
| AsMotor | function | 782 |
| AsPin | function | 773 |
| AsPivot | function | 775 |
| AsRatchet | function | 780 |
| AsRotaryLimit | function | 779 |
| AsSlide | function | 774 |
| Equal | operator | 743 |
| Free | procedure | 767 |
| Implicit | operator | 741, 742 |
| IsGrab | function | 771 |
| IsNil | function | 769 |
| NotEqual | operator | 744 |
| A | property | 786 |
| B | property | 788 |
| CollideBodies | property | 790 |
| ErrorBias | property | 792 |
| Impulse | property | 798 |
| Kind | property | 784 |
| MaxBias | property | 794 |
| MaxForce | property | 796 |
| PostSolve | property | 802 |
| PreSolve | property | 800 |
| UserData | property | 804 |
| TJointHelper | helper | 1400 |
| Space | function | 1403 |
| TJointKind | enum | 140 |
| jointPin | enum value | 140 |
| jointSlide | enum value | 140 |
| jointPivot | enum value | 140 |
| jointGroove | enum value | 140 |
| jointDampedSpring | enum value | 140 |
| jointDampedRotarySpring | enum value | 141 |
| jointRotaryLimit | enum value | 141 |
| jointRatchet | enum value | 141 |
| jointGear | enum value | 141 |
| jointMotor | enum value | 141 |
| jointCustom | enum value | 142 |
| TMarchSample | procedural | 1236 |
| TMotorJoint | record | 723 |
| Ref | field | 725 |
| Implicit | operator | 726, 727 |
| Rate | property | 733 |
| TMotorJointHelper | helper | 1392 |
| Base | function | 1395 |
| TPinJoint | record | 514 |
| Ref | field | 516 |
| Implicit | operator | 517, 518 |
| Distance | property | 531 |
| PinA | property | 528 |
| PinB | property | 529 |
| TPinJointHelper | helper | 1320 |
| Base | function | 1323 |
| TPivotJoint | record | 561 |
| Ref | field | 563 |
| Implicit | operator | 564, 565 |
| PinA | property | 573 |
| PinB | property | 574 |
| TPivotJointHelper | helper | 1336 |
| Base | function | 1339 |
| TPolygon | record | 208 |
| Ref | field | 210 |
| Free | procedure | 222 |
| Implicit | operator | 211, 212, 213, 214 |
| IsNil | function | 224 |
| Reshape | procedure | 226, 228 |
| ReshapeRaw | procedure | 231 |
| Border | property | 233 |
| Vert | property | 237 |
| VertCount | property | 235 |
| TPolygonHelper | helper | 1302 |
| Base | function | 1305 |
| TPolyline | record | 1178 |
| Ref | field | 1180 |
| Copy | function | 1197 |
| Create | function | 1191 |
| Free | procedure | 1193 |
| Implicit | operator | 1181, 1182 |
| IsNil | function | 1195 |
| SimplifyCurves | function | 1201 |
| SimplifyVertexes | function | 1205 |
| ToArray | function | 1209 |
| ToConvexHull | function | 1207 |
| Closed | property | 1217 |
| Count | property | 1211 |
| Vert | property | 1213 |
| Verts | property | 1215 |
| TPolylineSet | record | 1240 |
| Ref | field | 1242 |
| AddSegment | procedure | 1275 |
| ConvexDecomposition | function | 1253 |
| Create | function | 1250 |
| Free | procedure | 1270 |
| GetEnumerator | function | 1277 |
| Implicit | operator | 1243, 1244 |
| IsNil | function | 1272 |
| MarchHard | function | 1264, 1267 |
| MarchSoft | function | 1257, 1260 |
| Count | property | 1279 |
| Line | property | 1281 |
| TPolylineSetEnumerator | record | 1222 |
| Create | function | 1228 |
| MoveNext | function | 1229 |
| Current | property | 1230 |
| TRatchetJoint | record | 681 |
| Ref | field | 683 |
| Implicit | operator | 684, 685 |
| Angle | property | 695 |
| Phase | property | 697 |
| Ratchet | property | 699 |
| TRatchetJointHelper | helper | 1376 |
| Base | function | 1379 |
| TRotaryLimitJoint | record | 663 |
| Ref | field | 665 |
| Implicit | operator | 666, 667 |
| Max | property | 676 |
| Min | property | 675 |
| TRotaryLimitJointHelper | helper | 1368 |
| Base | function | 1371 |
| TSegment | record | 173 |
| Ref | field | 175 |
| Free | procedure | 190 |
| Implicit | operator | 176, 177, 178, 179 |
| IsNil | function | 192 |
| Join | procedure | 195 |
| A | property | 199 |
| B | property | 201 |
| Border | property | 197 |
| Normal | property | 203 |
| TSegmentHelper | helper | 1294 |
| Base | function | 1297 |
| TShape | record | 242 |
| Ref | field | 244 |
| AsCircle | function | 287 |
| AsPolygon | function | 288 |
| AsSegment | function | 289 |
| CacheBB | function | 298 |
| Collide | function | 296 |
| Equal | operator | 247 |
| Free | procedure | 283 |
| Implicit | operator | 245, 246 |
| IsNil | function | 285 |
| NotEqual | operator | 248 |
| PointQuery | function | 292 |
| SegmentQuery | function | 294 |
| Update | function | 300 |
| Area | property | 314 |
| BoundingBox | property | 318 |
| Category | property | 350 |
| CenterOfGravity | property | 316 |
| CollisionType | property | 355 |
| Density | property | 310 |
| Elasticity | property | 326 |
| Filter | property | 345 |
| Friction | property | 329 |
| Group | property | 347 |
| Kind | property | 304 |
| Mask | property | 353 |
| Mass | property | 308 |
| Moment | property | 312 |
| Next | property | 302 |
| Sensor | property | 322 |
| SurfaceVelocity | property | 332 |
| UserData | property | 334 |
| TShapeHelper | helper | 1310 |
| Body | function | 1313 |
| Space | function | 1315 |
| TShapeKind | alias | 121 |
| TSlideJoint | record | 536 |
| Ref | field | 538 |
| Implicit | operator | 539, 540 |
| Max | property | 556 |
| Min | property | 555 |
| PinA | property | 552 |
| PinB | property | 553 |
| TSlideJointHelper | helper | 1328 |
| Base | function | 1331 |
| TSpace | record | 952 |
| Ref | field | 954 |
| Add | function | 1058, 1059, 1060 |
| AddCollisionHandler | function | 1005 |
| AddDefaultCollisionHandler | function | 1009 |
| AddPostStepCallback | function | 1013 |
| AddWildcardHandler | function | 1007 |
| BoxQuery | function | 1087 |
| Contains | function | 1067, 1068, 1069 |
| DebugDraw | procedure | 1103 |
| Free | procedure | 985 |
| Implicit | operator | 955, 956 |
| IsNil | function | 987 |
| NewBody | function | 1025 |
| NewDampedRotarySpring | function | 1047 |
| NewDampedSpring | function | 1045 |
| NewGear | function | 1051 |
| NewGroove | function | 1044 |
| NewKinematicBody | function | 1028 |
| NewMotor | function | 1053 |
| NewPin | function | 1040 |
| NewPivot | function | 1042, 1043 |
| NewRatchet | function | 1050 |
| NewRotaryLimit | function | 1049 |
| NewSlide | function | 1041 |
| NewStaticBody | function | 1031 |
| PointQuery | function | 1075 |
| PointQueryNearest | function | 1078 |
| ReindexBody | procedure | 1096 |
| ReindexShape | procedure | 1095 |
| ReindexStatic | procedure | 1094 |
| ReleaseBodies | procedure | 989 |
| ReleaseJoints | procedure | 991 |
| ReleaseObjects | procedure | 995 |
| Remove | procedure | 1063, 1064, 1065 |
| SegmentQuery | function | 1081 |
| SegmentQueryFirst | function | 1084 |
| ShapeQuery | function | 1089 |
| Step | procedure | 997 |
| UseSpatialHash | procedure | 1099 |
| Bodies | property | 1135 |
| CollisionBias | property | 1123 |
| CollisionPersistence | property | 1125 |
| CollisionSlop | property | 1121 |
| CurrentTimeStep | property | 1127 |
| Damping | property | 1111 |
| Gravity | property | 1113 |
| Ground | property | 1106 |
| IdleSpeedThreshold | property | 1116 |
| Iterations | property | 1108 |
| Joints | property | 1140 |
| Locked | property | 1129 |
| Shapes | property | 1137 |
| SleepTimeThreshold | property | 1119 |
| UserData | property | 1131 |
| TSpaceBodyEnumerator | record | 904 |
| Create | function | 911 |
| GetEnumerator | function | 914 |
| MoveNext | function | 912 |
| Current | property | 913 |
| TSpaceHelper | helper | 1425 |
| AddCollisionEvents | function | 1428 |
| AddDefaultCollisionEvents | function | 1434 |
| AddWildcardEvents | function | 1431 |
| TSpaceJointEnumerator | record | 934 |
| Create | function | 944 |
| GetEnumerator | function | 947 |
| MoveNext | function | 945 |
| Current | property | 946 |
| TSpaceShapeEnumerator | record | 919 |
| Create | function | 926 |
| GetEnumerator | function | 929 |
| MoveNext | function | 927 |
| Current | property | 928 |
| VectZero | constant | 78 |