For my final project, I wanted to further explore hierarchical modeling, animation, texture mapping, and collision detection. To do this, I implemented a game, Cat and Mouse, in which a hierarchically modeled cat controlled by the user can run and attack mice that will be running around the screen.
The cat has four legs, each with an upper leg and lower leg that can move relative to each other. When the user holds down the W key the cat will run using its four hierarchically modeled legs. The S will cause the cat to run backwards and the keys A and D allow the cat to turn left and right. The mouse controls the user’s perspective relative to the cat. The tail is constantly wagging in two pieces allowing it to look more like a natural wave than a stiff stick moving back and forth. The cat’s head can move relative to the body, and the ears and eyes are stuck on the head of the cat.
For the mice, the there were texture coordinates that already came with the mouse obj file I downloaded. I used a base color of flat gray to get the lighting effect.
For the cat, I had to create the texture coordinates. I did this using the vector from the center of the cat to its target and from the center of the cat to the point that needs to be colored (using only the x and z values). With these two vectors, I calculated the angle between them and used this to calculate how far right and how far ahead the pixel was relative to the center of the cat and mapped it into texile space. I used a base color of brass to get the lighting effect. For the eyes, I merely used the black rubber color.
For the ground, I repeated a grass texture image.
I use simple spherical collision detection to test how close the cat and mice are to each other. If a cat gets too close to one of the mice, the mouse knows to run along the vector opposite the direction of the cat. However, the mice are always slower than the cat, and so the cat can still catch them. The user can “attack” by pressing the space bar, which will cause the cats’ head to go down and paw to swipe. If the cat is close enough to a mouse when the user attacks, the mouse will be transformed into bone and stop moving.
Above is the cat in mid-attack
Above shows the bone that the mouse turns into after getting attacked by the cat.
I had a lot of fun creating this project and learning a lot about hierarchical modeling, animation, texture mapping, and collision detection. I enjoyed the math challenges to get the animations working correctly and smoothly. The texture mapping was also mathematically challenging as I had to create my own system of mapping from world coordinates to texile coordinates and making sure that the texture of the cat didn’t’ change as it moved. Overall, I learned a lot and look forward to more graphics challenges.