Basketball Shooting Simulation

By Calin Washington

Project Description:

My final project for CPE 471 is a basketball shooting simulation. The player shoots the ball based on user input. My goal was to make the behavior and interaction between the ball and the hoop appear physically realistic. Results of each shot are output to the console along with total points, made shots, and missed shots.

Controls:

Implementation Details:

Lighting

The Blinn-Phong lighting model is used here. The light source is kept relatively dim and out of the way as I didn't consider complex or flashy lighting beneficial to the scene I was trying to create.

The lighting effect can be seen above on the player and on the basketball.


Camera

The camera is a free camera that can be situated to create a better viewing angle of the player and hoop for the user.

This is one angle that makes viewing the results of a shot a little easier.


Player

The player is hierarchically modeled using cube and sphere shapes. The player is designed to look like the top half of a person. When the user shoots, the player goes through an underhanded shooting animation before releasing the basketball.

This is the player while holding the basketball before taking a shot.

This is the player mid animation.

This is the player at the end of the animation after releasing the basketball.


Objects

The basketball and basketball hoop are .obj files with textures applied. The basketball hoop was created with a .jpg image applied to a rectangular surface.

This is the basketball

This is the basketball hoop

This is the image used for the basketball court


Aiming

The aim indicator is a cube object that is transformed and drawn in relation to the basketballs location. The object is rotated around the basketball based on the movement of the mouse.

This is the indicator at the lowest angle it can be pointed.

This is the indicator at the highest angle it can be pointed.


Shot Physics

When the ball is released a vector, called the shot vector, is created in the direction that was aimed. The magnitude of the shot vector is based on an hard-coded arbitrary speed. This vector is applied to the balls position. A gravity vector is then applied to the shot vector which decreases the y-value of the shot_vector. The magnitude of the gravity vector is hard-coded and arbitrary as well.

During each render call the shot vector is added to the current position of the ball and the shot vector is then incremented with the gravity vector. The gravity vector ensures that the basketball arcs downward over time. The shot ends once the shot vector is moving in the negative y direction and is below a certain height. The ball is then returned to its initial position.

As the ball traveled it is rotated along the x axis to simulate the backspin that occurs when shooting a basketball.

This is the basketball in the top of its arc.

This is the basketball at the end of its arc.


Collision Detection

The basketball is able to collide with the backboard of the hoop and the front of the rim. Scoring the basketball is also decided by determining a collision with the area inside the rim.

If the ball hits the backboard, the z value of the shot vector is fliped. The z value of the shot vector is multiplied by a constant to imitate the effect of backspin on the shot. The collision is detected using a bounding box on the backboard. During each render call the position of the ball is compared to the position of the bounding box.

The ball bounces off of the front of the rim based on the direction that the ball is traveling. Either the z value, the y value or both of the shot vector are flipped based on the direction of the ball. The collision is detected using a bounding box on the front of the rim. During each render call the position of the ball is compared to the position of the bounding box.

The collision with the inside of the rim is detected using a bounding sphere on the inside of the rim. During each render call the position of the ball is compared to the position of the bounding box.


Resources:

The basketball and basketball hoop objs were downloaded from: http://tf3dm.com