gameProgramming_hw6

garbage thrower

by chaiche

HTML

<div id="info">
  Hw6 丟垃圾
  <br>
  可以透過更改速度及空氣阻力來調整垃圾的狀態,如丟到垃圾桶立面則繼續下一關,如未丟中則要繼續丟
  <p id="level">level:0</p>
  <button id="throw" style="width:20%">Throw</button>
</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://rawgit.com/jyunming-chen/game3js/master/js/ccdbox.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.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: 50%;
	  padding: 5px;
	  color: #ffff00
	}
	
	a {
	  color: #00ffff
	}
	
	strong {
	  color: red
	}
	
	#container {
	  z-index: 0;
	  left: 0px;
	  top: 0px;
	  overflow: hidden;
	  position: absolute;
	  width: 100%;
	  height: 100%;
	}

JavaScript

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

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

//
var ball_speed = 5;
var ball_fist = false;
var ball_last = false;
var level = 1;

var ts;
var lastPos = new THREE.Vector3();
var keys = [
  [0, [-40, 55, -10]],
  [1, [-40, 55, 100]]
];
var T = .52;

$("#throw").click(function() {
  ts = clock.getElapsedTime();
  tsphere.material.visible = true;
	update.release = false;
});

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

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

init();
animate();

////////////////////////////////////////////////////////
// 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 THREE.Vector3(0, 0, 1), 0);
  axis.limits = new THREE.Vector2(-6, 0);
  axes.push(axis);
  var axis = new CCD_axis(new THREE.Vector3(1, 0, 0), 0);
  axis.limits = new THREE.Vector2(-2.5, 2.5);
 ...