# Exploring a Dark Museum

My project simulates walking through a dark room in a museum, full of statues. There is a spotlight to light the world that is the users "flashlight" (or it looks more like a headlamp). The program is runs a bit slow with screen capture on, but you can watch a demo below:

Some graphics technologies I used were:
• Collision Detection
• Spotlight
• Camera control
• Texture mapping
My camera control and texture mapping are fairly simple and similar to past assignments, so I only delineate below the collision detection and spotlight work that I did.

## Collision Detection

The image above is an example of the camera colliding with one of the statues in the room. To implement collision detection, I calculated bounding spheres for each of the statues in the program's init() function. Because the meshes I used had a lot of vertices, it took a long time to calculate their normals and bounding spheres. To speed this up, I kept track of the minX, maxX, minY, maxY, minZ, and maxZ when loading the meshes in Shape.cpp, and I used that to calculate the bounding spheres. Instead of summing all the vertices and taking their average, I used the min and max values to calculate a center. Also, because the camera was anchored to a set y-value, I did not use the meshes' y values to calculate their bounding sphere's radius, which made the bounding sphere a more realistic size.

To avoid colliding with the walls in the room, I had previously attempted to calculate bounding boxes for the walls, but I eventually found it easier just to set a maxX, minX, maxZ, minZ restriction on the camera's location.

I didn't use any tutorials or websites to learn about collision detection because Dr. Wood briefly explained bounding spheres, and I managed to play around with it to make it work.

## Spotlight

As you can see, in the image above, the lighting attenuates as it reaches the edges of the spotlight circle. It's actually not a circle; it's a cone (which is more evident when the light source's position is not the same as your eyepoint). In the glsl shaders, I calculated the vector (cone_vector) from the eyepoint to the "center" of the cone, and I calculated the vector from the eyepoint to the current vertex (view_vector). Then I calculated the angle between the cone_vector and the view_vector. The bigger the angle, the less light I put into the reflected color.

The hardest part was getting the spotlight to follow the camera. I had a bad bug where the spotlight would stay in the center of the room, as I walked around, so if you implement a moving spotlight, be sure to update the view_vector I just mentioned.

If you're interested in implementing directional lights, spotlights, or multiple lights, I found this tutorial to be useful.