Pool Table - Project Report - James Cole
Project

User Guide

A/D Or Left/Right Arrow Keys: Change launch angle.
W/S Or Up/Down Arrow Keys: Increase/Decrease Power.
Space: Launch Cue Ball.
Left Click: Rotate Camera.
Right Click: Pan Camera.
Mouse Wheel: Zoom.


Description

My project is a pool table with a cue ball and test balls. The user can launch the cue ball to send it rolling by applying rotation and transformation on the ball.
While it is buggy, the some collision detection with other balls and walls is implemented to provide some physics elements.

Process

This project was done using WebGl and Three.js.
I utilized Three.js's Perspective Camera and Orbit controls to set up the controlable camera for the scene.
I used meshes to create the table and the balls. For the table I made a felt mesh for the center area and four side meshs for the barriers
I then created the cue_ball and made the extra balls using an array, then set their position manually.
For textures I took some images from the internet and set them to the meshes.

To launch the cue ball I used keyboard controls.
The power is the percent of energy used when moving the ball.
Launching the ball gives it energy.
I used the arrow on the pivot to calculate the angle of the shot.
Each time I update the scene I run a ball physics function to test what each ball should be doing.
If the ball has energy then it moves a certin ditance in the x and z directions based on the balls projection angle, decreasing the energy until it is zero where it stops
This gives the apperence of the ball moving, slowing down, then stopping.
For rolling I had the ball rotate on the z axis based on the x direction and vice versa for the x axis, making the ball roll along after it is hit
To create collisions between walls and other balls I used ray tracing and casting to detect other meshes.
I then changed the direction of the ball based on where it hit and if it hit another ball, it would transfer some of it's energy
It is a little buggy at times such as the balls going through the walls and each other