I've finally got a copy of my C port of box2d lite up on Github. Please make and submit changes. Included is a Playdate SDK demo of movement, friction, drawing, joints, etc.
Feel free to discuss here, ask questions, etc. I'll try to get some time together to create documentation for the library. For now, the demo will have to be that.
Performance is best I've seen so far, as far as physics engines are concerned on device. Good performance up to about 8 active bodies in world.
How would you suggest making a multi-segment "joint" between two bodies? Is that possible? Am thinking along lines of a chain or rope connecting two things...
I experimented a bit with that for my prototype Lil' Crane and I didn't find a satisfying solution. Box2d lite is well suited for the Playdate because it is limited in scope which also mean that it is a bit limited to do stuff like strings.
In the end I ended up using a single joint for a whole rope and just render the rope with a curve if the distance between bodies was less than the length of the joint.
If you want the rope or chain to actually collide with the other bodies, you need to create a series of slim bodies and link them with show joints. But the issue is that is will not be great for performance and I think bodies will very easily get crazy and unstable. I could work but it will need a lot of tweaking.
Your idea of rendering a curve even though the joint is a line is excellent, I may well do that in conjunction with the "softness" property, which as far as I can tell allows the joint to stretch. Will try to come up with a "droop" curve for the rope if it's not being stretched...
Hello. Appreciate this isn't a Lua and C general help forum, but wondered if you could help point me in the right direction. How do I include things like this into my project? I'm a Mac user, so not sure if the makefile is relevant to me. Do I need to use a builder?
Thanks.
Edit: Tried it in Nova and it works perfectly. Thinking I need a builder for VS Code. I'll use Nova in the meantime. Thanks for sharing.
Edit 2: Is it possible to get the force of a collision? Or the velocity?
I am trying to use it in my project but I am a linux user, how can I add this to my vscode project? When I import to simulator allways says that playbox is not found.
Thanks so much
Check the Makefile in the example and main.c for how to add the API to the Lua runtime. Nova handles building this for you and I highly recommend it for Playdate dev.
I'm also trying to get this working with Nova, however I'm running into errors on building. I'm pretty new to developing on Mac, so not quite sure where my issue is. I downloaded the directory from GitHub, loaded it in Nova and tried to build with the Playdate extension, however I get this error. Do you have any ideas? I appreciate all the work you've done on porting this!
Task Terminated with exit code 1
/usr/local/bin/arm-none-eabi-gcc
detected_OS is "Darwin"
mkdir -p build
mkdir -p build/dep
mkdir -p `dirname build/extension/main.o`
/usr/local/bin/arm-none-eabi-gcc -g -c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -D__FPU_USED=1 -O2 -falign-functions=16 -fomit-frame-pointer -gdwarf-2 -Wall -Wno-unused -Wstrict-prototypes -Wno-unknown-pragmas -fverbose-asm -Wdouble-promotion -ffunction-sections -fdata-sections -Wa,-ahlms=build/main.lst -DTARGET_PLAYDATE=1 -DTARGET_EXTENSION=1 -MD -MP -MF build/dep/main.o.d -I . -I . -I /Users/ME/Developer/PlaydateSDK/C_API -I extension -I playbox2d extension/main.c -o build/extension/main.o
make: /usr/local/bin/arm-none-eabi-gcc: Bad CPU type in executable
make: *** [build/extension/main.o] Error 1
The file /Users/ME/Downloads/playbox2d-main/playboxdemo.pdx does not exist.
Task “Build” exited with a non-zero exit status: 1.
But I get this error when I open it with the simulator
11:28:19: Loading: OK
update failed: main.lua:58: attempt to index a nil value (global 'playbox')
stack traceback:
main.lua:58: in function 'setup'
main.lua:8: in function <main.lua:6>
Edit: I'm able to get it to run on the simulator on Linux, just not on the simulator on Windows.
Something is not setting up playbox correctly. Specifically, the registerPlaybox() method looks like it's never called because that is what makes Lua aware of the playbox global.
I didn't run into any problems related to 'registerPlaybox()' (just a datapoint)
(It's a wonder what some regular sleep and no interruptions can do - have been on vacation since Wednesday) - I finally had time to attempt setting up the Playdate SDK for mixed C/Lua builds on both an M1 Mac Mini and my regular Windows workstation, and have the playbox2d demo built, up and running on both (had to tweak the sources a bit to get Visual Studio 2019 happy, it didn't like 'unknown size' for a type of 'void*' or unsized array declarations): VS2019 tweaks .
This is neat stuff! I can't wait to build a minigame/easteregg with it.