FPS Bunny Target Practice

by Zach Mintzer

CPE471 Fall 2014, Professor Sueda

Description

For my final project I wanted to make a first-person shooter of some sort in a similar style of Counter-Strike. This would involve creating a map, adding collision detection, and creating a way to shoot a gun at objects and targets. I did the project in C++ using OpenGL and used knowledge of shaders, texture mapping, and math to achieve the goals I set.

Implementation

Creating the Map

I started the map by creating a plane and texture mapping it with a sand bitmap image file. When I initially texture mapped the .bmp I found I noticed that it didn't look very nice whether I repeated the texture over the plane or stretched it out. I solved this by applying a scaling matrix to the texture coordinates so that I could change how much the sand texture would repeat until I finally got the floor to look nice.

Next I needed to make a skybox so that the world didn't look like it was in a white void. I found matching bitmap images online that are typically used to create a skybox using a cube implementation. However, instead of using this approach I decided to just make five planes separately each mapped with the skybox images, and moved them around the map appropriately to form the sky.

Now that the world is set up, I added walls around with different textures to make the map I wanted for the player. I also added crates for the targets I would be adding later to sit on.

Collision Detection

Before adding targets to the map, I wanted to make sure that the player wouldn't be able to walk through walls, and therefore right off the map. To do this I implemented ODE's Box-Box collision into my moving system so that whenever the player moves, the program checks if you would collide with an object in the world and determine whether or not you should be able to move there. I originally attempted to use spherical detection for this, however the more I thought about it and how my map was set up, it didn't make as much sense to have spheres around my rectangular walls.

Targets and Shooting

Now that the player could move around and was not able to go through objects on the map, I added targets to the map. For targets I used bunny objects that would each be shaded differently (Blinn Phong, Silhouette, and Cel Shading).

My original concept for shooting would be to use a ray-sphere implementation, creating the ray from the position and direction of the camera (from the player's perspective). However, each implementation I attempted of this either used older OpenGL code or wouldn't work properly. I ended up creating a bullet object whenever the player shoots that would fly across the map. As the bullet moves, it detects whether it hits a map object or a target. If it hits a target, it also removes the target from the world.

Other Features

In order to prevent all of this code from getting messy in only a few .cpp files, I ended up making the entire program completely object-oriented with classes and many functions that each had their own dedicated uses in the overall system. This helped later on when adding individual features such as collision detection and shooting, since I didn't have to search through thousands of lines of code to know where to implement them.

I also added the ability of the player to jump, which involved adding code to the Camera to be able to move up and down the Y axis in the world. In addition, I made the program go to fullscreen mode and implemented using a glut cursor that could act as a crosshair so the player could aim.

Controls

Screenshots