1 tQuery.registerStatic('MinecraftCharAnimations', function(character){
  2 	var animations	= this;
  3 	// call parent ctor
  4 	tQuery.MinecraftCharAnimations.parent.constructor.call(this)
  5 	
  6 	var tweenAngle	= function(baseValue, nextValue, timePercent){
  7 		// compute the nextValue to get the shortest path - assume it is an angle
  8 		if( nextValue - baseValue > +Math.PI )	nextValue -= Math.PI*2;
  9 		if( nextValue - baseValue < -Math.PI )	nextValue += Math.PI*2;
 10 		return (1-timePercent) * baseValue + timePercent * nextValue;
 11 	}
 12 
 13 	
 14 	var onUpdate	= function(position){
 15 		character.parts.armR.rotation.z	= position.armRRotationZ;
 16 		character.parts.armL.rotation.z	= position.armLRotationZ;
 17 
 18 		character.parts.armR.rotation.x	=  position.armRotationX;
 19 		character.parts.armL.rotation.x = -position.armRotationX;
 20 
 21 		character.parts.legR.rotation.x	=  position.legRotationX;
 22 		character.parts.legL.rotation.x = -position.legRotationX;
 23 	};
 24 	var onCapture	= function(position){
 25 		position.armLRotationZ	= character.parts.armL.rotation.z;
 26 		position.armRRotationZ	= character.parts.armR.rotation.z;
 27 		position.armRotationX	= character.parts.armR.rotation.x;
 28 		position.legRotationX	= character.parts.legR.rotation.x;
 29 	};
 30 	var propTweens	= {
 31 		armLRotationZ	: tweenAngle,
 32 		armRRotationZ	: tweenAngle,
 33 		armRotationX	: tweenAngle,
 34 		legRotationX	: tweenAngle		
 35 	}
 36 	
 37 	
 38 	// Setup 'run' animation
 39 	var angleRange	= Math.PI/2-Math.PI/10;
 40 	animations.add('run'	, tQuery.createAnimation().pushKeyframe(0.5, {
 41 		armLRotationZ	: +Math.PI/10,
 42 		armRRotationZ	: -Math.PI/10,
 43 		armRotationX	: +angleRange,
 44 		legRotationX	: -angleRange			
 45 	}).pushKeyframe(0.5, {
 46 		armLRotationZ	: +Math.PI/10,
 47 		armRRotationZ	: -Math.PI/10,
 48 		armRotationX	: -angleRange,
 49 		legRotationX	: +angleRange
 50 	}).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate));
 51 
 52 	// Setup 'walk' animation
 53 	var angleRange	= Math.PI/3-Math.PI/10;
 54 	animations.add('walk'	, tQuery.createAnimation().pushKeyframe(0.5, {
 55 		armLRotationZ	: +Math.PI/30,
 56 		armRRotationZ	: -Math.PI/30,
 57 		armRotationX	: +angleRange,
 58 		legRotationX	: -angleRange		
 59 	}).pushKeyframe(0.5, {
 60 		armLRotationZ	: +Math.PI/30,
 61 		armRRotationZ	: -Math.PI/30,
 62 		armRotationX	: -angleRange,
 63 		legRotationX	: +angleRange
 64 	}).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate));
 65 
 66 	// Setup 'stand' animation
 67 	animations.add('stand', tQuery.createAnimation().pushKeyframe(0.3, {
 68 		armLRotationZ	: 0,
 69 		armRRotationZ	: 0,
 70 		armRotationX	: 0,
 71 		legRotationX	: 0
 72 	}).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate));
 73 
 74 	// Setup 'wave' animation
 75 	var angleRange	= Math.PI/2-Math.PI/10;
 76 	animations.add('wave'	, tQuery.createAnimation().pushKeyframe(0.5, {
 77 		armLRotationZ	: 0,
 78 		armRRotationZ	: Math.PI+2*Math.PI/5,
 79 		armRotationX	: 0,
 80 		legRotationX	: 0			
 81 	}).pushKeyframe(0.5, {
 82 		armLRotationZ	: 0,
 83 		armRRotationZ	: Math.PI+Math.PI/10,
 84 		armRotationX	: 0,
 85 		legRotationX	: 0			
 86 	}).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate));
 87 
 88 	// Setup 'hiwave' animation
 89 	var angleRange	= Math.PI/2-Math.PI/10;
 90 	animations.add('hiwave'	, tQuery.createAnimation().pushKeyframe(0.5, {
 91 		armLRotationZ	: Math.PI-3*Math.PI/5,
 92 		armRRotationZ	: Math.PI+3*Math.PI/5,
 93 		armRotationX	: 0,
 94 		legRotationX	: 0			
 95 	}).pushKeyframe(0.5, {
 96 		armLRotationZ	: Math.PI-Math.PI/10,
 97 		armRRotationZ	: Math.PI+Math.PI/10,
 98 		armRotationX	: 0,
 99 		legRotationX	: 0			
100 	}).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate));
101 });
102 
103 
104 tQuery.inherit(tQuery.MinecraftCharAnimations, tQuery.Animations);
105