Monthly Archives: February 2012

screw this noise, libsdl to the rescue!

I’d spent the last week beating my head trying to learn the dark arts of programming for the OS X.  I had basically gotten a window to open up… but that was it.  Did i really want to learn this? or was this simply a means to an end?  I’m guessing it’s the latter… there has to be a better solution than this. Turns out there is… libsdl.

It had all but skipped my mind… the Simple Directmedia Layer.  It’s basically a platform abstraction library that lets you write media-rich native apps without worrying about what the underlying architecture is.

I first tried using it about 5 years ago and was fairly impressed.  It’s easy to use and has a whole mess of language bindings.   I think I’ll be doing more of my n-body stuff using this lib as the front end instead of trying to learn all of the cocoa specifics.

Hopefully, this time next week I’ll have something that’s downloadable, runnable, and interactive!

Objective C, C++ and OpenGL

I started working on converting my N-Body simulation code over to C/C++ and realized that I had no idea how I’d actually display the results.  So… it was time to learn a little about displaying stuff in OS X.

One thing that struck me as ungainly was having to use XCode when really all I wanted to do was get myself a window and draw to it. This lead me to this awesome blog post showing a very minimalist Cocoa app.

With that start, I thought that I’d try to do most of my work in C++ instead of Objective C… so how does one do THAT in OS X?? There seems to be a bunch of literature about how to make C++ calls from Objective C… but not the other way around, which is really what I want to do… I want my C++ code to be the driver of the application and use Objective C to pass events and display results… It was stackoverflow to the rescue with this article:

Essentially, you write yourself a C header with some forward declarations for methods that are later declared in a .mm file.  Assuming that you’re coding in C++ instead of C, compile with g++ or you’ll get a lot of strange missing symbols at link-time if you use plain old gcc.

Once I have things going smoothly, I’ll post the skeleton code up on github!

The Lady of Thorn Keep, Part 3

Good friend and co-conspirator, Stephanie Stone has completed the third part of our on-going collaboration!

You can see from the image to the right, we’ve finally hit some action. As always, Steph does an awesome rendering; in this case, of Sorcha facing off against the Warlock, Fenris Wolfborne.

I’ve updated the story page to include the third part of our adventure! As always, comments and discussion are always welcome.

You can contact Stephanie and see more of her art at her Deviant Art account!

Wrapping N-Body Simulation

Continuing with my previous efforts, I updated my N-Body simulation code to not require the edges of the simulation to be boundaries.  Instead, the edges now wrap.

That might seem like a pretty simple change, but the code involved gets a bit complex…

For example, say you’re calculating the force between particle A and some other particle B and particle B’s force is wrapped around the screen, you need to basically translate B to the other side of A and do your calculation…

If you’re in a corner… say the upper right, you’d have to do this with all particles above and all particles to the right of you, so you’d need to do two sets of transformations.

The process is slow enough with 100,000 points that I need to think about moving from Java, which is what the simulation is currently written in, to something speedier, like C.