Apollo Simulation Project: Hello CoreSimulation

You might have remembered that over the summer, I was very gung-ho about creating an Apollo spacecraft simulator. You also might have wondered what ever happened to that project. Well, do not fret, it is still alive, and will be taking some major shape soon.

Next semester, I will be doing my Senior Computer Science Thesis (CS499) on CoreSimulation. CoreSimulation is an open-ended generic and parallel simulation framework for Mac OS X that I am writing under the guidance of Professor Luke Olson. The framework, along with its many counter-parts, will be the back-end that will power the Apollo Simulation Project.

If you would like to see my abstract that Professor Olson approved, follow this link.

In addition, I will probably be taking AE498cl, which is an Aerospace Engineering independent study. With my AE buddy (and roommate) Christian, we will begin to develop the physics that surrounds the Apollo CM/SM (Command Module and Service Module) as it orbits Earth.

Isn’t this exciting?

Movie Review: Quantum of Solace

The other day (meaning like 5 weeks ago) I went and saw Quantum of Solace, the new Bond movie, with my roommates and Will. I was not a big fan of Casino Royale, so to be honest, I was not expecting much. However, I was delightfully surprised to find that it was actually quite entertaining.

It was entertaining probably most importantly because of the art direction. There was an incredible use of color, and combined with the editing, it made for a much more artsy Bond than I’m used to. Secondly, it had action. It wasn’t a ton of womanizing, as Bond movies often are, but it actually had some good, guy like action. In a movie, explosions are always cool. I also thought that the cinematography was well done. It was much more like the Bourne series — upclose and jerky — and like that.

A good movie watched with good friends = good time. I recommend this movie if you are looking for some classic entertainment with some additional artsy goodies.

Kevin’s movie rating:

I would watch it again

Movie Rating Key:

  1. Best movie I have ever seen
  2. Absolutely incredible
  3. Pretty darn good
  4. I would watch it again
  5. Good, but only time I am seeing it
  6. Disappointing
  7. Not very good
  8. Horrendous
  9. Shouldn’t have been made

Nerd tattoos

I walked into the ACM office today, and on our whiteboard was a list of tattoo ideas. It’s a club of nerds (myself definitely included), so the list is quite hilarious:

  • Turnip
  • Tattoo of you getting tattoed
  • USB port
  • Human genome
  • Map of Middle Earth
  • Trogdor
  • Trogdor + 1
  • 09 F9 11 02 9D 74 E3 5B
    D8 41 56 C5 63 56 88 C0
  • Resistor color code chart
  • List of primes (expandable)
  • TCP Header fields and/or UDP, IP, 802.1Q, etc
  • Hobbits is gay
  • Gandalf the Gray/white/red/turquoise
  • a dwagon + 7
  • vim/emacs cheat sheet
  • Nano/pico cheat sheet
  • Linux kernel API
  • Win32 API
  • DeCSS source
  • Blu-ray codes
  • Regex cheat sheet
  • .NET API
  • “import shakespeare”
  • Map of Siebel, UIUC
  • Map of some steam tunnels
  • Maxwell’s equations

To say the least, this list is hilarious.

OpenGL on the Mac (Part 2): Building GLSL Shaders

Two of the coolest things (I think) you can do in OpenGL are vertex and fragment shaders. Unfortunately, however, debugging these things at run time can be quite a pain. Or if you want to see a change you’ve made in the shader code, you have to recompile your program, run it, only to find that you forgot a semi-colon or you misspelled something.

But I have good news for you! Along with Apple’s Developer Tools comes a program called OpenGL Shader Builder. It is exactly as you suspect: a dedicated workspace for creating, debugging, and testing vertex and fragment shaders. You don’t have to write a program and write all the right OpenGL code to bring the shader in. All you have to do is write shader code.

The point of this post is to give an introduction to OpenGL Shader Builder, and to do that, I am going to be using the sample code found at the following Lighthouse 3D tutorial, which will allow us to map a texture onto a sphere with lighting.

So the actual GLSL code itself is not the important part, but rather the important thing is that you can use your Mac to debug shaders without having to do a bunch of work. So let’s get started.

Let’s get started: Starting up OpenGL Shader Builder

The first step is to make sure you have Apple’s latest set of develop tools. To get those, click here. When you’ve installed the developer tools, open your developer folder (usually /Developer), go to Applications, go to Graphics Tools, and then open OpenGL Shader Builder.

When it launches, you will see it is split into four sections:

  • Program: Includes the list of all the shaders in your project (you can have multiple shaders and what not), and also allows you to set things like how the test geometry is going to be drawn, etc.
  • Render: Besides the editor, this is where you’ll be spending most of your time. It just shows some geometry of your choosing (plane, sphere, teapot, etc) with your shaders applied.
  • Textures: Here’s where you “load” textures. Basically you just tell OpenGL Shader Builder about some pictures you want to use as textures, and the type of the texture (cube map, 2D, etc).
  • Symbols: Displays a list of all of the changeable variables in rendering your shader (such as GLSL uniforms). Typically, you’ll use this to change what texture you want to be used, or where lights are.

For more on this stuff, see Apple’s documentation on OpenGL Shader Builder.

Adding a vertex and fragment shader

So what we are going to do now is add a vertex and a fragment shader. The code I am using is from the Lighthouse 3D listed above.

To create a new shader, simply go under the File menu, go to New, and then select either “GLSL Vertex Shader” or “GLSL Fragment Shader”
Creating a new shader

An editor will appear (or you may have to double click it in the Program tab). For the vertex shader, paste the following code:

varying vec3 lightDir, normal;

void main() {
    normal = normalize(gl_NormalMatrix * gl_Normal);
    lightDir = normalize(vec3(gl_LightSource[0].position));

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = ftransform();
}

And for the fragment shader, paste in the following code:

varying vec3 lightDir, normal;
uniform sampler2D tex;

void main() {
    vec3 ct,cf;
    vec4 texel;
    float intensity,at,af;

    intensity = max(dot(lightDir,normalize(normal)),0.0);

    cf = intensity * (gl_FrontMaterial.diffuse).rgb +
                      gl_FrontMaterial.ambient.rgb;
    af = gl_FrontMaterial.diffuse.a;

    texel = texture2D(tex,gl_TexCoord[0].st);
    ct = texel.rgb;
    at = texel.a;

    gl_FragColor = vec4(ct * cf, at * af);
 }

If you screw up any of the pasting, you’ll see that we get immediate feedback about the parsing in the lower portion of the editor. That’s awesome.

Adding in the texture

Now since the Lighthouse 3D tutorial deals with textures, we need to get one. I think the most appropriate thing to do would be to do a sphere with an earth texture. So go to this link and download the image, it’s an image of Earth as taken by NASA, and made into a nice spherical map. For now, just put it on your desktop.

Open the Texture tab in OpenGL Shader Builder. You’ll see a main viewing area on the left, and some thumbnails on the right. Drag your image from the desktop into the first well (index 0) in your document:
Drag in your texture

Rendering

OK, now we are ready to see the result. Switch to the Render tab, and in the pop-up that currently says Plane, change it to Sphere:
Change model to Sphere

Also, change the clear color to Black by clicking the swatch next to Clear Color:
Set clear color to black

And when you do all that, you’ll end up with a beautiful looking Earth:
Final render

Summary

What you should take away from this is that on the Mac, you can focus on what you are working on. If you are working on a vertex or fragment shader, why should you have to write a ton of C code to test it? The OpenGL Shader Builder is another excellent way to do really effective OpenGL programming on the Mac.

More pictures up

I just put up some pictures from my Fourth of July at the Docters, and also my trip to San Francisco with Dahvede and Christine. Check ‘em out!

Fourth of July with the Docter's The city with Christine and Dahvede

New pictures up

Last weekend was my 21st birthday. Leslie gave me one of the sweetest gifts ever: a day of adventures. We went to Shabbona State Park in rural Illinois, went apple picking, and cooked a Japanese meal together. It was quite the day.

Check out the pictures here.

Me and Leslie at the orchard

Xcode 3.1: Open Quickly and AppleScripts

For some of you are using Apple’s latest Xcode 3.1 tools, you might have realized the shiny new Open Quickly dialog (which kicks some rear). One thing that tripped me up is that it wouldn’t work for AppleScript files. Funny, I thought.

But then I stumbled upon the AppleScript Studio 1.4 Release Notes, and they say that by default, Xcode is not setup to edit compiled (binary) Apple Script files. To turn that on, run the following command from the terminal:

defaults write com.apple.Xcode ASKAllowEditingOfCompiledScripts YES

And to turn it off:

defaults write com.apple.Xcode ASKAllowEditingOfCompiledScripts NO

OpenGL on the Mac (Part 1): Using GLUT

Today in my computer graphics class, my professor was talking about development environments for writing with OpenGL, a graphics framework. He mentioned Linux and Windows, but unfortunately left out the Mac. The CS department has dedicated an entire homework to just being to compile some simple OpenGL, which what I learned from lecture today, is a lot more involved on Windows than on the Mac. So for those who are looking for some insight on how to do this on the Mac, this is the post for you.

I will do two posts on OpenGL environments on the Mac, one for the two most common windowing systems: GLUT and Cocoa. Here’s when you would use each:

  • GLUT: Use the OpenGL Utility Toolkit if you need code that is cross platform. For example, if you are developing on the Mac, but the final code will run on Linux, Windows, or the Mac. I will cover GLUT in this post.
  • Cocoa: If your code will only run on the Mac, then Cocoa is definitely the windowing system you will want to be using. I’ll cover how to do this in another post.

The tools I will be using in this post are Apple’s Developer Tools, and I highly highly highly recommend that for all software development you are doing on the Mac, you use these tools. If you don’t already have them, visit Apple’s Developer site to sign up for a free online ADC membership, and then download the latest Xcode tools. You always install the tools off the disk that came with your Mac, though it’s best to get the latest ones from the site listed above.

So let’s get started: Creating our project

I’m just going to go through this step by step, I hope you don’t mind.

  1. Get the Xcode tools from Apple’s developer site.
  2. Open Xcode.
  3. Create a new project by going under File -> New Project or just hit Command-Shift-N.
  4. From the template chooser that appears, in the sidebar on the left, choose “Command Line Utility”, and then from the area on the right, choose “Standard Tool” and then click the “Choose” button. Save your project where you so please.
    Template chooser
  5. At this point, the project window will come up. This contains everything you need to develop your application. For more information on how to use Xcode, please go here. That link will give you a quick start to using Xcode, since that is not the main focus of this post.
    The project window

Writing our code

We have a project, now we need to write the code.

  1. In the files list, select main.c. The file will appear in the editor below.
  2. In the editor, paste the below code:
    #ifdef __APPLE__
        #include <GLUT/glut.h>
    #else
        #include <GL/glut.h>
    #endif
    
    /*
     *  reshape(w,h) called when window changes size
     *  called with width w and height h of new window size
     */
    void reshape(int w, int h) {
        glViewport(0, 0, w, h);         /* Establish viewing area to cover entire window. */
    }
    
    /*
     *  display() called when window contents need to be refreshed
     */
    void display(void) {
        glClearColor(0.0, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
    
        glBegin(GL_TRIANGLES);
            glColor3f(1.0, 0.0, 0.0);   /* red */
            glVertex2f(-1.0, -1.0);     /* lower left corner */
            glColor3f(0.0, 1.0, 0.0);   /* green */
            glVertex2f(-1.0, 1.0);      /* upper left corner */
            glColor3f(0.0, 0.0, 1.0);   /* blue */
            glVertex2f(1.0, -1.0);      /* lower right corner */
        glEnd();
        glFlush();                      /* OpenGL is pipelined, and sometimes waits
                                           for a full buffer to execute */
    }
    
    int main(int argc, char **argv) {
        glutInit(&argc, argv);          /* setup GLUT */
        glutCreateWindow(argv[0]);      /* open a window */
        glutDisplayFunc(display);       /* tell GLUT how to fill window */
        glutReshapeFunc(reshape);       /* update shape of window */
        glutMainLoop();                 /* let glut manage i/o processing */
        return 0;                       /* ANSI C requires main to return int */
    }
    

The code here is the code you could use on any platform, but is specific to the GLUT windowing system (note the functions called from main). The first few lines of code are used for portability. On non-Apple systems, the GLUT header is located in the OpenGL framework, unlike on Apple systems, where it’s in a separate framework. I’ll get to this next.

Linking against OpenGL and GLUT

Now that we have code, we have to make sure all the pieces are going to be there when we compile and run our application. To accomplish this, we need to link against the OpenGL and GLUT frameworks (a special kind of dylib).

  1. In the sidebar on the left of our project window, right click on the project icon at the top of the bar. This will bring up a contextual menu. From there, select Add -> Existing Frameworks.
    Add Existing Frameworks
  2. An open panel will come up. Navigate to the Frameworks folder which is located in the Library folder in the System folder at the root of your hard drive.
    Navigate to Frameworks folder in /System/Library/Frameworks
  3. Once inside the Frameworks folder, select the GLUT.framework and click the Add button.
  4. At this point, another sheet will come down. Make sure that the checkbox next to the name of your project (actually your target, but ignore that for now) is checked, under the “Add To Targets” label. Then click Add.
    Add to your target
  5. Repeat the above steps for the OpenGL.framework.

Running our app

Now we are linked against the GLUT and OpenGL libraries, we will be able to run our executable. In Xcode, there are targets and there are executables. You can think of a target as the set of rules and commands that produce an executable. In most cases, you will have one executable (or other product like a framework) for each target. When you build in Xcode, you build a target. And when you run in Xcode, you are running the target’s associated executable.

  1. To build and run our executable, from the Build menu, just select “Build and Run”.

Our project will build, and our executable will be launched, and we will have a dandy app to show for it. And that’s it!
The final result

Conclusion

To review, to get an OpenGL app running on the Mac, it’s really quite easy.

  1. Create a new Xcode project (you don’t just have to make C command line utilities, you could do it in C++, Python, whatever).
  2. Write your OpenGL code.
  3. Build and Run!

Movie Review: Transformers

The other night I saw Transformers with the roomies. It was that or Lord of War, and having never seen Transformers, I thought I would give it a shot. For those of you who have no idea what the movie is about, it basically tells the story of two futuristic robots who have an epic battle on earth, in which the final outcome rests in the hands (quite literally) of some random kid.

As far as the making of the movie goes, the visual effects stole the show. There were only a small handful of shots where you could definitively tell there was CGI (except for the fact that these robots obviously don’t exist… yet). Now, as far as the writing goes… wow, I was stunned. I didn’t know that Transformers was supposed to be a comedy, and apparently it was because I spent half the movie laughing. I kind of felt like someone went to the Disney lot, pulled the good looking teenage stars, gave them something a four year old wrote as their first screenplay, and then started shooting rubber bullets at them telling them to read the script as it happened. As you can tell, that kind of ruined the movie for me as far as something I would want to own or see again (except for the comedic value of course).

But given better actors and writing, I think the film would have a lot more potential. I like Michael Bay’s work, but I think his writer and casting director could have done a much better job.

Kevin’s movie rating:

Good, but only time I am seeing it

Movie Rating Key:

  1. Best movie I have ever seen
  2. Absolutely incredible
  3. Pretty darn good
  4. I would watch it again
  5. Good, but only time I am seeing it
  6. Disappointing
  7. Not very good
  8. Horrendous
  9. Shouldn’t have been made

Image courtesy of spectrasonics.net

Review: Apple Time Capsule

I usually do not do reviews of hardware, but in this case, I feel the urge to.

For my apartment, I purchased the Apple Time Capsule, which is an Airport Extreme Base Station (wireless router) with a 500 GB for backing up. So, let’s start with the wireless router. Setting it all up was a cinch. I plugged it in, and all my computers were on. One of the great things about this router is that it broadcasts at 802.11n, so all of you with 802.11n cards in your laptop would love the transfer speed we get. Also, the back of the router has 3 additional Ethernet jacks, so you can run any other computers and what not off Ethernet. And it works like a charm.

The second main feature I love about the Time Capsule is the hard drive. Not only is it a shared hard drive (so anyone I give access to can see it and put files on it), but I can use it as my Time Machine volume (a back up disk that is). I can do wireless backup seamlessly whenever I am in the apartment. That is terrific considering the drive doesn’t have to be hooked up to my machine, etc. And because the router is 802.11n, it’s pretty darn fast too.

And finally, the Time Capsule also has a USB port, so you can plug in a printer or extra hard drive, or both (given you plug in a hub). Setting up the printer to work with my Macbook Pro was literally as easy as plugging in the printer.

I can be sitting in my living room, surfing the net, printing out pictures from a weekend adventure, and backing up my computer, all at the same time, wirelessly. And given the fact the cost is pretty good and the device looks pretty, I would say that is a tremendous deal.

If you’re thinking of getting a wireless router, get the Time Capsule.