BBC BASIC for Windows
Programming >> Libraries >> BOX2DLIB library (beta) released
http://bb4w.conforums.com/index.cgi?board=libraries&action=display&num=1388243972

BOX2DLIB library (beta) released
Post by admin on Jan 28th, 2013, 5:11pm

I'm pleased to announce a beta release of BOX2DLIB.BBC, the BB4W wrapper library for the Box2D Physics Engine:

http://tech.groups.yahoo.com/group/bb4w/files/Box2D/box2dlib.zip

The ZIP file contains BOX2DLIB.BBC, Box2D itself (as BOX2D221.DLL), BOX2DDBG.BBC (which supports the DebugDraw interface) and an example program 'Hello_Box2D.BBC'. BOX2DLIB.BBC, BOX2DDBG.BBC and BOX2D221.DLL must be copied into your BB4W libraries (LIB) folder; you will require Adminstrative Privileges to do that.

Hello_Box2D.BBC reproduces the functionality described in Chapter 2 of the online Box2D manual here:

http://www.box2d.org/manual.html#_Toc258082968

It incorporates a large amount of descriptive text, adapted from that in the manual, which should be read as an introduction to physics engines in general and Box2D in particular. Further details of Physics Engines can be found on Wikipedia:

http://en.wikipedia.org/wiki/Physics_engine

This beta release of the library provides extensive support for the most important Box2D features, including:

A total of twenty sample programs are provided, each illustrating a few features of Box2D. These are supplied as the menu program SAMPLES.EXE which also saves the source files to its directory when run:

http://tech.groups.yahoo.com/group/bb4w/files/Box2D/SAMPLES.EXE

The sample programs all use the DebugDraw interface to display their output.

Richard.



Re: BOX2DLIB library (beta) released
Post by ScriptBasic on Jan 16th, 2014, 5:49pm

Richard,

Is there a chance that the files being pointed to on Yahoo Groups files repository be made available here? The Yahoo mailing list/site seems closed and no way to access them as a non-member.

I'm curious what your thoughts are about using Chipmonk 2D Physics instead?

John
Re: BOX2DLIB library (beta) released
Post by admin on Jan 16th, 2014, 9:27pm

on Jan 16th, 2014, 5:49pm, ScriptBasic wrote:
Is there a chance that the files being pointed to on Yahoo Groups files repository be made available here?

Which particular files are you looking for? I copied what I thought were the most important ones into the Wiggio group's folder, from where they can be downloaded even by non-members. But it was a time-consuming process and I only transferred a small subset.

Quote:
The Yahoo mailing list/site seems closed and no way to access them as a non-member.

Only members can access the files, but there's nothing stopping you joining specifically for that purpose. Membership is still open to anybody, even though posting messages is currently disabled.

Quote:
I'm curious what your thoughts are about using Chipmonk 2D Physics instead?

A huge amount of effort went into making Box2D accessible from BBC BASIC, and as it is I'm somewhat aggrieved that (despite the initial enthusiasm) so little use has been made of it. There's not the slightest chance that I would consider spending time interfacing to an alternative 2D physics engine. cry

Can I take this opportunity to ask all BBC BASIC users to take another look at Box2D and the amazing things you can do with it. A couple of compiled BBC BASIC Box2D demos are here:

crates.exe
SAMPLES.EXE

And here's the YouTube video of the Ball Bearing Clock:



Richard.
Re: BOX2DLIB library (beta) released
Post by ScriptBasic on Jan 17th, 2014, 01:19am

Great stuff Richard.

I have downloaded the libs and examples and look forward working with it.

Update

I can get the Box2D chain example to run from the IDE but it can't find the BOX2DLIB.DLL if run from the compiled form. I even tried putting the DLL in the same directory as the program.


Re: BOX2DLIB library (beta) released
Post by admin on Jan 17th, 2014, 08:41am

on Jan 17th, 2014, 01:19am, ScriptBasic wrote:
it can't find the BOX2DLIB.DLL if run from the compiled form. I even tried putting the DLL in the same directory as the program.

To successfully embed the DLL in the compiled EXE it must be in one of two places: either in the BB4W library directory (@lib$) or in the same directory as the program (@dir$) - or in a sub-directory of one of those places.

So long as that is the case the only remaining requirement is to ensure that the DLL is correctly embedded when the program is compiled. The best way is probably to incorporate a REM!Embed compiler directive in the program, but if you don't want to bother with that you can simply add the DLL manually in the Compile dialog (Add @dir$ or Add @lib$ buttons).

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin1.html#directives
http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin1.html#embedded

Richard.
Re: BOX2DLIB library (beta) released
Post by ScriptBasic on Jan 17th, 2014, 4:07pm

The compile dialog showed the two library resources being included. All the library related files where put in the LIB directory of BBC4W. When the compiled app didn't work, I copied the DLL to the same directory as the .exe. I then copied it to the sysWOW64 directory with no luck. Works fine running from the IDE.


Re: BOX2DLIB library (beta) released
Post by admin on Jan 17th, 2014, 4:23pm

on Jan 17th, 2014, 4:07pm, ScriptBasic wrote:
The compile dialog showed the two library resources being included.

There should be three embedded resources in total for CHAIN.BBC to work. If your Compile dialog shows only two that will be why it isn't working!

Here's a version I compiled: chain.exe

And for those who missed it the first time round, here's Svein's 'Pintograph' drawing machine with my added Meccano (TM) graphics: pintograph.exe

Richard.

Re: BOX2DLIB library (beta) released
Post by ScriptBasic on Jan 17th, 2014, 5:41pm

Your chain.exe works fine. I added the BOX2DGFX.BBC to the lib include listbox (making 3 resources) but I'm still getting the same error.

User Image

I checked the temp directory created and there was no BOX2D221.DLL present. I copied from the LIB but it still doesn't work.

Can I assume that compiling BBC4W applications really means packing up the interpretive files into a bundle and executed with the runtime when uncompressed by the packaging code?

Update

I added the BOX2D221.DLL to the project and it now works from the exe created directory. Just to undo the confusion, these are library files needed to make chain.exe work standalone.

BOX2D221.DLL
BOX2DDBG.BBC
BOX2DLIB.BBC

FYI - When running the chain.exe it uses 50% of of both of my CPU cores. I would guess if I had a single core processor, I would be running at 100% CPU utilization.


Re: BOX2DLIB library (beta) released
Post by admin on Jan 17th, 2014, 7:59pm

on Jan 17th, 2014, 5:41pm, ScriptBasic wrote:
Can I assume that compiling BBC4W applications really means packing up the interpretive files into a bundle and executed with the runtime when uncompressed by the packaging code?

Indeed so.

Quote:
I added the BOX2D221.DLL to the project and it now works from the exe created directory.

As I mentioned, the safest method is to add a compiler directive in the source program:

Code:
REM!Embed @lib$+"BOX2DLIB.BBC", @lib$+"BOX2DDBG.BBC", @lib$+"BOX2D221.DLL" 

Quote:
I would guess if I had a single core processor, I would be running at 100% CPU utilization.

It shouldn't - there's a WAIT 1 (10 millisecond sleep) in the main loop. On my Windows 8.1 laptop (1.9 GHz Intel Core i7) it uses about 8% CPU. Does Wine support hardware-accelerated graphics?

Richard.
Re: BOX2DLIB library (beta) released
Post by ScriptBasic on Jan 17th, 2014, 9:55pm

Quote:
Does Wine support hardware-accelerated graphics?


Supposedly for OpenGL/SDL. Not sure what Box2D is using.


Re: BOX2DLIB library (beta) released
Post by admin on Jan 17th, 2014, 10:02pm

on Jan 17th, 2014, 9:55pm, ScriptBasic wrote:
Supposedly for OpenGL/SDL. Not sure what Box2D is using.

GDI+ for the Debug Draw interface (which is what chain.bbc is using).

The idea is to use Debug Draw during development, because it makes everything 'visible', but when all the physics is working as it should you switch that off and then render the final graphics however you prefer.

The crates and pintograph examples happen to use a mixture of custom assembler and GDI (in the BOX2DGFX library), but could just as well use SDL or OpenGL, in principle.

Richard.