Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-10

Writing Pascal Physics and Vectors

13 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

I've been working on writing Pascal bindings a friendly object orient interface to a few open source projects. I have put together Chipmunk2D, NanoVG, MiniMP3, and SDL2 for rendering nice real time platform independent programs where fast logic can be easily controlled with physics or fast graphics can easily be rendered.

If you are interested in hearing more, I've put up a quick and dirty video of one of my test scene that precisely detects points of contact and the forces behind them at the page below.

https://www.getlazarus.org/videos/physics/collisions/

Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a Discord channel.

DougC
to Anthony Walter

I would be helpful if you could meld this work into other Pascal-based efforts, such as the Castle Game Engine. I don't know the details of CGE but if it could use more of this type of functionality, why not make your work even more useful by connecting up with CGE?

Doug C.

---- On Fri, 15 Oct 2021 18:18:13 -0400 Anthony Walter via fpc-pascal wrote ----

I've been working on writing Pascal bindings a friendly object orient interface to a few open source projects. I have put together Chipmunk2D, NanoVG, MiniMP3, and SDL2 for rendering nice real time platform independent programs where fast logic can be easily controlled with physics or fast graphics can easily be rendered.

If you are interested in hearing more, I've put up a quick and dirty video of one of my test scene that precisely detects points of contact and the forces behind them at the page below.

https://www.getlazarus.org/videos/physics/collisions/

Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a Discord channel.

Ched
to Anthony Walter: I've been working on writing Pascal bindings a friendly object orient interface to a few…
Fade := Fade * Fade * Fade * Fade * Fade;
Why not Fade:=sqr(sqr(Fade))*fade ?

Cheers, Anthony, Ched

Le 15.10.21 à 22:18, Anthony Walter via fpc-pascal a écrit :

Show quoted text 18 lines
I've been working on writing Pascal bindings a friendly object orient interface to a few open source projects. I have put together Chipmunk2D, NanoVG, MiniMP3, and SDL2 for rendering nice real time platform independent programs where fast logic can be easily controlled with physics or fast graphics can easily be rendered. If you are interested in hearing more, I've put up a quick and dirty video of one of my test scene that precisely detects points of contact and the forces behind them at the page below. https://www.getlazarus.org/videos/physics/collisions/ <https://www.getlazarus.org/videos/physics/collisions/> Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a Discord channel. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Darius Blaszyk
to Anthony Walter: I've been working on writing Pascal bindings a friendly object orient interface to a few…

Hi Anthony,

Can you put the link up to the source code please?

Rgds, Darius

Sent from my iPhone

Show quoted text 13 lines
On 16 Oct 2021, at 00:27, Anthony Walter via fpc-pascal wrote:  I've been working on writing Pascal bindings a friendly object orient interface to a few open source projects. I have put together Chipmunk2D, NanoVG, MiniMP3, and SDL2 for rendering nice real time platform independent programs where fast logic can be easily controlled with physics or fast graphics can easily be rendered. If you are interested in hearing more, I've put up a quick and dirty video of one of my test scene that precisely detects points of contact and the forces behind them at the page below. https://www.getlazarus.org/videos/physics/collisions/ Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a Discord channel. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Unknown author
to Darius Blaszyk

ummm... the source code is on the linked page ;)

Darius Blaszyk wrote 8 lines
Can you put the link up to the source code please? > On 16 Oct 2021, at 00:27, Anthony Walter via fpc-pascal > wrote: > [...] > https://www.getlazarus.org/videos/physics/collisions/ > > Source code for the test scene is included on that page. [...]
NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*
Darius Blaszyk
to Unknown author

Not entirely, a link to the wrappers is missing, unless I overlooked it. A link to repository for a complete demo would be useful.

Darius

Sent from my iPhone

Show quoted text 20 lines
On 16 Oct 2021, at 12:59, wkitty42--- via fpc-pascal wrote:  ummm... the source code is on the linked page ;) > On 10/16/21 2:58 AM, Darius Blaszyk via fpc-pascal wrote: > Can you put the link up to the source code please? >>> On 16 Oct 2021, at 00:27, Anthony Walter via fpc-pascal wrote: >> [...] >> https://www.getlazarus.org/videos/physics/collisions/ >> >> Source code for the test scene is included on that page. [...] -- NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!* _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Anthony Walter
to Darius Blaszyk

If you are running x64-86 Linux, would like to get my code you can join my Discord channel at the link below. Windows and Mac users will need to have cmake and the ability to build with it, but they're invited as well.

https://discord.gg/NuTDatAz

I am making a lot of changes, so I don't want to create a public git repo just yet. Currently I am working on writing rope and water physics demos, and will probably refactor everything before I do my first git check in.

Ryan Joseph
to Anthony Walter: I've been working on writing Pascal bindings a friendly object orient interface to a few…
On Oct 16, 2021, at 5:18 AM, Anthony Walter via fpc-pascal wrote: Source code for the test scene is included on that page. If you want to help, I need to bounce ideas off people as well as test on Raspberry Pi, Mac, and Windows. Message me and maybe we can try to meet on a Discord channel.

Just seeing this now but this looks pretty useful. I once made a Pascal wrapper for Box2D but this looks like a better more complete solution. Do you have the Pascal unit for Chipmunk2D where we can download and try it?

Regards,
Ryan Joseph

Anthony Walter
to Ryan Joseph

Thanks for the interest Ryan. I am preparing to push my code to a public git repository with a FOSS license. In order to get this out soon it will be broken into a few releases.

The first release, which is 100% done but needs accompanying documentation, might be out in a week's time. It includes an OpenGL vector graphics system based on NanoVG, with a friendly object oriented interface and some examples programs. I am also writing a basic widget system to render controls such as buttons, sliders, and text boxes that are rendered by the same vector graphics system. This will be in the first release

Here is a small selection of the examples / demos I've written thus far.

Text paint: https://streamable.com/m4e4qn
Curtains: https://streamable.com/6o5y5o
Mouse track: https://streamable.com/uk8ak7
Crowd walk: https://streamable.com/mc3he6
Fire spark: https://streamable.com/fm02c4

The second release will include the complete physics system. It's about 80% done and again will be a friendly object oriented wrapper around the Chipmunk2D physics library. I will add to the same documentation system I am writing for the first release.

The third release will likely include a full object oriented wrapper about the Nuklear widget library using my vector graphics system as the renderer. It hasn't been started yet.

If anyone is interested, here is the interface to the graphics system. It centers on the idea of an ICanvas interface I've designed:

https://gist.github.com/sysrpl/6119ed313c8382004131761d6e292b3b

Ryan Joseph
to Anthony Walter
On Oct 29, 2021, at 4:25 AM, Anthony Walter via fpc-pascal wrote: Thanks for the interest Ryan. I am preparing to push my code to a public git repository with a FOSS license. In order to get this out soon it will be broken into a few releases.

Nice let us know when it's finished.

What I did some years ago was make a plain c wrapper around Box2D so that I could then call it from Pascal (it was c++ originally). I think the library you used is already C so it should be easy to call from Pascal anyways event without the OOP wrapper. Much better than Box2D which was C++ only.

https://github.com/thealchemistguild/Box2DC

Regards,
Ryan Joseph

Anthony Walter
to Ryan Joseph

Ah, so that was you who wrote the C wrapper? I saw that a while ago and considered using it, but after looking at and exploring how Chimpmunk2D works, I decided it was smaller, pretty darn good. That and Chipmunk2D is already C, so very little work was needed from me to convert it to work with Pascal.

Again, the physics part will be in my second release. The first part is just getting the vector graphics and a minimal GUI toolkit in OpenGL working. That plus an overview and reference website similar to my https://docs.getlazurs.org website.

If anyone cares to know more, here is a brief description of how my object oriented wrapper around Chipmunk2D physics is organized.

ISpace is the base object to work with physics. If you use the TPhyiscsScene class it's created and managed for you automatically. ISpace provides properties for controlling gravity, bodies, and joints. There is one ISpace object per physics simulation.

IBody objects are added to ISpace using ISpace.NewBody, ISpace.NewDynamic, and ISpace.NewStatic methods which create kinematic, dynamic, and static bodies respectively. Kinematic bodies react to collisions with each other and are affected by forces such as gravity. Dynamic bodies can be moved manually by the programmer, but are otherwise unaffected by forces and collisions. Static bodies cannot move but kinematic bodies may bounce off them.

IShape objects are added to bodies using IBody.NewCircle, IBody.NewRect, IBody.NewSegment, and IBody.NewPolygon method. A body by itself has no shape. Its shape is defined by the shapes you add to it. Shapes within the same body do not collide with each other or move with respect to the other shapes within the body. Each shape within a body can have different friction, density, and elasticity (or bounciness). The mass and center of gravity of a body is calculated by its constituent shapes.

IJoint includes a list of several joint types (I will not list them all here), and they can be used to connect two bodies together. Some joint types are motors, other are springs, and some are hinges or pivots. Collisions between bodies connected by a joint can be set to be ignored for those two bodies.

IArbitors allow you to either detect and handle collisions between body types you define. You can ignore them if you simply want the physics system to handle collisions for you.

Masks can be applied to body types, allowing you to say which bodies can collide with which other bodies. For example, if you were writing a game you could setup enemy bullets bodies to pass through enemy bodies using a simple mask. The enemy bullet bodies could then be setup to collide with the player body and wall bodies.

There is a lot more to the physics system, but my object orient design, plus some documentation and examples ought to get most people running in short order.

I have been mostly working on the graphics portion for the past week and haven't been working with the physics system in that time. Last time I was working on it I was trying to figure how how to make a decent rope. I am not at all satisfied with my initial work, and maybe someone can help me get rope physics working better, but below is the result of my first attempt.

Rope test : https://streamable.com/lli866

I'll put all the information above and the source code online in a git repository soon with a FOSS license. If anyone wants to help, let me know. Join me in the discord channel listed in my initial message, or see me on liberachat irc in the #fpc channel.