Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Zig build package, bindings and C API (JoltC) forhttps://github.com/jrouwe/JoltPhysics

License

NotificationsYou must be signed in to change notification settings

zig-gamedev/zphysics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig build package, bindings andC API forJolt Physics.

For a simple sample applications please seehere.

Getting started

Examplebuild.zig:

pubfnbuild(b:*std.Build)void {constexe=b.addExecutable(.{... });constzphysics=b.dependency("zphysics", .{        .use_double_precision=false,        .enable_cross_platform_determinism=true,    });exe.root_module.addImport("zphysics",zphysics.module("root"));exe.linkLibrary(zphysics.artifact("joltc"));}

Now in your code you may import and usezphysics:

constzphy=@import("zphysics");pubfnmain()!void {tryzphy.init(allocator, .{});deferzphy.deinit();// Create physics systemconstphysics_system=tryzphy.PhysicsSystem.create(...// layer interfaces - please see sample application        .{            .max_bodies=1024,            .num_body_mutexes=0,            .max_body_pairs=1024,            .max_contact_constraints=1024,        },    );deferphysics_system.destroy();// Create shapeconstbody_interface=physics_system.getBodyInterfaceMut();constshape_settings=tryzphy.BoxShapeSettings.create(.{1.0,1.0,1.0 });defershape_settings.release();constshape=tryshape_settings.createShape();defershape.release();// Create bodyconstbody_id=trybody_interface.createAndAddBody(.{        .position= .{0.0,-1.0,0.0,1.0 },        .rotation= .{0.0,0.0,0.0,1.0 },        .shape=shape,        .motion_type=.dynamic,        .object_layer=object_layers.non_moving,    },.activate);deferbody_interface.removeAndDestroyBody(body_id);physics_system.optimizeBroadPhase();// Perform ray cast    {constquery=physics_system.getNarrowPhaseQuery();varresult=query.castRay(.{ .origin= .{0,10,0,1 }, .direction= .{0,-20,0,0 } }, .{});if (result.has_hit) {// result.hit.body_id// result.hit.fraction// result.hit.sub_shape_id...        }    }// Main loopwhile (...) {physics_system.update(1.0/60.0, .{});// Draw all bodiesconstbodies=physics_system.getBodiesUnsafe();for (bodies)|body| {if (!zphy.isValidBodyPointer(body))continue;constobject_to_world=object_to_world: {constposition=zm.loadArr4(body.position);constrotation=zm.loadArr4(body.rotation);varxform=zm.matFromQuat(rotation);xform[3]=position;xform[3][3]=1.0;break :object_to_worldxform;            };// Issue a draw call...        }    }}

Usage in a shared library

Thejoltc artifact can be built as a shared library by specifying theshared build option:

    const zphysics = b.dependency("zphysics", .{        .shared = true,    });

If your zig module useszphysics and is itself part of a shared library that is reloaded at runtime, then some additional steps are required:

  • Before unloading the shared library, callpreUnload to export the internal global state
  • After reloading the shared library, callpostReload to import the internal state and update allocator vtables

If you useregisterTrace orregisterAssertFailed, these must also be called again to update their function pointers.

About

Zig build package, bindings and C API (JoltC) forhttps://github.com/jrouwe/JoltPhysics

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp