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.
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!
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: http://stackoverflow.com/questions/1061005/calling-objective-c-method-from-c-method
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!
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.