CPE 471 Final Project: Marble Roll

Camden Stocker

Introduction

I created a classic game that similar to a game I played when I was really young. The goal of the game is to move the marble to the other side of the level. The W ans S keys are used to move the marble forward and backward, and the A and D keys are used to move it to the left and to the right. My goal for this project was to create a physics based game that had collision detection and gave the player a little bit of a challenge.

Collison Detection

The only physice detection in this game is between a sphere (marble) and a plane (ground or the wall). I only implemented axis alligned collision detection with the planes which means that the planes had normal vectors of either (1, 0, 0) or (0, 1, 0), (0, 0, 1). In other words, the plane either faces down the x, y, or z axis. I manually found the normals of each plane. Based on which direction the plane is facing, I would then see if the centerpoint of the marble was within the bounds of the plane. If the marble was within the bounds, I then checked for collision. Each plane is made up of a normal vector and a point. I calculated the distance of the ball's center point to the edge of the plane, and if it was less than the radius of the ball, a collision has occured.

Camera

Getting the camera to follow the ball around was a huge feature that I was proud of. I used the GLM lookAt function to create the View matrix. I set the lookAt position to the center of the ball, and I translated the eye based on the balls velocity. I never got the pitch and yaw to work along with the camera following the ball, but I did work on that part for a long time. The camera follows the ball around wherever it goes, and it stays a constant distance away from the marble.

Rolling

One of the hardest parts of this project was getting the ball to roll on the ground. I did a lot of math to get this to work right. I calculated the total distance the ball was going to go in the current frame. Then, based on that distance, the ball rotated along the axis of the cross product of the direction vector and the upVector. It rotated a certain number of degrees based on how far the ball was traveling during that frame. There were a lot of issued with this. For example, whenever the ball changes directions all the way around, the rotation is a little bit off. The same thing happens when the ball comes to rest.

Other Physics Fun

I implemented some other physics stuff that madde the gameplay fun. alnong with the ball colliding with the walls, the ball also reacted to gravity. The ball bounced several surfaces. Some surfaces were more "bouncy" then other surfaces. In other words, when the ball bounced on a bouncy surface, the velocity would be multiplied by a factor of 1.2 instead of just 1. The trampolines is an example of this.

Above is the marble in the middle of jumping on the trampoline

Conclusion

This project really helped me learn a lot about collision detection and other physics features. I suprisingly figured most things out myself with the help of google on occasion. I did not rely too much on the online resources because I wanted to implement everything on my own. Near the end, the code became a little convoluted. If I were to go back and redo the code, I would create a little bit more inheritance so it would be more efficient. Overall, I learned so much and I really enjoyed the project

References