Sunday, June 26, 2011

Box2D game progress

Last night I wrote down a list of things I wanted to get nailed down for my Box2D-based game.

  1. Create a test arena
  2. Create a character actor patterned off of the example written by the libgdx author Mario Zechner (Box2D Platformer Character Controls) and gain understanding of sensor usage.  Additionally, character will have a single arm (ie. an aimed gun) that will shoot projectiles.
  3. Use raytracing to detect where an impact will occur.
  4. Define projectiles
  5. Create response (explosions) at impact points.
  6. Set surface impacts based on the surface - different responses for different surface types
  7. Have effects 'stick' at impact points
  8. Implement a button the character can stand on that opens a remote door.  Closes when the character leaves the button
  9. Create generic actor types that the character can interact with: boxes, elevators, varying gravity fields etc.
I made it through a few of these items and continue to learn lots of cool new stuff.

Creating a test arena was easy enough.  It just consisted of defining a world and supplying static platforms and walls at the periphery.  In the process I got a very good understanding of how OrthographicCamera and PerspectiveCamera's projections work.  Zechner has a very informative and easy to understand overview here.

From there, I started work on the character actor.  The primary shape comes from Zechner's definition in the link above.  I took that and added an arm using a RevoluteJoint.  A RevoluteJoint simply pins two bodies together.  What tripped me up and took a bit of time was that the joint was very...rubber-bandish.  As the character dropped into the arena and the arm caught a platform edge, the arm would get 'stuck' but the character body would continue to descend... It looked like the joint was actually a rubberband.  Here's a picture of the weirdness in action.  The blue line shows the joint (also, I made the arm really long to make getting the effect to happen easier.)

After much debugging, including porting the SliderCrank test from the Box2D C++ TestBed project to libgdx, I finally zeroed in on the density as the culprit.  I had the density of the 'arm' body set to 0.001f.  Bumping this up to 0.5f got rid of the rubber-banding and things started behaving as expected.  This diversion cost me a few hours.

After that, I implemented the capability of firing two different projectiles based on the angle of the arm.  The angle is controlled via the keyboard (atm).  The rotation is implemented via a motor attached to the joint.  When the rotate CW key is pressed the motor speed is set to a predefined > 0 value, and < 0 when the rotate CCW key is pressed. 

When the user hits the 'fire projectile' button, any previous bullet is destroyed and a new bullet is created based on the orientation of the arm using transforms.  To do this, I first create the projectile and then offset the location based on the relation of where the arm was created.  The initial velocity is defined based on this as well.  Then, the velocity vector is rotated following the angle of the arm and the position / angle of the projectile is set according to the arm's transform.

On a side note, one somewhat neat thing about the operation of the character is that I give it a finite impulse upon every jump-key press.  This gives the character the type of motion that you see in the old arcade Joust which is pretty cool looking and fun to mess around with.  This gives me the idea to implement some sort of bird-wing-flapping game.

Here's the current state of the game using the built-in debug renderer.

Friday, June 24, 2011

Box2D and Eclipse

Well, after about an hour and a half of effort, scouring the Internet and some elbow grease (heh) I *FINALLY* have got the Box2D testbed to compile using Eclipse on my Windows 7 x64 box.  It's not all that straightforward.  Here's an outline of the steps you'll need to take:

1) Install Eclipse (duh?) and the CDT (C Development Tools)
2) Install MinGW & related gcc/g++
3) Install & build GLUT for Win32
4) Download Box2D source
5) Install CMAKE, tweak some of the output and have it create your build file

Details for those steps:

1) Install Eclipse and the CDT.  You can grab Eclipse from  I'm personally using the Helios release.  I grabbed the Java edition (a while ago, actually).  To install the CDT for C development support, open up Eclipse and go to Help > Install New Software...  Set the "Work with:" drop-down to all sites and enter "CDT" as the filter text.  Eventually you'll be presented with things to install.  I selected everything.  Easy peasy.

2) Install MinGW.  Go to and download and execute the installer.  In the installation options, select pre-packaged catalogues and when queried, select C++ compiler, MSYS Basic System, and MinGW Developer Toolkit. Easy peasy (again).

3) Install GLUT for Win32 w/MinGW support.  I followed the instructions up on which is actually a reference to  There are instructions there for downloading and building glut-3.7.6 from src files.  Follow steps 2 through 7 on that site.  You'll need to perform these steps using the MSYS Shell prompt installed as part of step 2.  If things work out correctly, you'll see the gear test demo.

The next thing is to be able to build from Eclipse.  Ensure your environment path references the /bin directory of the MinGW installation.  Create a new C++ project in Eclipse.  Set it up as an Empty project and select MinGW GCC from the Toolchain list in the right pane.   This initially did not come up for me until I added the f:\mingw\bin path to my environment.  Anyway, name the project "GLUTDemo".

Go to and follow steps 5c through 6c.  This will create a project containing Demo.cpp that will verify you can create a GLUT based project and that it works.

4) This is really simple.  Just hit the Box2d website at to grab the latest and greatest source.  I'm running v2.1.2.  Extract that to some directory on your machine.

5) Box2d requires that you have Cmake installed.  Grab that from and install it.  Next, you need to use it to configure the build attributes for Box2D AND specify that you want it to create stuff for Eclipse.  Open a cmd.exe prompt.  Yes, a cmd.exe prompt -- not the MSYS sh.exe.  Navigate to the Box2D Build sub-directory.  From here, enter the following:
cmake -G"Eclipse CDT4 - MinGW Makefiles" -D CMAKE_BUILD_TYPE=Debug ..
You can now go into Eclipse and import the resulting project.  The build will kick off and eventually fail when it gets to the link stage of the TestBed.  Don't fret.   Open up Testbed\CmakeFiles\Testbed.dir\link.txt and add the following to the end of the last line:

-lwinmm -static-libgcc -static-libstdc++
This clears up a few problems: undefined references to joygetdevcaps & some time functions, and also libgcc_s_dw2-1.dll / libstdc++-6.dll not being found when trying to start the resulting .exe.

Right-click on the project and tell it to build.  This time, a testbed.exe should be created and you can happily run it.


Sunday, June 19, 2011

Crypto alpha

Here's a screenshot of the mono-alphabetic crypto-tool that I wrote.  The example you see is the puzzle and solution to the first entry in Elonka Dunin's Secret Code and Cryptograms book.  The 'Fill' button fills in all of the substitution values with the '@' symbol.  This is used for reference when decrypting so you can see what letters are missing.  The % column shows the frequency analysis on the contents of the base text (updated when the analyze button is hit.)  The decrypt button takes the Base Text and substitutions each alphabetically character with the substitution from above.

Looking at the resulting Alphabetic Subtitution table, it doesn't appear that this key follow the Affine Cipher which I was half-expecting.  There is somewhat of a pattern, but overall it looks random.

Fun Saturday

I'm putting the music app on the back burner for now and am going to concentrate on an idea I've got for a 2D game.  So, I'm hitting the libgdx forums on BadLogic again and diving into how it's implementation of Box2D works (as well as the fundamentals of Box2D itself.)  Spent a good chunk of time yesterday doing that.

On Friday I received a book from my dad entitled "Secret Codes and Cryptograms" which has over 600 codes to crack.  Rather than dive directly into that, I decided to start writing a Java program for doing cryptographic analysis and decryption.  Since my knowledge of the Swing GUI is nil and I wanted a nice GUI to help me in my code-breaking attempts, I started looking into that.

I'm using the Eclipse IDE and found the WindowBuilder Pro plug-in.  WindowBuilder Pro is a Visual Editor for GUIs.  A couple of tutorials later I'm up to speed on that and am currently design my UI for decryption.  The idea is to give it the following capabilities: text entry, letter frequency analysis, 'guessing' based on letter frequency,  mono-alphabetic substitution and (maybe) brute force methods.  We'll see how it goes.


Saturday, June 4, 2011

Been a while since last post...

My progress toward the DrumLine app has pretty much tapered off, unfortunately.  I'm able to create drum tracks programmatically, but there are hiccups in playback due to thread priorities.  The rhythm plays back just fine around 80-90%... but then there are the bits and bobs that make it skip which is extremely annoying and frustrating.  In addition to that, my GUI skills are not all that, so the going is slow.

In other news, at work I've been delving into Mercurial.  It's very similar to Git in that it is a DVCS.  I think they complement each other really well -- if you know Git, you'll understand Mercurial.  I'm getting a lot more familiar with the DVCS concept and the workflows around it.  Not that I'll change how I've got things set up from a DVCS standpoint for my Slide Rule app, but it's cool to grok how things work.

I've got the bug recently to look into cryptography.  I've read about Bitcoin on several different sites including Slashdot, Ron Paul RSS feeds, and  It's got my curiosity piqued.  I discovered that there is an FPGA implementation of the Bitcoin algorithm.  I tried getting that going on a BeMicro SDK board I have from Arrow, but that little sucker does not have enough Logic Cells to implement the guys design.  I've got a DE2-112 board on loan from Arrow, but haven't revisited it (yet!).  Anyway, Bitcoin implements hashing algorithms and Merkle trees and I figured it would be fun to learn more about that stuff so I'm slogging my way through an introductory book on Cryptography.