GithubHelp home page GithubHelp logo

box2c's People

Contributors

erincatto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

box2c's Issues

Joint parameter getters and setters

I'd like to recover as many of these as reasonably possible. In my engine, I've specifically wrapped all joint getters and setters from v2.4 in the scripting engine, in order to easily monitor and variably configure joints, based on a variety of different gameplay conditions. Additionally, I have some joint configurations that are designated as renderable in relation to their connected bodies; in these cases I recover even the generic joint data like the local anchor points and transform them using an array of body transforms, which are adjusted for visual interpolation.

I probably can't make a proper use case for getting and setting every single joint parameter at this time, since I've focused more on engine development than the creative process, however I think joints are where Box2D really shines and I wanted to express a desire to see that level of control make its way back. I figured it would also be easier to ask for another pass and then fill in any remaining blanks from there, if that makes sense.

A few examples that have popped up thusfar would be like b2DistanceJoint_SetLength, which takes all 3 length parameters, but if say only minLength needs to be changed, there is no way to recover what the other two were. b2DistanceJoint_SetTuning is in the same boat. There are also no functions to check or adjust a weld joint after creation.

EDIT: I'd also like for joint user data to return if that's reasonable to do.

Extend the API with missing functions from what was present in box2d

Starting with my needs for godot-box2d which integrates box2d into godot. Godot has its own physics system that has an API that needs implementing. With box2d this was possible, but in box2c some functions are missing.

- b2Body_SetFixedRotation() // be able to set fixed rotation of body after it's created.
- b2Body_ForceSleep() // force a body to sleep. I used to call this after making a body static. Not 100% sure if it was needed, but nice to have since there is a wake function as well.
- b2Body_GetBullet() // get if a body has ccd enabled
- b2Body_SetBullet() // set if a body has ccd enabled
- b2Body_IsSleepingAllowed() // get if a body is allowed to sleep
- b2World_GetBodies() // some function to get bodies in the world. I use this to go through all bodies and check which of them moved so I can call a callback on them and mark them as active bodies. There might be a better way to do it, not sure.

Haven't went yet into setting callbacks and other things, still wip, but these are just a few. I will add more as I advance.

v3.1 Tasks

  • sample character mover
  • smooth manifold merger
  • world dump
  • shift origin
  • floating point determinism
  • rolling resistance
  • samples app support multiple OpenGL versions

Linux gcc build

This is my fork which I build on Arch linux x64. Core library does not require changes in CMakeLists.txt but samples are trick.

Could not build library by gcc on Arch linux with -Wpedantic

Prerequiments:

➜  box2c git:(main) ✗ lsb_release -a
LSB Version:	n/a
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a                                                                                       /0.0s
➜  box2c git:(main) ✗ gcc --version
gcc (GCC) 13.2.1 20230801
...
➜  box2c git:(main) ✗ cmake --version 
cmake version 3.27.8
...

Build command is cmake . && make -j that gives the next:

In file included from /home/nagolove/tmp/box2c/extern/simde/x86/sse.h:34,
                 from /home/nagolove/tmp/box2c/extern/simde/x86/avx.h:28,
                 from /home/nagolove/tmp/box2c/src/contact_solver.h:9,
                 from /home/nagolove/tmp/box2c/src/island.c:10:
/home/nagolove/tmp/box2c/extern/simde/x86/../simde-f16.h:96:11: error: ISO C does not support the ‘_Float16’ type [-Werror=pedantic]
   96 |   typedef _Float16 simde_float16;
      |           ^~~~~~~~
In file included from /home/nagolove/tmp/box2c/extern/simde/x86/sse.h:34,
                 from /home/nagolove/tmp/box2c/extern/simde/x86/avx.h:28,
                 from /home/nagolove/tmp/box2c/src/contact_solver.h:9,
                 from /home/nagolove/tmp/box2c/src/contact_solver.c:4:
/home/nagolove/tmp/box2c/extern/simde/x86/../simde-f16.h:96:11: error: ISO C does not support the ‘_Float16’ type [-Werror=pedantic]
   96 |   typedef _Float16 simde_float16;
      |           ^~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/box2d.dir/build.make:317: src/CMakeFiles/box2d.dir/island.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/nagolove/tmp/box2c/extern/simde/x86/sse.h:34,
                 from /home/nagolove/tmp/box2c/extern/simde/x86/avx.h:28,
                 from /home/nagolove/tmp/box2c/src/contact_solver.h:9,
                 from /home/nagolove/tmp/box2c/src/graph.c:11:
/home/nagolove/tmp/box2c/extern/simde/x86/../simde-f16.h:96:11: error: ISO C does not support the ‘_Float16’ type [-Werror=pedantic]
   96 |   typedef _Float16 simde_float16;
      |           ^~~~~~~~
cc1: all warnings being treated as errors

After removing -Wpedantic from CMakeLists.txt building gone to work.

Consider all b2_null{Type}Id values as 0

Taken from include/box2d/id.h various null ids are defined as {-1, -1, 0}. This has different binary representation than nullptr. Some bits are 1 while with nullptr all bits are 0. While there is no big difference in C/C++, because every field/variable must be initialized (unless you want to memset 0 the entire structure), other languages might use their own policies. For example in C# struct cannot have custom default (no parameters) constructor, the compiler automatically provides a default constructor that initializes all fields to their default values and these are 0 for int/uint. So with C# binding, the current approach would be much more cumbersome to use and error-prone because you couldn't rely on the default compiler behavior.

Stack allocator grow

The stack allocator should be grown each time step when capacity has been exceeded. I can still report the needed capacity for optimal startup.

Restoring/Adding helper functions for AABBs

In v2.4 I was able to iterate over the fixtures of a body, getting AABBs from the shape, agnostic of the shape type, since ComputeAABB was part of the base class. Now it looks like the only path to replicate this behavior is to use the shapeID to get the type, then switch case that to use the shape specific compute functions in geometry.h after also getting the geometry pointers.

It looks like b2ComputeShapeAABB already exists, but isn't exposed for the user. I think it would be nice to be able to get an AABB from a shapeID and transform in a similar way.

Additionally, it would be nice to have some of the AABB helper functions back. In this same case, I would use Combine with each of these AABBs to create one large "body AABB" which I would then make sure was usable with IsValid. I'm also missing GetCenter, Contains, and b2TestOverlap.

FinishTask and ParallelFor

Hi Erin,

the FinishTask function is not checking if the task pointer is null and returning if it is, which can occur if the task array is full.

https://github.com/erincatto/box2c/blob/main/samples/sample.cpp#L52

Also, I think a good idea is to add a ParallelFor function to Box2C. This is a common practice I think. With enkiTS, ParallelFor can be implemented by a enqueue function followed by a wait for task function. This is good because it doesn't add to the task array and since (I think) enkiTS scheduler is thread-safe, the parallel for function can be called from multiple threads.

Creation/destruction of things in response to collision

Callbacks block this. Implement some samples to show best practices and get community feedback.

Use cases:

  • in response to a collision create a body and attach it with a constraint to an existing body
  • destroy a body
  • change a shape

Feature request: One-way joints.

As I've been developing a game around the previous version of Box2D, I've found myself wishing for "one way joints."

The best use-case I can provide is between two dynamic bodies in a platformer-type setting. You would have a primary player-controlled "body" and an auxiliary "head," connected together with two joints: distance and revolute. The revolute joint is configured to limit how much movement the head can perform, while the distance joint acts as a spring to center it.

As the player lands on a platform, the head has room to bounce down a little bit. This looks awesome. But, since it is now pulling down on the player body, if the player were to immediately jump again, the force of the joint pulling on it would reduce the next jump's height.

Since this particular set up of joints is entirely based around the effects on only one of the bodies, if it was possible to turn off the joint effects on the other, that would be excellent. I have experimented with several practical ways to try to get around this, but each seems to have its own caveats or produces a different result.

I figured I would request this early, since I would imagine that it would require adding some bools to the joint defs and that would be less API changes later.

Missing body/shape functions for dampings, gravity, filter

Currently it looks like there's no getters or setters for existing bodies for linear damping, angular damping, or gravity scale.

EDIT: I'm also noticing that there are no functions for getting/setting the filter on existing shapes.

Soft contact sample

Circles move with linear speed towards a point. According to the formula below.
Similar code works fine with Box2D C++ and its ports.
There the circles never pass through each other.

auto dist_x =  player_p.x/PPM - enemy_p.x;
auto dist_y =  player_p.y/PPM  - enemy_p.y;
auto distance = sqrt(dist_x*dist_x+dist_y*dist_y);
auto velocity_x = dist_x/distance*speed;
auto velocity_y = dist_y/distance*speed;
b2Body_SetLinearVelocity(enemy[i], b2Vec2{velocity_x , velocity_y});

Faster render

map a buffer and have multiple threads write to different sections
have one large draw call from that buffer

https://docs.gl/gl3/glMapBufferRange
what you need is glMapBufferRange to map a buffer with circle transforms
https://docs.gl/gl3/glDrawElementsInstanced
glDrawElementsInstanced, draw 1 instance per circle
have 3 buffers
1 index buffer with circle indices
1 vertex buffer with circle vertices
1 vertex buffer with one transform matrix per circle
map the transform buffer and write to different sections from threads, then unmap it
for that transform buffer use this https://docs.gl/gl3/glVertexAttribDivisor
set the attribute divisor to 1, this will map one element from the buffer to each circle instance
and then in a shader you will get this transform matrix as a regular vertex attribute

Please consinder providing a public api file

What would you think about providing a file for public apis so that other languages can write generators that can generate code which is easier to read on that language.

For example Steam provides a json file for Steamworks-SDK.

steam_api.txt

Only having a header file either requires using generic ffi-binding-generator where the yielding code is unreadable or manually parsing header file which is not great to write or writing every binding manually which is hard to maintain.

With this file it is very easy to generate ffi-bindings and create a readable code.

Example: https://github.com/aeb-dev/steamworks_gen which generates https://github.com/aeb-dev/steamworks

Chain shape access

Be able to access the segments for bespoke distance, TOI, etc. For character mover.

v3 TODO

  • large islands graph coloring
  • continuous collision
  • speculative collision
  • ray cast complete
  • shape cast complete
  • rebuild tree spans island solver
  • all joint types
  • all shape types
  • edge mesh builder
  • fix shape render
  • samples run on linux and mac
  • all samples from v2
  • performance tracking
  • update documentation (doxygen)
  • contact reporting
  • query shape vs world for clearance
  • unit test for empty world
  • migration guide
  • fixed rotation
  • destroy shapes
  • add awake index back (destroy contact perf)
  • capsules
  • bullets (continuous priority)
  • kinematic bodies
  • modify body types
  • speculative bug
  • set mass data (default density == 1)
  • joints in graph
  • ARM Neon support (simde)
  • review task API
  • sensors
  • body movement limit to 0.5 * b2_huge (falling too far asserts)?
  • -march=native ?
  • example repo using FetchContent_Declare
  • refactor b2MassData
  • test shared lib build
  • cmake install
  • test presolve disable contact
  • v3 documentation on website
  • get chain shape owner
  • sample with chain linking
  • audit memory usage
  • test mingw
  • sanitizers in github actions
  • hit events
  • single c and h file
  • use int32_t in public data structures
  • try pixel units
  • swap sine and cosine in b2Rot
  • springs for revolute and prismatic joints
  • kinematic tree
  • no masking for pair queries so that groups can work
  • custom contact filter callback

How access to shape data in AABB query?

I would use b2World_QueryAABB for get visible objects in work for drawing. But now I have not pointers to internal structures with polygon data, circle data etc. How it would be implemented? Or may be I did not see such in example.

Ray/Shapecast a single shape by ID

In v2.4 I was able to collect a list of fixtures, and then raycast their shapes directly, without needing to know the shape type. It looks like there isn't a way to do this currently.

My use case was some basic line of sight checking for targeting. I would use QueryAABB to get everything in range of an object, filtering everything into two lists: fixtures marked as "hurtboxes," and fixtures marked as capable of blocking line of sight. Then to find the closest valid target, I would use body positions to determine a ray, and cast against anything in the "block line of sight" list; continually adjusting the maxFraction from any hits, before finally using that possibly-shorter ray to cast against the "hurtbox" fixtures to see if they still hit.

Probably not the most accurate approach, but it worked well enough for my use. With v3 adding b2World_OverlapPolygon, I am wondering if a visibility polygon approach might be more accurate and efficient. But I still think it would be beneficial to have something like a b2Shape_RayCast function. This could possibly also apply to shapecasting.

Add functions for returning default def structs.

I am currently working on creating automated C# bindings for box2c at this repo Box2D.NET. Most C# bindings generators do not support generating constant structs like this one below.

static const b2Filter b2_defaultFilter = {0x00000001, 0xFFFFFFFF, 0};

It is left up to the user to initialize the default values manually because of these limitations. Right now I have handwritten extensions that provide the default values but these are error prone and will become outdated if box2c adds/modifies/removes any members from these structs.

It would be great if box2c also came functions that could provide default values as an alternative to using the const structs. Maybe something like b2_MakeDefaultWorldDef would be a good option? Ideally the user should be able use these functions and run the binding generator without having to worry about possible changes to the default values.

Sample Repo

Sample repo with box2d v3/raylib/enkiTS

Make it a template?

Checking if a shape by ID is a sensor

Currently working on migrating an AABB query callback that collects all shapes in an area, and I'd like to ignore any shapes that are sensors, but currently do not have a replacement for IsSensor. It would definitely be nice to have that function back.

I was also thinking that this might also be a possibly good use case for adding another field to b2QueryFilter for ignoring sensors, since that might be useful for others as well.

Getting a b2JointType from a b2JointId

After creating a joint, there's no way to get what kind of joint type it is from the ID. Before it was possible to store the base b2Joint class and use GetType; I use this in switch cases to check/modify joint parameters after creation.

EDIT: I've also noticed that b2JointType is internal, which would also have to be changed.

Restoring changing the density of existing shapes, and resetting the mass of a body

I've noticed that there's no functions for getting or setting the density of a shape after creation. After making changes, in v2.4 I would also use ResetMassData to make sure that the body's mass is properly updated as well. It would be nice to have these back using the new systems.

EDIT: I also noticed that there's no getter for MassData either.

Fix shape cast

It is not handling the unit test of ray vs box. The shape cast code should handle zero radius (I think).

Allow negative gravity scale again

I use a negative gravity scale at body definition all the time in v2.4 to make light things like bubbles float upwards, and adjust it per frame for any body in water, allowing certain objects to float. Unfortunately several assertions prevent this from being treated as a valid input, requiring that gravityScale >= 0.0f. I'm hoping this is not intentional.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.