Barak Cohen's (1+ε) Cents: Computer Science and Algorithms Blog

Wednesday, October 21, 2009

QBert 3D: Java with OpenGL Open Source Impelmentation

Q*bert was one of the more popular arcade games back in the early 80's. It features Qbert - a cute little fellow with a large snout that jumps around pyramids of different sizes while being chased by evil enemies seeking to annihilate him. Just to top things off, there are also large scary balls falling down the pyramid posing yet another threat to poor Qbert. To successfully complete a level, Qbert must jump on all the cubes comprising the pyramid.

Today I have for you another project from the Computer Graphics class I took last year. This time, a 3D version of Qbert, implemented in Java and OpenGL (using JOGL). As always, a large part of the credit is due to my partner in crime, Gur Dotan. Click here to download.

To run the game, unzip the download, open a command prompt, change to the QBert3D sub directory and then type "java -jar Qbert3d.jar".

Use the arrow keys to control Qbert's movement. It's a bit tricky at first because the turns are always with respect to Qbert's current direction. For example, if Qbert is facing you and you hit "right", Qbert will turn right, which is your left. Try to put yourself in Qbert's position and play as if you're Qbert. You can also hold down the left mouse button and move the mouse to rotate the camera so you can see where you have cubes not yet visited. Release the button to return to the normal viewing settings.

Each level has a corresponding XML file in the Levels directory. Inside each XML file you can edit the number of balls, enemies, their speed and intelligence but the real nifty part is the matrix in the end of the file where each entry specifies the height of the board at that point. This feature allows you to create non-pyramid levels! Feel free to create your own levels and if you send them to me, I promise to post them here.

There is also a Word document that describes some of the basic principles behind the design and coding of the game. The source code is also included and should be fairly easy to understand. As always, you are welcome to modify, redistribute, refactor, debug or anything else you want. I only ask that you give credit where it's due (to me and Gur) and let me know so I can check it out.

Download Qbert 3D

Sunday, October 19, 2008

Statistical Data Mining Tutorials

Good Data Mining tutorials are not always easy to come by. Fortunately, Andrew Moore who is a professor of at Carnegie Mellon University has created quite a few excellent tutorials, covering the basics of Statistical Data Mining and Machine Learning. The tutorials are generally suited for undergrads, but I think just about anyone with a solid math background should be able to keep up. For the mathematically uninitiated (myself included) , Andrew also gives a good introduction to probability theory, so you're pretty much covered either way.

The list of topics includes:
  • Decision Tree
  • Bayesian Networks
  • Naive Bayesian Classifiers
  • K-means and Hierarchical Clustering
  • Neural Networks
  • Support Vector Machines
And much much more!

Take a look here, you won't be sorry.


Thursday, October 16, 2008

Ray Tracing: A Simple Java, Open Source Implementation

From Wikipedia: "Ray tracing is a technique for generating an image by tracing the path of light through pixels in an image plane. The technique is capable of producing a very high degree of photorealism".

Basically, it means that we want to render images by imitating how we perceive the physical world as its image is recreated in our mind using the light rays that hit objects in space and are then returned to our eyes. We do this by modeling the world in a virtual 3d space. We place a virtual "eye" which is looking at a given direction and has a viewing plane, which is the portion of the world which the eye sees. Then, project a "ray of light" from the eye and through each pixel on the viewing plane and follow the ray along its path in space.

We test to see if the ray intersects any objects along that path. If it does, we calculate the color of the object at the point of intersection, taking into account visible light sources, the object's properties such as color, material, etc. This process is actually known as "Ray Casting". To make it "Ray Tracing" we continue tracing the ray after the intersection to see if the reflected ray hits any objects, and so on.

One of the assignments in the Computer Graphics course I took last semester was to write a simple ray tracer in Java. Written by myself and my more than capable partner, Gur Dotan, the tracer was implemented from scratch, and includes the following features:
  1. Primitive objects: Sphere, Box, Disc, Cylinder, Rectangle and a Torus.
  2. Light sources: Directional, Point and Light Area.
  3. Phong lighting model: Diffuse, Specular, Ambient and Emission parameters for all objects.
  4. Textures: PNG files, or a Checkers pattern with variable size / colors.
  5. Recursive ray tracing: Trace rays reflection recursively upon intersection.
  6. Supersampling: Using multiple rays per pixel for anti-aliasing
You can download the application here. Simply run the JAR file to start things up. It is completely self contained and has no 3rd party dependencies. The right window is where you enter the model of the world, and you can download some reference scenes here. Then, simply click Render.

The source code is actually pretty straightforward, can be found here, in the form of an Eclipse project. A short document outlining things is contained in the zip file.

Please note that the code is provided mostly for educational purposes and it is released as-is, without warranty of any kind. That being said, feel free to make any use of it. It is free both as in "free beer" and as in "free speech".

If you're looking for a commercial grade ray tracer, I recommend POV-Ray, an excellent open source ray tracer written in C++.

Click to view in my Flickr

Have fun,

Wednesday, October 15, 2008

Hello World

Hello and welcome to my blog. My name is Barak Cohen and I'm a 3rd year Computer Science undergrad at Tel-Aviv University, Israel.

I've been meaning to start this blog for some time and have actually bought the domain name a while back. What kept me from writing so far is simply not being sure I'll be able to keep the blog alive, and nothing's sadder than seeing a idle blog whose last post was ages ago.

Today I've finally mustered up the courage to write, hoping I'll be able to keep going during the school year. I'm also hoping to have my brother Dekel, himself a CS grad student at TAU, post here as well. I'm also extending an open invitation to you, the reader. Please feel free to send any CS related content you deem worth publishing and I'll be sure to post it on your behalf.

Wish me luck,