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: 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!

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.

Using Background Images in Blender

While I was building the iPhone4 model, I began to realize that my proportions were off.  The Home Button seemed out of place. The front camera and speaker were not quite the right shape.  The buttons and breaks in the seems were a bit off from where they needed to be… the list went on and on.

It turns out that blender has a feature for exactly this problem, background images.  This lets you set an image as the background to your modeling space, thus allowing you to match up your mesh boundaries to features of the image!  Obviously, care has to be chosen when choosing these kinds of images, but assuming you can find fairly orthogonal shots of the front, back, left, right, top and bottom, you can model very precisely from actual photographs.

Ok. How can you set background images?  Go to your view menu and click properties. That should pop up a properties pane.  Near the bottom of the properties pane, you’ll see the widget for background images.  Check the check box and click “Add Image”.  Select which view you’d like this image to show up in (front, left, right, back, etc) and expand the “Not Set” arrow. That should give you a little dialog box that’ll give you a file picker.

You can add an image for every orthogonal view, so when you hit a perspective key on the number pad, the appropriate background image is displayed.

After digging around the web for a while, I finally found a set of images that could help me re-tune my iPhone mesh… here’s the mesh with the “front” background image

N-Body Simulation

A long time ago, I created a simple animation using POV-Ray that simulated a Neptune-like planet that I named Augustus-Voltaire 4.  I used POV-Ray’s built-in programmatic texturing features to create a blue banded atmosphere that had white speckled high atmospheric clouds. You can see the video here… It’s got some pretty bad aliasing features due to compression, but you can get a basic idea of what I was going for…

Ultimately, I wasn’t happy with the result, so now years later, I’ve decided to take a stab at the problem again…  This time, armed with a much faster computer!  But how do you simulate turbulent, banded clouds?

I came up with a couple of different ideas for how to do it… but the only one that seemed to produce anything vaguely interesting was N-Body simulation.  Essentially, you assume that the atmosphere is a fluid and realize that fluids can be approximated with particles.  In the simulation, you throw a few thousand simulated particles which interact with each other in set ways (in my case, they all repel each other in an enclosed space).

I wrote the simulator in Java… and is kind of slow.  Here is my first real attempt… it took about 18 hours to render.  The source is too large to include here in the post.  If you’re interested in seeing it, drop me an email.

In this simulation the Red and Blue components of the color describe its mass.  The redder the particle, the heavier it is.  The Green component of the color is controlled by how fast the particle is going.   I introduced a force pushing through the center.  The intensity tapers off as you get closer to the top and bottom.  That the simulation quickly reached a form of equilibrium…. which is kinda cool, but doesn’t make for very interesting weather patterns.

I noted as I watched this run, was.. the particles tended to segregate themselves based on mass.  The heavier stuff accumulated near the center of rotation and the lighter stuff was pushed out to the edges.

In my second N-Body simulation, I used far fewer particles but made each particle way more massive.  I also changed the shape of the force pushing through the center of the simulation, making it much more narrow.

Once again, you can see that we quickly reach a stable pattern.  This one seems to have much more circulation though.  It seems like bigger particles are the way to go.   I have 2 more avenues to explore as far as particles go…

  • Make the simulatiion have a 3rd generation.  This aught to cause different masses to group in layers. That might be visually interesting.
  • Add more complex ambient forces than the simple down-the-middle force.

Smoke Simulation and the Make Human Project

Over Thanksgiving, I spent time back in Miami, where I grew up.  During that time I essentially took a break from everything… including projects.  However… I did find some interesting material regarding 3D that I made note of to try…

First, check out this tutorial on Blender Smoke Simulation!

I’m pretty impressed with the tutorial.  I need to try to make something that uses this sweet feature!

The 2nd thing is the Make Human project.  Essentially it’s a programmatic way of generating human meshes.  It turns out that I have a very important use of this project… In the first Little Robots animation, I need hands, arms and legs.  Hopefully I’ll be able to use this project for the initial meshes! It’ll save me a HUGE amount of time!

Hello Seña – The Script

Last weekend I worked out the first draft of “Hello Seña”, the script that I’ll use for the first Little Robots animation.  As I described in my post “Getting it Together“, the scene takes place just before our first Little Robot gets activated.

If you’re interested in reading the script… it can be found [here].

Originally I had planned on making the dialog very plain, but while writing the script, I was inspired to add a few dark elements…

RICHARD: It sounds like we are ahead of schedule then. What about the others? Have you heard anything else from them?

ONEMURI: No, I haven’t and it’s been a while.  I’m getting a little worried that something has happened.

The conversation pauses for a moment.  Richard leans back in his chair and exhales.

RICHARD: Well, even if they were found out, we’re all supposed to be isolated, right?  There’s nothing else that we can do but do our best.

From this excerpt, you can see that I’ve added a layer of secrecy to the overall mythology.  Onemuri and Richard have some secret timeline and they are colluding with others who seem to have gone missing.

An interesting challenge of this script will be that most of the dialog will be in Japanese.  Since I don’t speak Japanese but plan on voicing the Richard character in the story, this means that I’ll have a lot of verbal practice to look forward to.

My first Blender animation

I originally modeled this several months ago… but each of my renderings had little issues… first with lighting… then with camera clipping… I worked out the various issues but never actually went through the 10+ hours of re-rendering it at decent quality until now… here you go… my first blender animation!

The PAX 2011 Sorting Workshop

I was going through the PAX Prime 2011 program guide one last time before committing it to the circular file when a paper (picture right) fell out.

Yes, mofo. That paper is hand written. By me. Barbaric right?  So what exactly is this artifact?

There was a panel that I attended called “The Sorting Workshop”.  I was intrigued both by the Harry Potterness of the title and the fact that it was a writing panel at a game convention.  I wanted to be sorted!  Instead of being sorted into magical houses, however, the goal of the panel was to sort you into your best games related writing occupation (Journalism, PR, or Community Management).  Let me quote, verbatim, the description of the panel as found in the program guide:

Unicorn Theatre
The Sorting Workshop
3:00pm – 4:00pm
Writing Workshop: Journalism, PR, Community Managers Industry vets inflict writing on attendees to determine where in the industry an apsiring writer belongs. A game developer and a publicist kick things off with a 10-minute product demo that you get 20 minutes to write up. Then a panel of journalists, community managers, and publicists sort your writing samples into which field it aught to be in based on tone, content, and accuracy. You won’t be graded, but you might be mocked with dramatic readings of your sample. Whatever happens, you’ll have a chance to make industry contacts and learn the difference between writing for journalism, for community management, for marketing and for PR. Bring pens, pencils and a surface to write on (we recommend the PAX guide) – We’ll provide the rest.

Panelists include: AJ Glasser [Lead writer, Inside Social Games, inside Network],
Susan Arendt [Senior Editor, The Escapist], Dan Amrich [Social Media Manager, Ac-
tivision, Sue Bohle [Founder, The Bohle Company], Jon “Seg” Seggerson [Content
Programmer, Telltale Games]

The thing that made this panel awesome were the panelists.  All of the other panels that I attended at PAX were fluffy, comforting workshops that tried to make you feel good about yourself and your lack of ability.  I enjoyed that these professionals just kind of breathed real life into the presentation.  (They also weren’t afraid to brandish expletives. It was fucking rad)

We ran out of time before individuals could get properly sorted… so I will never know whether I’m destined for PR fame or community management… As a career software engineer, though, I suppose it doesn’t matter much in the long run…  Still.. if you happened to have been on that panel and are reading this… drop me a note!

PAX 2011 Redux

This year, I was fortunate enough to inherit a 3-day pass to PAX Prime 2011, courtesy of my long time friend and compatriot, Nick Hernandez.

Even though I’ve seen the various PAX episodes on PAtv, but nothing prepared me for the sheer magnitude of the expo.

To give you an example of what I’m talking about, here is a picture of the demo area for the game Prototype 2.  You can see, they didn’t just put up a projector to demo stuff… they built an entire helicopter prop with sounds… and this was on the tame side as far as booths go.

Probably the most extreme example of commercial promotion of a francise was Halo Fest.  Basically, it was a mini convention …. within a convention!  There were complex dioramas.. scale vehicles like this Warthog.. and TONS of space dedicated do game play.

This isn’t to say that PAX is not just some orgy of AAA title marketing… there are a LOT of for-the-community things… like the Classic Console Freeplay.  Ever want to play an original NES game but couldn’t afford it as a kid?  This is the place for you.

All in all, my PAX experience was awesome.  I am totally going back next year. Period.