1 tQuery.registerStatic('MinecraftCharHeadAnimations', 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 if( nextValue - baseValue > Math.PI ) nextValue -= Math.PI*2; 8 if( nextValue - baseValue < -Math.PI ) nextValue += Math.PI*2; 9 return (1-timePercent) * baseValue + timePercent * nextValue; 10 } 11 12 13 var onUpdate = function(position){ 14 character.parts.headGroup.rotation.x = position.headRotationX; 15 character.parts.headGroup.rotation.y = position.headRotationY 16 }; 17 var onCapture = function(position){ 18 position.headRotationX = character.parts.headGroup.rotation.x; 19 position.headRotationY = character.parts.headGroup.rotation.y; 20 }; 21 var propTweens = { 22 headRotationX : tweenAngle, 23 headRotationY : tweenAngle 24 }; 25 26 27 // Setup 'still' animation 28 animations.add('still' , tQuery.createAnimation().pushKeyframe(0.5, { 29 headRotationX : 0, 30 headRotationY : 0 31 }).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate)); 32 33 // Setup 'no' animation 34 animations.add('no' , tQuery.createAnimation().pushKeyframe(0.5, { 35 headRotationX : 0, 36 headRotationY : +Math.PI/6 37 }).pushKeyframe(0.5, { 38 headRotationX : 0, 39 headRotationY : -Math.PI/6 40 }).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate)); 41 42 // Setup 'yes' animation 43 animations.add('yes' , tQuery.createAnimation().pushKeyframe(0.3, { 44 headRotationY : 0, 45 headRotationX : +Math.PI/8 46 }).pushKeyframe(0.3, { 47 headRotationX : -Math.PI/8, 48 headRotationY : 0 49 }).propertyTweens(propTweens).onCapture(onCapture).onUpdate(onUpdate)); 50 }); 51 52 53 tQuery.inherit(tQuery.MinecraftCharHeadAnimations, tQuery.Animations); 54