softball

right-handed

by Rebecca Chen

HTML

<div id="info">
  Softball Pitcher
  <br>
  <br> ( generic CCD Solver )
</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>

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%;
	}

JavaScript

var scene, renderer, camera;
var controls;
var lowerArm, upperArm;
var clock = new THREE.Clock();

var sign = 1;
var zz = 30;

var gcontrols;
var theta1 = 0,
  theta2 = 0,
  theta3 = 0;
var tsphere;
var dt = 0;
var torsoTurn = 0;

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, -35);
  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]));
  m.multiply(new THREE.Matrix4().makeRotationX(q[1]));
  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[2]));
  m.multiply(new THREE.Matrix4().makeTranslation(0, -60, 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 (-1.5,1.5); 
  axes.push(axis);
  var axis = new CCD_axis(new THREE.Vector3(1, 0, 0), 1);
 // axis.limits = new THREE.Vector2(-0.7, -0.01);
  axes.push(axis);
}

////////////////////////////////////////////////////////////////

function init() {
  var width = window.innerWidth;
  var height = window.innerHeight;

  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setSize(width,...