agent & predect
by k6e2n0t12
HTML
<div id="info">volleyball demo
<br/>
<button id="shoot" style="width:15%">start</button>
<button id="catch_mode" style="width:15%">set</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>
<script src="//cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5.1/dat.gui.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, setOrBump = 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() {
serve();
turn = !turn;
hitOneTime = 1;
shootBall();
});
$('#catch_mode').click(function() {
setOrBump = !setOrBump;
if(setOrBump){
$(this).text("bump");
robot.body.rotation.x = 0;
robot.hitBallMachineHand.rotation.x = 2.1;
board.mesh.position.y = 2.05;
board.mesh.rotation.z = 0.75;
}
else{
$(this).text("set");
robot.body.rotation.x = -0.2;
robot.hitBallMachineHand.rotation.x = 0.9;
board.mesh.position.y = 1.1;
board.mesh.rotation.z = 0.75;
}
});
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.7, 1.1, 0);
board.mesh.rotation.z = 0.75;
scene.add(board.mesh);
gcontrols = {
v0: 10,
}
var gui = new dat.GUI();
gui.add(gcontrols, 'v0', 8, 12);
gui.close();
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...