First person shooter (FPS) control demo in GLUT

Today I was looking around for some quick copy and paste code to add FPS gaming control to a small GLUT application I am writing. Half an hour or so of searching later and I still couldn’t find anything that I liked. A lot of the results were from forums of people trying to roll out their own code. I gave up and resorted to something I didn’t think I’d ever do, use code I wrote during my PhD …

After an hour or so of tinkering I got something that I’m happy with. I got my GLUT demo to do the following:

  • W,A,S,D keys for moving and strafing
  • Mouse look (default is inverted mouse)
  • Mouse button to fly up/down
  • SPACEBAR to toggle FPS control mode
  • Mouse always stays within the window with the cursor hidden

It has the feel of a proper FPS game.

Here’s what the demo looks like. Interestingly, when taking a screenshot the mouse cursor appears in the image.

The demo code can be used as a copy and paste project to quickly get a viewer running. All you have to do is add your rendering code into the Display() function.

Download

GlutFPS.tar.gz

The demo requires freeglut to be installed. You can use CodeBlocks to open up the project or type make if you’re in Linux. If you’re using Windows you’ll have to setup your own Visual Studio project.

If you have any questions just leave a comment and I’ll get back to you.

Python turtle!

I’ve recently started learning Python and was surprised and delighted to find that it has an implementation of the old Turtle program that I used to play around with back in primary. For some reason it even runs as slow as the original! (intentional?). Here is a simple geometric flower pattern I whipped up that I thought I’d share.

Seems to be lacking anti-aliasing support …

Here is the Python code.

# Thanks goes to Raphael for improving the original slow clunky code
import turtle

turtle.hideturtle()
turtle.speed('fastest')
turtle.tracer(False)

def petal(radius,steps):
    turtle.circle(radius,90,steps)
    turtle.left(90)
    turtle.circle(radius,90,steps)

num_petals = 8
steps = 8
radius = 100

for i in xrange(num_petals):
    turtle.setheading(0)
    turtle.right(360*i/num_petals)
    petal(radius,steps)

turtle.tracer(True)
turtle.done()