volleyball
by YouTingKuo
HTML
<div id="info">volleyball demo
<br/>
<br/>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
CSS
#info {
position: absolute;
top: 2%;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var scene, renderer, camera;
var controls;
var clock = new THREE.Clock();
var theta = Math.PI/3;
var V0 = 10, Vx = V0*Math.cos(theta), Vy = V0*Math.sin(theta);
var y0 = 1, t=0, dT;
var ball;
init();
animate();
function init() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x888888);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 5, 10);
controls = new THREE.OrbitControls(camera, renderer.domElement);
light = new THREE.PointLight(0xffffff);
light.position.set(0,500,500);
scene.add(light);
var geometry = new THREE.BoxGeometry(100, 20, 20);
var material = new THREE.MeshBasicMaterial({
wireframe: true
});
floor = new THREE.Mesh(new THREE.PlaneGeometry(16,8,32),new THREE.MeshLambertMaterial({
side: THREE.DoubleSide,
color: 0xffffff
}));
floor.rotation.x=-Math.PI/2;
scene.add(floor);
ball = new THREE.Mesh(new THREE.SphereGeometry(0.105, 32, 32), new THREE.MeshBasicMaterial());
ball.position.set(-4, 1, 0);
scene.add(ball);
cylinder = new THREE.Mesh(new THREE.CylinderGeometry(0.1,0.1,2.55,32),new THREE.MeshLambertMaterial({
side: THREE.DoubleSide,
color: 0xffffff
}));
cylinder2 = new THREE.Mesh(new THREE.CylinderGeometry(0.1,0.1,2.55,32),new THREE.MeshLambertMaterial({
side: THREE.DoubleSide,
color: 0xffffff
}));
cylinder.position.set(0,2.55/2,5);
cylinder2.position.set(0,2.55/2,-5);
scene.add(cylinder);
scene.add(cylinder2);
net =new THREE.Mesh(new THREE.PlaneGeometry(1,8,32),new THREE.MeshLambertMaterial({
side: THREE.DoubleSide,
color: 0xffffff
}));
net.position.set(0,1.93,0);
net.rotation.z=Math.PI/2;
net.rotation.y=Math.PI/2;
scene.add(net);
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
...