Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AthemIO/SwiftJolt

Repository files navigation

SwiftJolt

Swift wrapper for the Jolt Physics engine with C++ interoperability.

Requirements

  • Swift 6.1+
  • macOS 14+, iOS 17+, or visionOS 1+
  • C++17 compiler

Installation

Add SwiftJolt to your Package.swift:

dependencies: [
    .package(url: "https://github.com/AthemIO/SwiftJolt.git", branch: "main")
]

Then add SwiftJolt as a dependency to your target:

.target(
    name: "YourTarget",
    dependencies: ["SwiftJolt"],
    swiftSettings: [.interoperabilityMode(.Cxx)]
)

Note: After cloning, initialize the submodule:

git submodule update --init --recursive

Usage

import SwiftJolt
import simd

// Create a physics world
let world = PhysicsWorld()
world.gravity = SIMD3(0, -9.81, 0)

// Create shapes
let sphereShape = world.createSphereShape(radius: 0.5)
let boxShape = world.createBoxShape(halfExtents: SIMD3(10, 0.5, 10))

// Create a dynamic body
var ballSettings = BodySettings()
ballSettings.shape = sphereShape
ballSettings.position = SIMD3(0, 10, 0)
ballSettings.motionType = .dynamic
let ball = world.createBody(ballSettings)

// Create a static floor
var floorSettings = BodySettings()
floorSettings.shape = boxShape
floorSettings.position = SIMD3(0, 0, 0)
floorSettings.motionType = .static
floorSettings.objectLayer = ObjectLayerNonMoving
let floor = world.createBody(floorSettings)

// Simulate
for _ in 0..<60 {
    world.step(deltaTime: 1.0 / 60.0)
}

// Query state
let position = world.getPosition(ball)
let velocity = world.getLinearVelocity(ball)

Features

  • Physics world management
  • Collision shapes: sphere, box, capsule, cylinder, convex hull, mesh
  • Body types: static, kinematic, dynamic
  • Forces, impulses, and torques
  • Raycasting and overlap queries
  • Constraints: fixed, point, hinge, slider
  • User data attachment for entity mapping

License

MIT

About

Jolt Physics library with Swift bindings

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published