Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Physac
#1
This is a standalone version of the Physac 2D physics engine ripped straight out of raylib-64. This version does not have any raylib dependencies (i.e. you can use the engine with vanilla QB64 graphics commands). As a bonus, it also contains the reasings library (Robert Penner's easing equations) and raymath (raylib math library).

There are some support functions as well. See include/support.bi for documentation.

There are 6 examples. 5 of them are for Physac and 1 for reasings.

Documentation:

Usage:

Copy the complete "include" directory to your project location.

And then (assuming your source files is at the root of the project location) do the following:

Physac
Code: (Select All)
$INCLUDE:'include/physac.bi'

reasings
Code: (Select All)
$INCLUDE:'include/reasings.bi'

raymath
Code: (Select All)
$INCLUDE:'include/raymath.bi'

[Image: screenshot2.png]

[Image: screenshot3.png]

[Image: screenshot4.png]

[Image: screenshot5.png]
[Image: screenshot6.png]
[Image: screenshot1.png]

Get the latest version directly from GitHub: raylib-64-master.zip
Reply
#2
Fantastic - thanks! Now I just need a little time to do something with it  Cool
RokCoder - dabbling in QB64pe for fun
Reply
#3
I was just chatting with another user about 2D physics engines. Karma, the good kind, has struck. Thank you.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#4
AWESOME @a740g
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#5
Really nice, @a740g!  Man, than easings example is smooooth.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#6
I was playing around with this and discovered that CreatePhysicsBodyRectangle creates rectangles with very strange attributes. In the original C physics_demo.c, try replacing -

Code: (Select All)
CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
with -

Code: (Select All)
CreatePhysicsBodyRectangle(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(20, 80), 10);
Those rectangles just roll and roll and roll! It's very odd as the library works pretty well with regular polygons but the momentum on those rectangles is off the scale!
RokCoder - dabbling in QB64pe for fun
Reply
#7
(10-02-2024, 10:50 PM)RokCoder Wrote: I was playing around with this and discovered that CreatePhysicsBodyRectangle creates rectangles with very strange attributes. In the original C physics_demo.c, try replacing -

Code: (Select All)
CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
with -

Code: (Select All)
CreatePhysicsBodyRectangle(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(20, 80), 10);
Those rectangles just roll and roll and roll! It's very odd as the library works pretty well with regular polygons but the momentum on those rectangles is off the scale!
Big Grin Yeah. That is crazy. There is an updated version of the library. I'll check if the updated version works better.
Reply
#8
(10-02-2024, 11:55 PM)a740g Wrote: Yeah. That is crazy. There is an updated version of the library. I'll check if the updated version works better.
As it stands, the little tower building project I had in mind is a no-go. It needs rectangles (and possibly more control over the friction, restitution, etc parameters). I've attached my little testbed project to give an idea of where it was going... and an even better idea of why it isn't going there any more Big Grin

.zip   physics-tower-game.zip (Size: 70.63 KB / Downloads: 19)
RokCoder - dabbling in QB64pe for fun
Reply
#9
Updated library to the latest version of Physac and ported all Physac examples. Project is now hosted on GitHub. Download link is in the first post.

@RokCoder, I still did not find a solution to your CreatePhysicsBodyRectangle issue. However, I'll keep looking. Will let you know if I find anything.
Reply
#10
I've been looking over the underlying code for the Physac engine, and its seems that it is a refactored version of the code I ported to QB64. 

Can it process objects with concave surfaces? The original code that this seem to be based off of, had a function set the rotation and removed any concave sides of the polygon, if you didn't run this after polygon creation, the object would behave erratically.  I don't see the function here. Perhaps culled as unnecessary?

Concave objects would be awesome, because then you could create things like gears and simple machines. I have kinda worked around this by joining two bodies with very rigid joints, but its not a very good workaround.

It's cool that it uses threads so that should help with speed. 

It has nifty little function to shatter the polygons, could be useful for impact damage.

The only down side is that it doesn't seem to have have joints. Maybe I missed it? Joints can add a lot to physics engine, you can look at some of the examples on my github. Perhaps that is something that they will add later on? Perhaps porting that back to c++ might be an option?

Great job on bringing that to QB64! I will be keeping an eye on this in the future.
Reply




Users browsing this thread: 1 Guest(s)