測試用
by YouTingKuo
HTML
<div id="info">Volley Ball
<br/>
<button id="shoot" style="width:15%">start</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/ball.js"></script>
<script src="https://youtingkuo.github.io/volleyball/agent.js"></script>
<script src="https://youtingkuo.github.io/volleyball/robot.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 basicScene = new BasicScene (scene);//add basic scene here
var ball = new Ball (scene);
var board, theta, phi;
var player = function() {
this.myTurn = 1;
this.hitMode = 0; // 0:bump ; 1:set
this.board = new Agent (new THREE.Vector3 (0, 0, 0),
new THREE.Vector3(0,0,0));
this.robot = new robot (scene);
this.board.mesh.position.set(4.7, 0, 0);
if(this.hitMode == 0) this.bump();
else if(this.hitMode == 1) this.set();
scene.add(this.board.mesh);
this.robot.hitBallMachine.position.set(this.board.mesh.position.x+0.8, 0.4, this.board.mesh.position.z);
}
player.prototype.bump = function(){
this.robot.body.rotation.x = -0.2;
this.robot.hitBallMachineHand.rotation.x = 0.9;
this.board.mesh.position.y = 1.1;
this.board.mesh.rotation.z = 0.75;
};
player.prototype.set = function(){
this.robot.body.rotation.x = 0;
this.robot.hitBallMachineHand.rotation.x = 2.1;
this.board.mesh.position.y = 2.05;
this.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, 6, 15);
controls = new THREE.OrbitControls(camera, renderer.domElement);
var player1 = new player();
/*
rightBoard = new Agent (new THREE.Vector3 (0, 0, 0),
new THREE.Vector3(0,0,0));
rightBoard.mesh.position.set(4.7, 1.1, 0);
rightBoard.mesh.rotation.z = 0.75;
scene.add(rightBoard.mesh);
*/
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth,...