Skip to content

Instantly share code, notes, and snippets.

View nklsrh's full-sized avatar

Nikhil Suresh nklsrh

View GitHub Profile
function setup()
{
draw();
}
function draw()
{
// ---------------------------------
// Based on Aerotwist's cool tutorial - http://www.aerotwist.com/tutorials/getting-started-with-three-js/
// ---------------------------------
// set up the sphere vars
// lower 'segment' and 'ring' values will increase performance
var radius = 5,
segments = 6,
rings = 6;
// set up the paddle vars
paddleWidth = 10;
paddleHeight = 30;
paddleDepth = 10;
paddleQuality = 1;
// set up paddle 1
paddle1 = new THREE.Mesh(
new THREE.CubeGeometry(
paddleWidth,
camera = new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
scene = new THREE.Scene();
// add the camera to the scene
scene.add(camera);
// create the plane's material
var planeMaterial =
new THREE.MeshLambertMaterial(
{
color: 0x4BD121
});
// create the playing surface plane
var plane = new THREE.Mesh(
new THREE.PlaneGeometry(
// // create a point light
pointLight = new THREE.PointLight(0xF8D898);
// set its position
pointLight.position.x = -1000;
pointLight.position.y = 0;
pointLight.position.z = 1000;
pointLight.intensity = 2.9;
pointLight.distance = 10000;
// ball's x-direction, y-direction and speed per frame
var ballDirX = 1, ballDirY = 1, ballSpeed = 2;
// update ball position over time
ball.position.x += ballDirX * ballSpeed;
ball.position.y += ballDirY * ballSpeed;
// if ball goes off the top side (side of table)
if (ball.position.y <= -fieldHeight/2)
{
ballDirY = -ballDirY;
}
// if ball goes off the bottom side (side of table)
if (ball.position.y >= fieldHeight/2)
{
ballDirY = -ballDirY;
// update the board to reflect the max score for match win
document.getElementById("winnerBoard").innerHTML = "First to " + maxScore + " wins!";