predect final point
by YouTingKuo
HTML
<div id="info">volleyball demo
<br/>
<button id="shoot" style="width:15%">start</button>
<button id="catch_mode" style="width:15%">catch</button>
<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>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>
<script src="https://youtingkuo.github.io/volleyball/basicScene.js"></script>
<script src="https://youtingkuo.github.io/volleyball/agent.js"></script>
<script src="https://youtingkuo.github.io/volleyball/robot.js"></script>
<script src="https://youtingkuo.github.io/volleyball/ball.js"></script>
CSS
#info {
position: absolute;
top: 2%;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var scene = new THREE.Scene();
var renderer, camera, controls;
var keyboard = new KeyboardState();
var clock = new THREE.Clock();
var board, theta, phi;
var turn = false, attackOrCatch = false;
var hitOneTime = 1;
var basicScene = new BasicScene (scene);//add basic scene here
//var robot = new robot (scene);
var ball = new Ball (scene);
var test, finalP;
$('#shoot').click(function() {
turn = !turn;
hitOneTime = 1;
shootBall();
});
$('#catch_mode').click(function() {
attackOrCatch = !attackOrCatch;
if(attackOrCatch){
$(this).text("normal");
board.mesh.rotation.z = 0;
}
else{
$(this).text("catch");
board.mesh.rotation.z = Math.PI/4;
}
});
init();
animate();
function init() {
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, 10, 10);
controls = new THREE.OrbitControls(camera, renderer.domElement);
/*
//機器人手上的板子
board = new Agent (new THREE.Vector3 (0, 0, 0),
new THREE.Vector3(0,0,0));
board.mesh.position.set(4.5, 1.125+0.5, 0);
board.mesh.rotation.z = Math.PI/4;
scene.add(board.mesh);
*/
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function flightOfBall() {
var dT = clock.getDelta();
var f = new THREE.Vector3(0, -9.8, 0);
var n = rotation(new THREE.Vector3(0, 1, 0), Math.PI/4, 0);
//var p0 = board.mesh.localToWorld(new THREE.Vector3(0, 0.125+0.105, 0));
/*
//揮板子
var distance = ball.mesh.position.clone().sub(board.mesh.localToWorld(new THREE.Vector3(0, 0.125+0.105, 0))).lengthSq(); //板子跟球的距離
if(distance < 4 && hitOneTime)
...