This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
camera = new THREE.PerspectiveCamera( | |
VIEW_ANGLE, | |
ASPECT, | |
NEAR, | |
FAR); | |
scene = new THREE.Scene(); | |
// add the camera to the scene | |
scene.add(camera); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// // 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------------- | |
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set the scene size | |
var WIDTH = 640, | |
HEIGHT = 360; | |
// create a WebGL renderer, camera | |
// and a scene | |
var renderer = new THREE.WebGLRenderer(); | |
// start the renderer | |
renderer.setSize(WIDTH, HEIGHT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ball's x-direction, y-direction and speed per frame | |
var ballDirX = 1, ballDirY = 1, ballSpeed = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// limit ball's y-speed to 2x the x-speed | |
// this is so the ball doesn't speed from left to right super fast | |
// keeps game playable for humans | |
if (ballDirY > ballSpeed * 2) | |
{ | |
ballDirY = ballSpeed * 2; | |
} | |
else if (ballDirY < -ballSpeed * 2) | |
{ | |
ballDirY = -ballSpeed * 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// update ball position over time | |
ball.position.x += ballDirX * ballSpeed; | |
ball.position.y += ballDirY * ballSpeed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
NewerOlder