-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete the Bullet C-API (was googlecode Issue 43) #130
Comments
Hey Erwin, any updates on the C API? I'd like to use Bullet in my pure LuaJIT 3D game engine and this means we need to bind with the C API with FFI to avoid the slower actual Lua API bindings. Thanks! |
Hey Erwin! (and every one) First, I think that Bullet is great! I would like to support Bullet C API, since as said before, it is the most important feature if we want portability with other language (I do :-) ). Since you tagged this in milestone Bullet 3.00, I test the latest C-API(of ngb...@gmail.com) in the Bullet3 repo. First I found this tree possible bugs:
Question that I have:
After those global points, I would like to describe the current status, why it's not good and my alternative. == Current Status - OpenPL-like library ==
It sound nice, OpenGL-ES-like idea, every one could implement the library differently.
If someone want to make an OpenPL-like idea, it should be separated from Bullet C wrapper. == Alternative - "real" C wrapper == I think that bullet should look like the "standard" style of API. I took ODE for example, but actually it's the same as most wrappers(for every language). Notice that the numbers matches to previous numbers.
Believe me, it's easier for everyone:
== Summery == I know I might put a bomb after people hard work, but I only wish the best for Bullet. BTW: Sorry for my English.
[1] See the example for placement new in: http://en.cppreference.com/w/cpp/language/new |
I'm interested in seeing this C API come together (as someone who might write a wrapper) and I think @Tal500 makes good points. I'd rather see the C API designed like that. |
@resttime thanks for your comment! Lately, I was very short in my free time, so my current result are not very huge. Here is my work repository: The first goal is to have a fast and convince C API as possible, for the Hello World example (work in progress). Notice that macro helpers are meant to be used widely in the CPP files, the header should be easy to understand. I know I need to fix alignment to be 16-byte aligned, and the Vector3 is probably not the smartest thing, should change it to Vector(4 components). Any suggestion would be appreciated. |
I am still figuring the new Bullet 3.x API out, let alone a C-API. Note that Bullet 2.x is moving all into Bullet 3. I did one experiment for a C-API file in Bullet 3 here: bullet3\src\Bullet3OpenCL\Initialize\b3OpenCLUtils.h |
@Tal500 @erwincoumans |
First, I want to thank you for your review and comments! It's really motivate me. I'm glad to announce I've complete to wrap a very minor API in order to complete Hello World test/example. it's working! (tested with bullet-2.82-r2704) I have tried to push down restricted pointers, macro, and inlining in purpose, to see how far it could work, and I think it worked well. Some could be dropped if you decide it too complex. There are many places in the code that I thought to myself - why we need structure duplication? It's hard to maintain, bad in converting performance, and a source for bugs! Bullet could support the entire C API directly, in its headers, everything with the "bt"/"b3" prefix, no need for "cbt", like at my header.
As same as Erwin suggest in b3OpenCLUtils.h, for example, the header could look like this:
Finally, I have two suggestion about changing API that would fit both C and C++:
Future thinking - custom C sub-classing and overriding with vtables? What do you think? What C features from here do you want in Bullet3? |
I don't have much time to digg into this further at this moment, but I'll get to it. For the math C-API, it would be helpful to stay compatible with OpenCL when it makes sense to do so. In OpenCL there is a float4, and there is some b3Float4 for compatibility, see src\Bullet3Common\shared\b3Float4.h. The idea is to store common structures can be used in C++, C and OpenCL in 'shared' folders. Again, I need to think more about this and your feedback/thoughts are welcome. |
Fair enough. I see that B3 API is far from being stable, so I won't try making them C-compatible yet. This would allow to users to use this fork of Bullet if they want to use it in the lagecy API. What do you think? |
Erwin, as I said before, I've forked bullet3 for embedded C binding: Right now, I'm focused on the old Bullet2 API, since the B3 API isn't stable yet. I'm currently working on LinearMath, making mathematical structures the same between C&C++. The idea is that ALL mathematical structure is shared between C&C++. If the user is in C++, she can call function member and language features. See my src/LinearMath/btVector3.h for example. And about the simplified structures, such as b3Float4, it can be easily retrieved from btVector:
And the opposite in a similar way. The code is far from being finished, but would you consider such approach in b3? |
I really hope bullet 3 api will have a supported c api. Lack of a stable supported fully featured wrapper has been biggest slow down with using Bullet in my non c++ projects. Is the bullet 3 api going to be able to downgrade back to the cpu if the video card card isn't capable enough? Thanks for all the great work. |
I've also been working on a C API as part of a P/Invoke .NET wrapper. It's pretty much complete for bullet 2 and I've planned to start with bullet 3 this summer. https://github.com/AndresTraks/BulletSharpPInvoke/tree/master/libbulletc It's a bit different though as it's first and foremost designed to be an intermediate layer between bullet and other higher level wrappers instead of being a natural C API. The code is completely independent from bullet, so nothing needs to be modified in bullet itself. Here's the idea of how it currently works: //btCollisionShape_wrap.h
#ifndef BT_COLLISION_SHAPE_H
#define btCollisionShape void
#endif
EXPORT void btCollisionShape_delete(btCollisionShape* obj); //btSphereShape_wrap.h
#ifndef BT_SPHERE_MINKOWSKI_H
#define btSphereShape void
#endif
EXPORT btSphereShape* btSphereShape_new(btScalar radius);
EXPORT btScalar btSphereShape_getRadius(btSphereShape* obj); //btCollisionShape_wrap.cpp
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include "btCollisionShape_wrap.h"
void btCollisionShape_delete(btCollisionShape* obj)
{
delete obj;
} //btSphereShape_wrap.cpp
#include <BulletCollision/CollisionShapes/btSphereShape.h>
#include "btSphereShape_wrap.h"
btSphereShape* btSphereShape_new(btScalar radius)
{
return new btSphereShape(radius);
}
btScalar btSphereShape_getRadius(btSphereShape* obj)
{
return obj->getRadius();
} //bulletc.h
#include "btCollisionShape_wrap.h"
#include "btSphereShape_wrap.h" //test.cpp
#include <bulletc.h>
btSphereShape* shape = btSphereShape_new(1.0f);
btScalar radius = btSphereShape_getRadius(shape);
btCollisionShape_delete(shape); |
AndresTraks, After this, the C API might be easily written in full Bullet 3 API. Do you think we should combine our efforts? |
Yes, I can surely help. My interest is that Bullet could be compiled into a .dll/.so library with the C symbols exported. This is a standard way of writing wrappers for other languages like C# and Lua. |
Bump. Any progress on this since the last update? I am very interested in writing up-to-date Bullet bindings for Rust, which would require a C FFI. |
Sadly I'm very busy these days, but I didn't forget it, just need some time and help. As said above, I focused on first supporting LinearMath before the rest of Bullet. You might use this, and extend this binding to the Bullet API function in your project, and send your implementation for updating the C API. I would like however some help on finishing LinearMath implementation, contact me if you're interested. |
Hi all, I've completed basic Bullet 2 LinearMath C API. Now I want to write embedded C API for Bullet 2 Core(collision&dynamics). By embedded I mean that the function decelerations are in the original header, and their implementation are in the original source. (AndresTraks especially, I want you to answer this :) |
@ebkalderon ☝️ |
After some serious thinking, I decided to pause my effort on the Bullet fork with embedded support, until some merging or decision from official Bullet. As I described many before, I finished making LinearMath compatible with C. I thought it was crucial if we want C API inside the official Bullet API. If ODE did only C API, Bullet can do both C and C++ API. Now, after this LinearMath C API infrastructure, writing a C API in the same headers should be not difficult. I'm not going to do so if it won't be merged, or a strategic decision will be made. Even known it's only for Bullet 2 right now I still think it's important, since it's the widely used version right now. Wait for your response. |
@Tal500 Maybe you should make a pull request and propose a first step towards a C api. |
@CapsAdmin, as you suggested I created this pull request: #636 |
@kyle-emmerich @erwincoumans just FYI, im working on a C wrapper, with the end goal to be used with the LuaJIT ffi: https://github.com/rweichler/bullet_luajit/blob/master/bullet_wrapper.cpp |
Thanks for sharing the various projects and thoughts about a Bullet 2.x specific C-API. We have pybullet python bindings for bullet3/examples/SharedMemory/PhysicsClientC_API.h and it would be straight-forward to add Lua bindings the that C-API as well. The move to Bullet 3.x and 4.x is going to happen, and don't want to extend the life of the 2.x API, even if that is the current most active version. Let's keep this issue open for discussion, some people may like to use the Bullet 2.x specific C-APIs. |
How is this going along? Is there any viable C API nowadays? |
EvilPudding, I stopped the work since Erwin didn't accept it. He said(as much as I understand) that the new C API will be part of Bullet3 API. |
What does that mean? And is it available right now? |
Yes, the new C API is here: It is used in PyBullet, see the quickstart guide here. |
@erwincoumans Thanks a lot! |
Hi Erwin
|
@Tal500 The good thing about that it's backwards compatible, meaning you can pass a function callback whose signature does not receive the |
@Tal500 There is no global world: you can create multiple physics clients/servers and each server has its own world. I highly recommend trying to prototype in Python/PyBullet and try out the API. |
@erwincoumans I didn't understand the API at first, but now it's look great! |
@erwincoumans Why is the C API you linked in an example and is not installed by default? Do we have to copy the example API for each project and update it manually every time there's an update? |
I don't even know how to compile this... I tried to use the cmake file of the SharedMemory example, and I get the following error:
Why does this file assume it is in the |
I would thank someone who would walk me through how to get a compiled library so I can use the C API? Why is this so tangled? |
@EvilPudding App_RobotSimulator and App_HelloBulletRobotics are two example of using the C and C++ API. Both should build out-of-the box as well, using cmake. For Linux and Mac, use the build_cmake_pybullet_double.sh as an example. For Windows, see the build_visual_studio_vr_pybullet_double_cmake.bat in the root of Bullet. Alternatively, premake also builds BulletRobotics library, with C-API. |
Thanks for the help, I'm sorry if this was obvious stuff, it's just it's a bit different from other libraries I've used before. Thanks for all the hard work. |
Ok, here's where I got it wrong, my package manager has an older version of the library which does not contain the C api... Sorry about that. Now I see the C API does get installed in the default folder. |
@erwincoumans I understand if you don't have the time to answer, but I'm trying to compile a C file using the API, and I can't seem to link it with If I just link it,
Again, I don't want to be a bother, so if you don't have the time, I understand if you don't answer. |
Turns out I needed to add
I tried to search for them in the elf information in the installed libs and can't find where they ended up. If I don't use those functions it looks like it works fine. This is a great library, and I'm very thankful for all the work put in here, thanks @erwincoumans |
cmake App_RobotSimulator_NoGUI and App_RobotSimulator link against BulletRobotics without a problem. Let's close this old issue: Bullet/examples/SharedMemory/PhysicsClientC_API.h is the API. |
See https://code.google.com/p/bullet/issues/detail?id=43&colspec=Modified%20ID%20Type%20Stars%20Status%20Owner%20Summary
The text was updated successfully, but these errors were encountered: