Skip to content

Repository files navigation

JoltPhysics4Delphi

A Delphi wrapper and object-oriented binding layer for the Jolt Physics high-performance rigid body physics engine.

Ask DeepWiki

Unbenannt

Hundreds in movement sometimes and still almost cant get it under 60fps on ryzen4500u vega igpu...

This project provides a clean VCL-friendly implementation that bridges the native Jolt Physics C API with Raylib for 3D rendering. It allows you to run a fully multi-threaded physics simulation directly inside a Delphi application.

Status: Work in Progress (Alpha)
The original Jolt Physics C API contains over 3,000 lines of definitions. This wrapper currently covers a few hundred of the most essential lines. While not feature-complete, the core functionality is fully usable and highly stable.

✨ Features

 Core Physics System: World creation, gravity setup, broadphase optimization.
 Rigid Bodies: Static and Dynamic actors with full transform syncing (Position & Rotation).
 Collision Shapes: Box, Sphere, Capsule, and Cylinder primitives.
 Physics Interactions: Apply forces, impulses, and set linear/angular velocities.
 Raycasting: Built-in 3D raycasting from screen coordinates to the physics world.
 Optimization: Frustum & Distance Culling   
 Multi-threading: Utilizes Jolt's built-in thread pool and job system for maximum performance.
 VCL Integration: Includes a TRaylibSandbox component that embeds a Raylib 3D window inside a standard Delphi VCL form, running smoothly in a background thread.

Controls:

Left click drag and throw items
Right click camera rotation
Mouse Wheel zoom in out

📦 Project Structure

The repository consists of three main units:

JoltPhysics.pas - The low-level header translation mapping the JoltC.dll C API to Delphi types and records.
ModelEngine.pas - The Object-Oriented Delphi layer (TModelEngine, TModelActor) that manages the physics world and actors.
RaylibSandbox.pas - A VCL TWinControl that runs a threaded Raylib window, handling 3D rendering, camera input, and user interaction (dragging bodies with the mouse).

🛠️ What's Missing? (Roadmap)

Since the original C API is massive, there is still a lot to cover. Here is what is currently missing but planned for future updates:

 Complete locking BodyInterface for safe multi-threaded access.
 Advanced Joint/Constraint systems (Hinges, Distance, etc.).
 Compound shapes (Mesh shapes, Convex Hulls).
 Collision callback events in Delphi.
 Custom memory allocators (currently using JPH_TempAllocatorMalloc).
 Character virtual controllers.

Exe and sample project included

Latest Changes:

v0.2:

 True 3D Rotation: Implemented proper quaternion-based rotation and transform matrices (Scale * Rotation * Translation) so objects now visually roll and tumble correctly.
 Pyramid Shape: Added stPyramid (simulated via a 4-sided Jolt cylinder) with a slight spawn offset to prevent perfect balancing.
 Frustum & Distance Culling: Optimized the 3D renderer to skip drawing objects that are out of camera view or beyond a set distance limit.
 Custom Spawn Transforms: TModelActor.Create now accepts optional initial position (APos) and rotation (ARot) parameters for dynamic spawning.
 Dynamic Glow State: Moved collision glow logic into a TealGlow property on the actor, triggered by velocity thresholds for cleaner rendering logic.
 Selection Highlighting: Dynamically selected objects are now rendered with a yellow wireframe overlay for clear visual feedback.
 Code Cleanup: Renamed cube-specific variables to generic item names (FItems, PItemData) to reflect support for multiple shape types.    

Based on JoltC from https://github.com/amerkoleci/joltc

ModelEngine based on https://github.com/GuvaCode/raylib-TPS-prototype

About

A Delphi wrapper and object-oriented binding layer for the Jolt Physics high-performance rigid body physics engine.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages