hw6 throw

by tom0000p

HTML

<div id="info">
  Hw6
  <br>
  <button id="throw" style="width:20%">Throw</button>
  <button id="restart" style="width:20%">restart</button>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js"></script>
<script src="https://rawgit.com/jyunming-chen/game3js/master/js/ccdbox.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

CSS

body {
	  background-color: #fff;
	  color: #111;
	  margin: 0px;
	  overflow: hidden;
	  font-family: Monospace;
	  font-size: 20px;
	}
	
	#info {
	  position: absolute;
	  top: 0px;
	  width: 100%;
	  padding: 5px;
	  text-align: center;
	  color: #ffff00
	}
	
	a {
	  color: #00ffff
	}
	
	strong {
	  color: red
	}
	
	#container {
	  z-index: 0;
	  left: 0px;
	  top: 0px;
	  overflow: hidden;
	  position: absolute;
	  width: 100%;
	  height: 100%;
	}
  
  #gui {
    position: absolute;
    top: 20px;
    left: 20px;
    height: 350px;
}

JavaScript

var scene, renderer, camera;
var controls;
var lowerArm, upperArm;

var clock = new THREE.Clock();
var ball, ballP, ballV, ballF;

var ts;
var lastPos = new THREE.Vector3();
var pos;
var point = [];
/*
var keys = [
  [0, [-40, 55, -10]],
  [1, [-40, 55, 100]]
];
*/
var keys = [
  [0, [, , ]],
  [1, [, , ]]
];
var T = .52;
var flag = 0
var i = 0;
$("#throw").click(function() {
  ts = clock.getElapsedTime();
  tsphere.material.visible = true;
	update.release = false;
  flag = 1;
});

$("#restart").click(function() {
			window.location.reload();
});


var circle;
var gcontrols;
var theta1 = 0,
  theta2 = 0,
  theta3 = 0, theta4 = 0;
var tsphere;
var target;

var axes = [];
var joints = [];

init();
animate();


function click() {
if (event.button==2) {
alert('禁止使用右鍵')
}
}document.onmousedown=click
////////////////////////////////////////////////////////
// forward kinematics
function fk(q, joints) {
  // joint[0]: shoulder
  // joint[1]: elbow
  // joint[2]: hand
  //	joints[0] = new THREE.Vector3(0,0,0);
  var m = new THREE.Matrix4();

  // from home plate
  var localzero = new THREE.Vector3(0, 0, 0);
  m.makeTranslation(0, 0, -15);
  //m.multiply(new THREE.Matrix4().makeRotationY(torsoTurn));
  m.multiply(new THREE.Matrix4().makeTranslation(-25, 100, 0));
  localzero.applyMatrix4(m);
  joints[0].copy(localzero);

  m.multiply(new THREE.Matrix4().makeRotationZ(q[0])); // 'ZXY'
  m.multiply(new THREE.Matrix4().makeRotationX(q[1]));
  m.multiply(new THREE.Matrix4().makeRotationY(q[2]));
  m.multiply(new THREE.Matrix4().makeTranslation(0, -40, 0));
  localzero.set(0, 0, 0);
  localzero.applyMatrix4(m);
  joints[1].copy(localzero);

  m.multiply(new THREE.Matrix4().makeRotationX(q[3]));
  m.multiply(new THREE.Matrix4().makeTranslation(0, -40, 0));
  localzero.set(0, 0, 0);
  localzero.applyMatrix4(m);
  joints[2].copy(localzero);
}

/////////////////////////////////////////////////////////////
// joint axis setup
//
function setarm() {
  var axis = new CCD_axis(new...