Formatting changes to walk.js 1.1

Minor formatting changes for HiFi coding standard compliance
This commit is contained in:
DaveDubUK 2014-11-08 11:47:57 +00:00
parent 7a1f7bd418
commit ef325db052
4 changed files with 321 additions and 292 deletions

View file

@ -90,25 +90,22 @@ Motion = function() {
for (var i = 0; i < this.avatarJointNames.length; i++) { for (var i = 0; i < this.avatarJointNames.length; i++) {
if (i > 17 || i < 34) if (i > 17 || i < 34) {
// left hand fingers // left hand fingers
MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(16, 0, 0)); MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(16, 0, 0));
} else if (i > 33 || i < 38) {
else if (i > 33 || i < 38)
// left hand thumb // left hand thumb
MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(4, 0, 0)); MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(4, 0, 0));
} else if (i > 41 || i < 58) {
else if (i > 41 || i < 58)
// right hand fingers // right hand fingers
MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(16, 0, 0)); MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(16, 0, 0));
} else if (i > 57 || i < 62) {
else if (i > 57 || i < 62)
// right hand thumb // right hand thumb
MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(4, 0, 0)); MyAvatar.setJointData(this.avatarJointNames[i], Quat.fromPitchYawRollDegrees(4, 0, 0));
} else {
else
// zero out the remaining joints // zero out the remaining joints
MyAvatar.clearJointData(this.avatarJointNames[i]); MyAvatar.clearJointData(this.avatarJointNames[i]);
}
} }
} }
@ -123,15 +120,16 @@ Motion = function() {
this.walkWheelPos = 0; this.walkWheelPos = 0;
this.advanceWalkWheel = function(angle){ this.advanceWalkWheel = function(angle){
this.walkWheelPos += angle; this.walkWheelPos += angle;
if (motion.walkWheelPos >= 360) if (motion.walkWheelPos >= 360) {
this.walkWheelPos = this.walkWheelPos % 360; this.walkWheelPos = this.walkWheelPos % 360;
}
} }
// last frame history // last frame history
this.lastDirection = 0; this.lastDirection = 0;
this.lastVelocity = 0; this.lastVelocity = 0;
this.lastStrideLength = 0; // kept for use during transitions
}; // end Motion constructor }; // end Motion constructor
@ -159,7 +157,7 @@ state = (function () {
// status vars // status vars
powerOn: true, powerOn: true,
minimised: true, minimised: true,
editing:false, editing: false,
editingTranslation: false, editingTranslation: false,
setInternalState: function(newInternalState) { setInternalState: function(newInternalState) {
@ -284,10 +282,11 @@ state = (function () {
if (motion.strideLength === 0) { if (motion.strideLength === 0) {
motion.setGender(MALE); motion.setGender(MALE);
if (motion.direction === BACKWARDS) if (motion.direction === BACKWARDS) {
motion.strideLength = motion.selWalk.calibration.strideLengthBackwards; motion.strideLength = motion.selWalk.calibration.strideLengthBackwards;
else } else {
motion.strideLength = motion.selWalk.calibration.strideLengthForwards; motion.strideLength = motion.selWalk.calibration.strideLengthForwards;
}
} }
return; return;
} }
@ -299,26 +298,30 @@ state = (function () {
Transition = function(lastAnimation, nextAnimation, reachPoses, transitionDuration, easingLower, easingUpper) { Transition = function(lastAnimation, nextAnimation, reachPoses, transitionDuration, easingLower, easingUpper) {
this.lastAnim = lastAnimation; // name of last animation this.lastAnim = lastAnimation; // name of last animation
this.nextAnimation = nextAnimation; // name of next animation
if (lastAnimation === motion.selWalk || if (lastAnimation === motion.selWalk ||
nextAnimation === motion.selSideStepLeft || nextAnimation === motion.selSideStepLeft ||
nextAnimation === motion.selSideStepRight) nextAnimation === motion.selSideStepRight) {
this.walkingAtStart = true; // boolean - is the last animation a walking animation? // boolean - is the last animation a walking animation?
else this.walkingAtStart = true;
this.walkingAtStart = false; // boolean - is the last animation a walking animation? } else {
this.nextAnimation = nextAnimation; // name of next animation this.walkingAtStart = false;
}
if (nextAnimation === motion.selWalk || if (nextAnimation === motion.selWalk ||
nextAnimation === motion.selSideStepLeft || nextAnimation === motion.selSideStepLeft ||
nextAnimation === motion.selSideStepRight) nextAnimation === motion.selSideStepRight) {
this.walkingAtEnd = true; // boolean - is the next animation a walking animation? // boolean - is the next animation a walking animation?
else this.walkingAtEnd = true;
this.walkingAtEnd = false; // boolean - is the next animation a walking animation? } else {
this.walkingAtEnd = false;
}
this.reachPoses = reachPoses; // placeholder / stub: array of reach poses for squash and stretch techniques this.reachPoses = reachPoses; // placeholder / stub: array of reach poses for squash and stretch techniques
this.transitionDuration = transitionDuration; // length of transition (seconds) this.transitionDuration = transitionDuration; // length of transition (seconds)
this.easingLower = easingLower; // Bezier curve handle (normalised) this.easingLower = easingLower; // Bezier curve handle (normalised)
this.easingUpper = easingUpper; // Bezier curve handle (normalised) this.easingUpper = easingUpper; // Bezier curve handle (normalised)
this.startTime = new Date().getTime(); // Starting timestamp (seconds) this.startTime = new Date().getTime(); // Starting timestamp (seconds)
this.progress = 0; // how far are we through the transition? this.progress = 0; // how far are we through the transition?
this.walkWheelIncrement = 6; // how much to turn the walkwheel each frame when transitioning to / from walking this.walkWheelIncrement = 3; // how much to turn the walkwheel each frame when transitioning to / from walking
this.walkWheelAdvance = 0; // how many degrees the walk wheel has been advanced during the transition this.walkWheelAdvance = 0; // how many degrees the walk wheel has been advanced during the transition
this.walkStopAngle = 0; // what angle should we stop the walk cycle? this.walkStopAngle = 0; // what angle should we stop the walk cycle?

View file

@ -17,7 +17,6 @@ AveragingFilter = function(length) {
this.pastValues = []; this.pastValues = [];
for(var i = 0; i < length; i++) { for(var i = 0; i < length; i++) {
this.pastValues.push(0); this.pastValues.push(0);
} }
@ -26,17 +25,14 @@ AveragingFilter = function(length) {
if (this.pastValues.length === 0 && arguments[0]) { if (this.pastValues.length === 0 && arguments[0]) {
return arguments[0]; return arguments[0];
} } else if (arguments[0]) {
else if (arguments[0]) {
// apply quick and simple LP filtering // apply quick and simple LP filtering
this.pastValues.push(arguments[0]); this.pastValues.push(arguments[0]);
this.pastValues.shift(); this.pastValues.shift();
var nextOutputValue = 0; var nextOutputValue = 0;
for (var ea in this.pastValues) nextOutputValue += this.pastValues[ea]; for (var ea in this.pastValues) nextOutputValue += this.pastValues[ea];
return nextOutputValue / this.pastValues.length; return nextOutputValue / this.pastValues.length;
} } else return 0;
else return 0;
}; };
}; };
@ -44,15 +40,10 @@ AveragingFilter = function(length) {
// provides LP filtering with a more stable frequency / phase response // provides LP filtering with a more stable frequency / phase response
ButterworthFilter = function(cutOff) { ButterworthFilter = function(cutOff) {
switch(cutOff) { // cut off frequency = 5Hz
this.gain = 20.20612010;
case 5: this.coeffOne = -0.4775922501;
this.coeffTwo = 1.2796324250;
this.gain = 20.20612010;
this.coeffOne = -0.4775922501;
this.coeffTwo = 1.2796324250;
break;
}
// initialise the arrays // initialise the arrays
this.xv = []; this.xv = [];
@ -95,39 +86,42 @@ WaveSynth = function(waveShape, numHarmonics, smoothing) {
var harmonics = 0; var harmonics = 0;
var multiplier = 0; var multiplier = 0;
var iterations = this.numHarmonics * 2 + 2; var iterations = this.numHarmonics * 2 + 2;
if (this.waveShape === TRIANGLE) iterations++; if (this.waveShape === TRIANGLE) {
iterations++;
}
for(var n = 2; n < iterations; n++) { for(var n = 2; n < iterations; n++) {
switch(this.waveShape) { switch(this.waveShape) {
case SAWTOOTH: case SAWTOOTH: {
multiplier = 1 / n; multiplier = 1 / n;
harmonics += multiplier * Math.sin(n * frequency); harmonics += multiplier * Math.sin(n * frequency);
break; break;
}
case TRIANGLE: case TRIANGLE: {
if (n % 2 === 1) { if (n % 2 === 1) {
var mulitplier = 1 / (n * n); var mulitplier = 1 / (n * n);
// multiply (4n-1)th harmonics by -1
// multiply every (4n-1)th harmonic by -1 if (n === 3 || n === 7 || n === 11 || n === 15) {
if (n === 3 || n === 7 || n === 11 || n === 15)
mulitplier *= -1; mulitplier *= -1;
}
harmonics += mulitplier * Math.sin(n * frequency); harmonics += mulitplier * Math.sin(n * frequency);
} }
break; break;
}
case SQUARE: case SQUARE: {
if (n % 2 === 1) { if (n % 2 === 1) {
multiplier = 1 / n; multiplier = 1 / n;
harmonics += multiplier * Math.sin(n * frequency); harmonics += multiplier * Math.sin(n * frequency);
} }
break; break;
}
} }
} }
@ -216,13 +210,13 @@ filter = (function() {
return pos; return pos;
}, },
// simple clipping filter (faster way to make square waveforms) // simple clipping filter (clips bottom of wave only, special case for hips y-axis skeleton offset)
clipTrough: function(inputValue, peak, strength) { clipTrough: function(inputValue, peak, strength) {
var outputValue = inputValue * strength; var outputValue = inputValue * strength;
if (outputValue < -peak) if (outputValue < -peak) {
outputValue = -peak; outputValue = -peak;
}
return outputValue; return outputValue;
} }
} }

View file

@ -1363,22 +1363,20 @@ walkInterface = (function() {
function setBackground(backgroundID) { function setBackground(backgroundID) {
for (var i in _backgroundOverlays) { for (var i in _backgroundOverlays) {
if (_backgroundOverlays[i] === backgroundID) if (_backgroundOverlays[i] === backgroundID) {
Overlays.editOverlay(_backgroundOverlays[i], { Overlays.editOverlay(_backgroundOverlays[i], {
visible: true visible: true
}); });
else Overlays.editOverlay(_backgroundOverlays[i], { } else {
visible: false Overlays.editOverlay(_backgroundOverlays[i], { visible: false });
}); }
} }
}; };
// top row menu type buttons (on | walk | stand | fly | hide) // top row menu type buttons (on | walk | stand | fly | hide)
function hideMenuButtons() { function hideMenuButtons() {
for (var i in _buttonOverlays) { for (var i in _buttonOverlays) {
Overlays.editOverlay(_buttonOverlays[i], { Overlays.editOverlay(_buttonOverlays[i], { visible: false });
visible: false
});
} }
}; };
@ -1401,9 +1399,7 @@ walkInterface = (function() {
function setButtonOverlayVisible(buttonOverlayName) { function setButtonOverlayVisible(buttonOverlayName) {
for (var i in _buttonOverlays) { for (var i in _buttonOverlays) {
if (_buttonOverlays[i] === buttonOverlayName) { if (_buttonOverlays[i] === buttonOverlayName) {
Overlays.editOverlay(buttonOverlayName, { Overlays.editOverlay(buttonOverlayName, { visible: true });
visible: true
});
} }
} }
}; };
@ -1484,13 +1480,13 @@ walkInterface = (function() {
}); });
} }
if (!showButtons) return; if (!showButtons) {
return;
}
// set all the non-selected ones to showing // set all the non-selected ones to showing
for (var i = 8; i < _bigbuttonOverlays.length; i += 2) { for (var i = 8; i < _bigbuttonOverlays.length; i += 2) {
Overlays.editOverlay(_bigbuttonOverlays[i], { Overlays.editOverlay(_bigbuttonOverlays[i], { visible: true });
visible: true
});
} }
// set the currently selected one // set the currently selected one
@ -1877,6 +1873,7 @@ walkInterface = (function() {
_motion.curJointIndex = 4; _motion.curJointIndex = 4;
initialiseJointsEditingPanel(); initialiseJointsEditingPanel();
return; return;
} else if (clickX > 78 && clickX < 121 && clickY > 111 && clickY < 128) { } else if (clickX > 78 && clickX < 121 && clickY > 111 && clickY < 128) {
_motion.curJointIndex = 5; _motion.curJointIndex = 5;
initialiseJointsEditingPanel(); initialiseJointsEditingPanel();
@ -1962,7 +1959,7 @@ walkInterface = (function() {
return; return;
case _hideButton: case _hideButton:
_hideButtonSelected: case _hideButtonSelected:
Overlays.editOverlay(_hideButton, { Overlays.editOverlay(_hideButton, {
visible: false visible: false
@ -2084,8 +2081,11 @@ walkInterface = (function() {
case _standardWalkBigButton: case _standardWalkBigButton:
if (_motion.avatarGender === FEMALE) _motion.selWalk = _motion.femaleStandardWalk; if (_motion.avatarGender === FEMALE) {
else _motion.selWalk = _motion.maleStandardWalk; _motion.selWalk = _motion.femaleStandardWalk;
} else {
_motion.selWalk = _motion.maleStandardWalk;
}
_motion.curAnim = _motion.selWalk; _motion.curAnim = _motion.selWalk;
initialiseWalkStylesPanel(true); initialiseWalkStylesPanel(true);
return; return;
@ -2095,7 +2095,9 @@ walkInterface = (function() {
// toggle forwards / backwards walk display // toggle forwards / backwards walk display
if (_motion.direction === FORWARDS) { if (_motion.direction === FORWARDS) {
_motion.direction = BACKWARDS; _motion.direction = BACKWARDS;
} else _motion.direction = FORWARDS; } else {
_motion.direction = FORWARDS;
}
return; return;
case _sliderOne: case _sliderOne:
@ -2240,7 +2242,9 @@ walkInterface = (function() {
// workaround for bug (https://worklist.net/20160) // workaround for bug (https://worklist.net/20160)
if ((event.x > 310 && event.x < 318 && event.y > 1350 && event.y < 1355) || if ((event.x > 310 && event.x < 318 && event.y > 1350 && event.y < 1355) ||
(event.x > 423 && event.x < 428 && event.y > 1505 && event.y < 1508 )) return; (event.x > 423 && event.x < 428 && event.y > 1505 && event.y < 1508 )) {
return;
}
if (_state.currentState === _state.EDIT_WALK_JOINTS || if (_state.currentState === _state.EDIT_WALK_JOINTS ||
_state.currentState === _state.EDIT_STANDING || _state.currentState === _state.EDIT_STANDING ||
@ -2252,8 +2256,11 @@ walkInterface = (function() {
var thumbClickOffsetX = event.x - _minSliderX; var thumbClickOffsetX = event.x - _minSliderX;
var thumbPositionNormalised = thumbClickOffsetX / _sliderRangeX; var thumbPositionNormalised = thumbClickOffsetX / _sliderRangeX;
if (thumbPositionNormalised < 0) thumbPositionNormalised = 0; if (thumbPositionNormalised < 0) {
if (thumbPositionNormalised > 1) thumbPositionNormalised = 1; thumbPositionNormalised = 0;
} else if (thumbPositionNormalised > 1) {
thumbPositionNormalised = 1;
}
var sliderX = thumbPositionNormalised * _sliderRangeX; // sets range var sliderX = thumbPositionNormalised * _sliderRangeX; // sets range
if (_movingSliderOne) { if (_movingSliderOne) {
@ -2263,12 +2270,9 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].sway = _motion.curAnim.joints[0].sway =
thumbPositionNormalised * _sliderRanges.joints[0].swayRange; thumbPositionNormalised * _sliderRanges.joints[0].swayRange;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].pitch = _motion.curAnim.joints[_motion.curJointIndex].pitch =
thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].pitchRange; thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].pitchRange;
} }
@ -2280,12 +2284,9 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].bob = _motion.curAnim.joints[0].bob =
thumbPositionNormalised * _sliderRanges.joints[0].bobRange; thumbPositionNormalised * _sliderRanges.joints[0].bobRange;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].yaw = _motion.curAnim.joints[_motion.curJointIndex].yaw =
thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].yawRange; thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].yawRange;
} }
@ -2297,12 +2298,9 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].thrust = _motion.curAnim.joints[0].thrust =
thumbPositionNormalised * _sliderRanges.joints[0].thrustRange; thumbPositionNormalised * _sliderRanges.joints[0].thrustRange;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].roll = _motion.curAnim.joints[_motion.curJointIndex].roll =
thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].rollRange; thumbPositionNormalised * _sliderRanges.joints[_motion.curJointIndex].rollRange;
} }
@ -2317,11 +2315,8 @@ walkInterface = (function() {
var newPhase = 360 * thumbPositionNormalised - 180; var newPhase = 360 * thumbPositionNormalised - 180;
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].swayPhase = newPhase; _motion.curAnim.joints[0].swayPhase = newPhase;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].pitchPhase = newPhase; _motion.curAnim.joints[_motion.curJointIndex].pitchPhase = newPhase;
} }
@ -2335,11 +2330,8 @@ walkInterface = (function() {
var newPhase = 360 * thumbPositionNormalised - 180; var newPhase = 360 * thumbPositionNormalised - 180;
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].bobPhase = newPhase; _motion.curAnim.joints[0].bobPhase = newPhase;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].yawPhase = newPhase; _motion.curAnim.joints[_motion.curJointIndex].yawPhase = newPhase;
} }
@ -2353,11 +2345,8 @@ walkInterface = (function() {
var newPhase = 360 * thumbPositionNormalised - 180; var newPhase = 360 * thumbPositionNormalised - 180;
if (_state.editingTranslation) { if (_state.editingTranslation) {
_motion.curAnim.joints[0].thrustPhase = newPhase; _motion.curAnim.joints[0].thrustPhase = newPhase;
} else { } else {
_motion.curAnim.joints[_motion.curJointIndex].rollPhase = newPhase; _motion.curAnim.joints[_motion.curJointIndex].rollPhase = newPhase;
} }
@ -2368,13 +2357,10 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[0].swayOffsetRange; 2 * _sliderRanges.joints[0].swayOffsetRange;
_motion.curAnim.joints[0].swayOffset = newOffset; _motion.curAnim.joints[0].swayOffset = newOffset;
} else { } else {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[_motion.curJointIndex].pitchOffsetRange; 2 * _sliderRanges.joints[_motion.curJointIndex].pitchOffsetRange;
_motion.curAnim.joints[_motion.curJointIndex].pitchOffset = newOffset; _motion.curAnim.joints[_motion.curJointIndex].pitchOffset = newOffset;
@ -2387,13 +2373,10 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 *_sliderRanges.joints[0].bobOffsetRange; 2 *_sliderRanges.joints[0].bobOffsetRange;
_motion.curAnim.joints[0].bobOffset = newOffset; _motion.curAnim.joints[0].bobOffset = newOffset;
} else { } else {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[_motion.curJointIndex].yawOffsetRange; 2 * _sliderRanges.joints[_motion.curJointIndex].yawOffsetRange;
_motion.curAnim.joints[_motion.curJointIndex].yawOffset = newOffset; _motion.curAnim.joints[_motion.curJointIndex].yawOffset = newOffset;
@ -2406,21 +2389,19 @@ walkInterface = (function() {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
if (_state.editingTranslation) { if (_state.editingTranslation) {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[0].thrustOffsetRange; 2 * _sliderRanges.joints[0].thrustOffsetRange;
_motion.curAnim.joints[0].thrustOffset = newOffset; _motion.curAnim.joints[0].thrustOffset = newOffset;
} else { } else {
var newOffset = (thumbPositionNormalised - 0.5) * var newOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[_motion.curJointIndex].rollOffsetRange; 2 * _sliderRanges.joints[_motion.curJointIndex].rollOffsetRange;
_motion.curAnim.joints[_motion.curJointIndex].rollOffset = newOffset; _motion.curAnim.joints[_motion.curJointIndex].rollOffset = newOffset;
} }
} }
} // end if editing joints // end if editing joints
else if (_state.currentState === _state.EDIT_WALK_TWEAKS) {
} else if (_state.currentState === _state.EDIT_WALK_TWEAKS) {
// sliders for commonly required walk adjustments // sliders for commonly required walk adjustments
var thumbClickOffsetX = event.x - _minSliderX; var thumbClickOffsetX = event.x - _minSliderX;
@ -2430,50 +2411,39 @@ walkInterface = (function() {
var sliderX = thumbPositionNormalised * _sliderRangeX; // sets range var sliderX = thumbPositionNormalised * _sliderRangeX; // sets range
if (_movingSliderOne) { if (_movingSliderOne) {
// walk speed // walk speed
Overlays.editOverlay(_sliderOne, { Overlays.editOverlay(_sliderOne, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.calibration.frequency = thumbPositionNormalised * MAX_WALK_SPEED; _motion.curAnim.calibration.frequency = thumbPositionNormalised * MAX_WALK_SPEED;
} else if (_movingSliderTwo) { } else if (_movingSliderTwo) {
// lean (hips pitch offset) // lean (hips pitch offset)
Overlays.editOverlay(_sliderTwo, { Overlays.editOverlay(_sliderTwo, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
var newOffset = (thumbPositionNormalised - 0.5) * 2 * _sliderRanges.joints[0].pitchOffsetRange; var newOffset = (thumbPositionNormalised - 0.5) * 2 * _sliderRanges.joints[0].pitchOffsetRange;
_motion.curAnim.joints[0].pitchOffset = newOffset; _motion.curAnim.joints[0].pitchOffset = newOffset;
} else if (_movingSliderThree) { } else if (_movingSliderThree) {
// stride (upper legs pitch) // stride (upper legs pitch)
Overlays.editOverlay(_sliderThree, { Overlays.editOverlay(_sliderThree, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.joints[1].pitch = thumbPositionNormalised * _sliderRanges.joints[1].pitchRange; _motion.curAnim.joints[1].pitch = thumbPositionNormalised * _sliderRanges.joints[1].pitchRange;
} else if (_movingSliderFour) { } else if (_movingSliderFour) {
// legs separation (upper legs roll) // legs separation (upper legs roll)
Overlays.editOverlay(_sliderFour, { Overlays.editOverlay(_sliderFour, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.joints[1].rollOffset = (thumbPositionNormalised - 0.5) * _motion.curAnim.joints[1].rollOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[1].rollOffsetRange; 2 * _sliderRanges.joints[1].rollOffsetRange;
} else if (_movingSliderFive) { } else if (_movingSliderFive) {
// legs forward (lower legs pitch offset) // legs forward (lower legs pitch offset)
Overlays.editOverlay(_sliderFive, { Overlays.editOverlay(_sliderFive, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.joints[1].pitchOffset = (thumbPositionNormalised - 0.5) * _motion.curAnim.joints[1].pitchOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[1].pitchOffsetRange; 2 * _sliderRanges.joints[1].pitchOffsetRange;
} else if (_movingSliderSix) { } else if (_movingSliderSix) {
// lower legs splay (lower legs roll offset) // lower legs splay (lower legs roll offset)
Overlays.editOverlay(_sliderSix, { Overlays.editOverlay(_sliderSix, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
@ -2482,25 +2452,20 @@ walkInterface = (function() {
2 * _sliderRanges.joints[2].rollOffsetRange; 2 * _sliderRanges.joints[2].rollOffsetRange;
} else if (_movingSliderSeven) { } else if (_movingSliderSeven) {
// arms forward (upper arms yaw offset) // arms forward (upper arms yaw offset)
Overlays.editOverlay(_sliderSeven, { Overlays.editOverlay(_sliderSeven, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.joints[9].yawOffset = (thumbPositionNormalised - 0.5) * _motion.curAnim.joints[9].yawOffset = (thumbPositionNormalised - 0.5) *
2 * _sliderRanges.joints[9].yawOffsetRange; 2 * _sliderRanges.joints[9].yawOffsetRange;
} else if (_movingSliderEight) { } else if (_movingSliderEight) {
// arms out (upper arm pitch offset) // arms out (upper arm pitch offset)
Overlays.editOverlay(_sliderEight, { Overlays.editOverlay(_sliderEight, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
}); });
_motion.curAnim.joints[9].pitchOffset = (thumbPositionNormalised - 0.5) * _motion.curAnim.joints[9].pitchOffset = (thumbPositionNormalised - 0.5) *
-2 * _sliderRanges.joints[9].pitchOffsetRange; -2 * _sliderRanges.joints[9].pitchOffsetRange;
} else if (_movingSliderNine) { } else if (_movingSliderNine) {
// lower arms splay (lower arm pitch offset) // lower arms splay (lower arm pitch offset)
Overlays.editOverlay(_sliderNine, { Overlays.editOverlay(_sliderNine, {
x: sliderX + _minSliderX x: sliderX + _minSliderX
@ -2508,21 +2473,30 @@ walkInterface = (function() {
_motion.curAnim.joints[10].pitchOffset = (thumbPositionNormalised - 0.5) * _motion.curAnim.joints[10].pitchOffset = (thumbPositionNormalised - 0.5) *
-2 * _sliderRanges.joints[10].pitchOffsetRange; -2 * _sliderRanges.joints[10].pitchOffsetRange;
} }
} // if tweaking } // if tweaking
}; };
function mouseReleaseEvent(event) { function mouseReleaseEvent(event) {
if (_movingSliderOne) _movingSliderOne = false; if (_movingSliderOne) {
else if (_movingSliderTwo) _movingSliderTwo = false; _movingSliderOne = false;
else if (_movingSliderThree) _movingSliderThree = false; } else if (_movingSliderTwo) {
else if (_movingSliderFour) _movingSliderFour = false; _movingSliderTwo = false;
else if (_movingSliderFive) _movingSliderFive = false; } else if (_movingSliderThree) {
else if (_movingSliderSix) _movingSliderSix = false; _movingSliderThree = false;
else if (_movingSliderSeven) _movingSliderSeven = false; } else if (_movingSliderFour) {
else if (_movingSliderEight) _movingSliderEight = false; _movingSliderFour = false;
else if (_movingSliderNine) _movingSliderNine = false; } else if (_movingSliderFive) {
_movingSliderFive = false;
} else if (_movingSliderSix) {
_movingSliderSix = false;
} else if (_movingSliderSeven) {
_movingSliderSeven = false;
} else if (_movingSliderEight) {
_movingSliderEight = false;
} else if (_movingSliderNine) {
_movingSliderNine = false;
}
}; };
Controller.mousePressEvent.connect(mousePressEvent); Controller.mousePressEvent.connect(mousePressEvent);
@ -2575,7 +2549,7 @@ walkInterface = (function() {
case _state.EDIT_WALK_STYLES: case _state.EDIT_WALK_STYLES:
case _state.EDIT_WALK_TWEAKS: case _state.EDIT_WALK_TWEAKS:
case _state.EDIT_WALK_JOINTS: case _state.EDIT_WALK_JOINTS: {
hideMenuButtons(); hideMenuButtons();
initialiseFrontPanel(false); initialiseFrontPanel(false);
@ -2604,10 +2578,11 @@ walkInterface = (function() {
} else if (_state.currentState === _state.EDIT_WALK_JOINTS) { } else if (_state.currentState === _state.EDIT_WALK_JOINTS) {
if (_state.editingTranslation) if (_state.editingTranslation) {
setBackground(_controlsBackgroundWalkEditHipTrans); setBackground(_controlsBackgroundWalkEditHipTrans);
else } else {
setBackground(_controlsBackgroundWalkEditJoints); setBackground(_controlsBackgroundWalkEditJoints);
}
initialiseWalkStylesPanel(false); initialiseWalkStylesPanel(false);
setSliderThumbsVisible(true); setSliderThumbsVisible(true);
@ -2619,15 +2594,17 @@ walkInterface = (function() {
setButtonOverlayVisible(_onButton); setButtonOverlayVisible(_onButton);
setButtonOverlayVisible(_backButton); setButtonOverlayVisible(_backButton);
return; return;
}
case _state.EDIT_STANDING: case _state.EDIT_STANDING:
case _state.EDIT_SIDESTEP_LEFT: case _state.EDIT_SIDESTEP_LEFT:
case _state.EDIT_SIDESTEP_RIGHT: case _state.EDIT_SIDESTEP_RIGHT: {
if (_state.editingTranslation) if (_state.editingTranslation) {
setBackground(_controlsBackgroundWalkEditHipTrans); setBackground(_controlsBackgroundWalkEditHipTrans);
else } else {
setBackground(_controlsBackgroundWalkEditJoints); setBackground(_controlsBackgroundWalkEditJoints);
}
hideMenuButtons(); hideMenuButtons();
initialiseWalkStylesPanel(false); initialiseWalkStylesPanel(false);
initialiseFrontPanel(false); initialiseFrontPanel(false);
@ -2654,10 +2631,11 @@ walkInterface = (function() {
setButtonOverlayVisible(_onButton); setButtonOverlayVisible(_onButton);
setButtonOverlayVisible(_backButton); setButtonOverlayVisible(_backButton);
return; return;
}
case _state.EDIT_FLYING: case _state.EDIT_FLYING:
case _state.EDIT_FLYING_UP: case _state.EDIT_FLYING_UP:
case _state.EDIT_FLYING_DOWN: case _state.EDIT_FLYING_DOWN: {
setBackground(_controlsBackgroundWalkEditJoints); setBackground(_controlsBackgroundWalkEditJoints);
hideMenuButtons(); hideMenuButtons();
@ -2685,18 +2663,22 @@ walkInterface = (function() {
setButtonOverlayVisible(_onButton); setButtonOverlayVisible(_onButton);
setButtonOverlayVisible(_backButton); setButtonOverlayVisible(_backButton);
return; return;
}
case _state.STANDING: case _state.STANDING:
case _state.WALKING: case _state.WALKING:
case _state.FLYING: case _state.FLYING:
case _state.SIDE_STEP: case _state.SIDE_STEP:
default: default: {
hideMenuButtons(); hideMenuButtons();
hideJointSelectors(); hideJointSelectors();
setBackground(_controlsBackground); setBackground(_controlsBackground);
if (_state.powerOn) setButtonOverlayVisible(_onButton); if (_state.powerOn) {
else setButtonOverlayVisible(_offButton); setButtonOverlayVisible(_onButton);
} else {
setButtonOverlayVisible(_offButton);
}
setButtonOverlayVisible(_configWalkButton); setButtonOverlayVisible(_configWalkButton);
setButtonOverlayVisible(_configStandButton); setButtonOverlayVisible(_configStandButton);
setButtonOverlayVisible(_configFlyingButton); setButtonOverlayVisible(_configFlyingButton);
@ -2705,9 +2687,9 @@ walkInterface = (function() {
initialiseFrontPanel(true); initialiseFrontPanel(true);
initialiseWalkStylesPanel(false); initialiseWalkStylesPanel(false);
return; return;
}
} }
} }
} }
}; // end public methods (return) }; // end public methods (return)
})(); })();

View file

@ -14,7 +14,7 @@
// constants // constants
var MALE = 1; var MALE = 1;
var FEMALE = 2; var FEMALE = 2;
var MAX_WALK_SPEED = 2.5; var MAX_WALK_SPEED = 2.5;//3.919;
var TAKE_FLIGHT_SPEED = 4.55; var TAKE_FLIGHT_SPEED = 4.55;
var TOP_SPEED = 300; var TOP_SPEED = 300;
var UP = 1; var UP = 1;
@ -24,7 +24,7 @@ var RIGHT = 8;
var FORWARDS = 16; var FORWARDS = 16;
var BACKWARDS = 32; var BACKWARDS = 32;
// ovelay images location // location of animation files and overlay images
var pathToAssets = 'http://s3.amazonaws.com/hifi-public/WalkScript/'; var pathToAssets = 'http://s3.amazonaws.com/hifi-public/WalkScript/';
// load the UI // load the UI
@ -51,7 +51,7 @@ var SAWTOOTH = 1;
var TRIANGLE = 2; var TRIANGLE = 2;
var SQUARE = 4; var SQUARE = 4;
// filters for synthesising more complex, natural waveforms // various filters for synthesising more complex, natural waveforms
var leanPitchFilter = filter.createAveragingFilter(15); var leanPitchFilter = filter.createAveragingFilter(15);
var leanRollFilter = filter.createAveragingFilter(15); var leanRollFilter = filter.createAveragingFilter(15);
var hipsYawShaper = filter.createWaveSynth(TRIANGLE, 3, 2); var hipsYawShaper = filter.createWaveSynth(TRIANGLE, 3, 2);
@ -71,56 +71,65 @@ Script.update.connect(function(deltaTime) {
// check for editing modes first, as these require no positioning calculations // check for editing modes first, as these require no positioning calculations
switch (state.currentState) { switch (state.currentState) {
case state.EDIT_WALK_STYLES: case state.EDIT_WALK_STYLES: {
motion.curAnim = motion.selWalk; motion.curAnim = motion.selWalk;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_WALK_TWEAKS: case state.EDIT_WALK_TWEAKS: {
motion.curAnim = motion.selWalk; motion.curAnim = motion.selWalk;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_WALK_JOINTS: case state.EDIT_WALK_JOINTS: {
motion.curAnim = motion.selWalk; motion.curAnim = motion.selWalk;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_STANDING: case state.EDIT_STANDING: {
motion.curAnim = motion.selStand; motion.curAnim = motion.selStand;
motion.direction = FORWARDS; motion.direction = FORWARDS;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_SIDESTEP_LEFT: case state.EDIT_SIDESTEP_LEFT: {
motion.curAnim = motion.selSideStepLeft; motion.curAnim = motion.selSideStepLeft;
motion.direction = LEFT; motion.direction = LEFT;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_SIDESTEP_RIGHT: case state.EDIT_SIDESTEP_RIGHT: {
motion.curAnim = motion.selSideStepRight; motion.curAnim = motion.selSideStepRight;
motion.direction = RIGHT; motion.direction = RIGHT;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_FLYING: case state.EDIT_FLYING: {
motion.curAnim = motion.selFly; motion.curAnim = motion.selFly;
motion.direction = FORWARDS; motion.direction = FORWARDS;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_FLYING_UP: case state.EDIT_FLYING_UP: {
motion.curAnim = motion.selFlyUp; motion.curAnim = motion.selFlyUp;
motion.direction = UP; motion.direction = UP;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.EDIT_FLYING_DOWN: case state.EDIT_FLYING_DOWN: {
motion.curAnim = motion.selFlyDown; motion.curAnim = motion.selFlyDown;
motion.direction = DOWN; motion.direction = DOWN;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
default: default:
break; break;
@ -137,60 +146,78 @@ Script.update.connect(function(deltaTime) {
return; return;
} }
var localVelocity = {x: 0, y: 0, z: 0}; var localVelocity = {x: 0, y: 0, z: 0};
if (speed > 0) if (speed > 0) {
localVelocity = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), velocity); localVelocity = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), velocity);
}
if (!state.editing) { if (!state.editing) {
// determine the candidate animation state // determine the candidate animation state
var actionToTake = undefined; var actionToTake = undefined;
if (speed < 0.05) actionToTake = state.STANDING; // as per MIN_AVATAR_SPEED, MyAvatar.cpp if (speed < 0.05) {
else if (speed < TAKE_FLIGHT_SPEED) actionToTake = state.WALKING; actionToTake = state.STANDING;
else if (speed >= TAKE_FLIGHT_SPEED) actionToTake = state.FLYING; } else if (speed < TAKE_FLIGHT_SPEED) {
actionToTake = state.WALKING;
} else if (speed >= TAKE_FLIGHT_SPEED) {
actionToTake = state.FLYING;
}
// determine the principle direction // determine the principle direction
if (Math.abs(localVelocity.x) > Math.abs(localVelocity.y) && if (Math.abs(localVelocity.x) > Math.abs(localVelocity.y) &&
Math.abs(localVelocity.x) > Math.abs(localVelocity.z)) { Math.abs(localVelocity.x) > Math.abs(localVelocity.z)) {
if (localVelocity.x < 0) motion.direction = LEFT; if (localVelocity.x < 0) {
else motion.direction = RIGHT; motion.direction = LEFT;
} else {
motion.direction = RIGHT;
}
} else if (Math.abs(localVelocity.y) > Math.abs(localVelocity.x) && } else if (Math.abs(localVelocity.y) > Math.abs(localVelocity.x) &&
Math.abs(localVelocity.y) > Math.abs(localVelocity.z)) { Math.abs(localVelocity.y) > Math.abs(localVelocity.z)) {
if (localVelocity.y > 0) motion.direction = UP; if (localVelocity.y > 0) {
else motion.direction = DOWN; motion.direction = UP;
} else {
motion.direction = DOWN;
}
} else if (Math.abs(localVelocity.z) > Math.abs(localVelocity.x) && } else if (Math.abs(localVelocity.z) > Math.abs(localVelocity.x) &&
Math.abs(localVelocity.z) > Math.abs(localVelocity.y)) { Math.abs(localVelocity.z) > Math.abs(localVelocity.y)) {
if (localVelocity.z < 0) motion.direction = FORWARDS; if (localVelocity.z < 0) {
else motion.direction = BACKWARDS; motion.direction = FORWARDS;
} else {
motion.direction = BACKWARDS;
}
} }
// maybe at walking speed, but sideways? // maybe at walking speed, but sideways?
if (actionToTake === state.WALKING && if (actionToTake === state.WALKING &&
(motion.direction === LEFT || (motion.direction === LEFT ||
motion.direction === RIGHT)) motion.direction === RIGHT)) {
actionToTake = state.SIDE_STEP; actionToTake = state.SIDE_STEP;
}
// maybe at walking speed, but flying up or down? // maybe at walking speed, but flying up or down?
if (actionToTake === state.WALKING && if (actionToTake === state.WALKING &&
(motion.direction === UP))// || (motion.direction === UP ||
//motion.direction === DOWN)) motion.direction === DOWN)) {
actionToTake = state.FLYING; actionToTake = state.FLYING;
}
// select appropriate animation and initiate Transition if required // select appropriate animation and initiate Transition if required
// note: The transitions are not compete, and are the most likely
// candidate for the next worklist item
switch (actionToTake) { switch (actionToTake) {
case state.STANDING: case state.STANDING: {
// do we need to change state? // do we need to change state?
if (state.currentState !== state.STANDING) { if (state.currentState !== state.STANDING) {
switch (motion.curAnim) { switch (motion.curAnim) {
case motion.selWalk: case motion.selWalk: {
// Walking to standing // Walking to standing
motion.curTransition = new Transition( motion.curTransition = new Transition(
@ -200,57 +227,60 @@ Script.update.connect(function(deltaTime) {
{x: 0.1, y: 0.5}, {x: 0.1, y: 0.5},
{x: -0.25, y: 1.22}); {x: -0.25, y: 1.22});
break; break;
}
case motion.selSideStepLeft: case motion.selFly:
case motion.selSideStepRight: case motion.selFlyUp:
case motion.selFlyDown: {
break; // Flying to Standing
default:
// flying to standing
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
motion.selStand, motion.selStand,
[], 0.25, [], 0.5,
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
default:
break;
} }
state.setInternalState(state.STANDING); state.setInternalState(state.STANDING);
motion.curAnim = motion.selStand; motion.curAnim = motion.selStand;
} }
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.WALKING: case state.WALKING: {
if (state.currentState !== state.WALKING) { if (state.currentState !== state.WALKING) {
if (motion.direction === BACKWARDS) if (motion.direction === BACKWARDS) {
motion.walkWheelPos = motion.selWalk.calibration.startAngleBackwards; motion.walkWheelPos = motion.selWalk.calibration.startAngleBackwards;
} else {
else motion.walkWheelPos = motion.selWalk.calibration.startAngleForwards; motion.walkWheelPos = motion.selWalk.calibration.startAngleForwards;
}
switch (motion.curAnim) { switch (motion.curAnim) {
case motion.selStand: case motion.selStand: {
// Standing to Walking // Standing to Walking
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
motion.selWalk, motion.selWalk,
[], 0.1, [], 0.25,
{x: 0.5, y: 0.1}, {x: 0.5, y: 0.5},
{x: 0.5, y: 0.9}); {x: 0.5, y: 0.5});
break; break;
}
case motion.selSideStepLeft: case motion.selFly:
case motion.selSideStepRight: case motion.selFlyUp:
case motion.selFlyDown: {
break;
default:
// Flying to Walking // Flying to Walking
motion.curTransition = new Transition( motion.curTransition = new Transition(
@ -260,69 +290,56 @@ Script.update.connect(function(deltaTime) {
{x: 0.24, y: 0.03}, {x: 0.24, y: 0.03},
{x: 0.42, y: 1.0}); {x: 0.42, y: 1.0});
break; break;
}
default:
break;
} }
state.setInternalState(state.WALKING); state.setInternalState(state.WALKING);
} }
motion.curAnim = motion.selWalk; motion.curAnim = motion.selWalk;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.SIDE_STEP: case state.SIDE_STEP: {
var selSideStep = 0; var selSideStep = 0;
if (motion.direction === LEFT) { if (motion.direction === LEFT) {
if (motion.lastDirection !== LEFT) if (motion.lastDirection !== LEFT) {
motion.walkWheelPos = motion.selSideStepLeft.calibration.cycleStart; motion.walkWheelPos = motion.selSideStepLeft.calibration.cycleStart;
}
selSideStep = motion.selSideStepLeft; selSideStep = motion.selSideStepLeft;
} else { } else {
if (motion.lastDirection !== RIGHT) if (motion.lastDirection !== RIGHT) {
motion.walkWheelPos = motion.selSideStepRight.calibration.cycleStart; motion.walkWheelPos = motion.selSideStepRight.calibration.cycleStart;
}
selSideStep = motion.selSideStepRight; selSideStep = motion.selSideStepRight;
} }
if (state.currentState !== state.SIDE_STEP) { if (state.currentState !== state.SIDE_STEP) {
if (motion.direction === LEFT) { if (motion.direction === LEFT) {
motion.walkWheelPos = motion.selSideStepLeft.calibration.cycleStart; motion.walkWheelPos = motion.selSideStepLeft.calibration.cycleStart;
switch (motion.curAnim) {
case motion.selStand:
break;
default:
break;
}
} else { } else {
motion.walkWheelPos = motion.selSideStepRight.calibration.cycleStart; motion.walkWheelPos = motion.selSideStepRight.calibration.cycleStart;
switch (motion.curAnim) {
case motion.selStand:
break;
default:
break;
}
} }
state.setInternalState(state.SIDE_STEP); state.setInternalState(state.SIDE_STEP);
} }
motion.curAnim = selSideStep; motion.curAnim = selSideStep;
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}
case state.FLYING: case state.FLYING: {
if (state.currentState !== state.FLYING) if (state.currentState !== state.FLYING) {
state.setInternalState(state.FLYING); state.setInternalState(state.FLYING);
}
// change animation for flying directly up or down // change animation for flying directly up or down
if (motion.direction === UP) { if (motion.direction === UP) {
@ -332,23 +349,21 @@ Script.update.connect(function(deltaTime) {
switch (motion.curAnim) { switch (motion.curAnim) {
case motion.selStand: case motion.selStand:
case motion.selWalk: case motion.selWalk: {
// standing | walking to flying up // standing | walking to flying up
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
motion.selFlyUp, motion.selFlyUp,
[], 0.25, [], 0.35,
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
case motion.selSideStepLeft: case motion.selFly:
case motion.selSideStepRight: case motion.selFlyUp:
case motion.selFlyDown: {
break;
default:
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
@ -357,6 +372,11 @@ Script.update.connect(function(deltaTime) {
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
default:
break;
} }
motion.curAnim = motion.selFlyUp; motion.curAnim = motion.selFlyUp;
} }
@ -368,7 +388,7 @@ Script.update.connect(function(deltaTime) {
switch (motion.curAnim) { switch (motion.curAnim) {
case motion.selStand: case motion.selStand:
case motion.selWalk: case motion.selWalk: {
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
@ -377,21 +397,24 @@ Script.update.connect(function(deltaTime) {
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
case motion.selSideStepLeft: case motion.selFly:
case motion.selSideStepRight: case motion.selFlyUp:
case motion.selFlyDown: {
break;
default:
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
motion.selFlyDown, motion.selFlyDown,
[], 0.5, [], 0.45,
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
default:
break;
} }
motion.curAnim = motion.selFlyDown; motion.curAnim = motion.selFlyDown;
} }
@ -403,7 +426,7 @@ Script.update.connect(function(deltaTime) {
switch (motion.curAnim) { switch (motion.curAnim) {
case motion.selStand: case motion.selStand:
case motion.selWalk: case motion.selWalk: {
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
@ -412,13 +435,11 @@ Script.update.connect(function(deltaTime) {
{x: 1.44, y:0.24}, {x: 1.44, y:0.24},
{x: 0.61, y:0.92}); {x: 0.61, y:0.92});
break; break;
}
case motion.selSideStepLeft: case motion.selFly:
case motion.selSideStepRight: case motion.selFlyUp:
case motion.selFlyDown: {
break;
default:
motion.curTransition = new Transition( motion.curTransition = new Transition(
motion.curAnim, motion.curAnim,
@ -427,12 +448,18 @@ Script.update.connect(function(deltaTime) {
{x: 0.5, y: 0.08}, {x: 0.5, y: 0.08},
{x: 0.28, y: 1}); {x: 0.28, y: 1});
break; break;
}
default:
break;
} }
motion.curAnim = motion.selFly; motion.curAnim = motion.selFly;
} }
} }
animateAvatar(deltaTime, speed); animateAvatar(deltaTime, speed);
break; break;
}// end case state.FLYING
} // end switch(actionToTake) } // end switch(actionToTake)
@ -447,17 +474,20 @@ Script.update.connect(function(deltaTime) {
// the faster we go, the further we lean forward. the angle is calcualted here // the faster we go, the further we lean forward. the angle is calcualted here
function getLeanPitch(speed) { function getLeanPitch(speed) {
if (speed > TOP_SPEED) speed = TOP_SPEED; if (speed > TOP_SPEED) {
speed = TOP_SPEED;
}
var leanProgress = speed / TOP_SPEED; var leanProgress = speed / TOP_SPEED;
if (motion.direction === LEFT || if (motion.direction === LEFT ||
motion.direction === RIGHT) motion.direction === RIGHT) {
leanProgress = 0; leanProgress = 0;
} else {
else {
var responseSharpness = 1.5; var responseSharpness = 1.5;
if (motion.direction == BACKWARDS) responseSharpness = 3.0; if (motion.direction == BACKWARDS) {
responseSharpness = 3.0;
}
leanProgress = filter.bezier((1 - leanProgress), leanProgress = filter.bezier((1 - leanProgress),
{x: 0, y: 0.0}, {x: 0, y: 0.0},
@ -466,10 +496,11 @@ function getLeanPitch(speed) {
{x: 1, y: 1}).y; {x: 1, y: 1}).y;
// determine final pitch and adjust for direction of momentum // determine final pitch and adjust for direction of momentum
if (motion.direction === BACKWARDS) if (motion.direction === BACKWARDS) {
leanProgress = -motion.motionPitchMax * leanProgress; leanProgress = -motion.motionPitchMax * leanProgress;
else } else {
leanProgress = motion.motionPitchMax * leanProgress; leanProgress = motion.motionPitchMax * leanProgress;
}
} }
// return the smoothed response // return the smoothed response
@ -480,19 +511,26 @@ function getLeanPitch(speed) {
function getLeanRoll(deltaTime, speed) { function getLeanRoll(deltaTime, speed) {
var leanRollProgress = 0; var leanRollProgress = 0;
if (speed > TOP_SPEED) speed = TOP_SPEED; if (speed > TOP_SPEED) {
speed = TOP_SPEED;
}
// what's our our anglular velocity? // what's our our anglular velocity?
var angularVelocityMax = 70; // from observation var angularVelocityMax = 70; // from observation
var angularVelocity = filter.radToDeg(MyAvatar.getAngularVelocity().y); var angularVelocity = filter.radToDeg(MyAvatar.getAngularVelocity().y);
if (angularVelocity > angularVelocityMax) angularVelocity = angularVelocityMax; if (angularVelocity > angularVelocityMax) {
if (angularVelocity < -angularVelocityMax) angularVelocity = -angularVelocityMax; angularVelocity = angularVelocityMax;
}
if (angularVelocity < -angularVelocityMax) {
angularVelocity = -angularVelocityMax;
}
leanRollProgress = speed / TOP_SPEED; leanRollProgress = speed / TOP_SPEED;
if (motion.direction !== LEFT && if (motion.direction !== LEFT &&
motion.direction !== RIGHT) motion.direction !== RIGHT) {
leanRollProgress *= (Math.abs(angularVelocity) / angularVelocityMax); leanRollProgress *= (Math.abs(angularVelocity) / angularVelocityMax);
}
// apply our response curve // apply our response curve
leanRollProgress = filter.bezier((1 - leanRollProgress), leanRollProgress = filter.bezier((1 - leanRollProgress),
@ -502,14 +540,17 @@ function getLeanRoll(deltaTime, speed) {
{x: 1, y: 1}).y; {x: 1, y: 1}).y;
// which way to lean? // which way to lean?
var turnSign = -1; var turnSign = -1;
if (angularVelocity < 0.001) turnSign = 1; if (angularVelocity < 0.001) {
turnSign = 1;
}
if (motion.direction === BACKWARDS || if (motion.direction === BACKWARDS ||
motion.direction === LEFT) motion.direction === LEFT) {
turnSign *= -1; turnSign *= -1;
}
if (motion.direction === LEFT || if (motion.direction === LEFT ||
motion.direction === RIGHT) motion.direction === RIGHT) {
leanRollProgress *= 2; leanRollProgress *= 2;
}
// add damping with simple averaging filter // add damping with simple averaging filter
leanRollProgress = leanRollFilter.process(turnSign * leanRollProgress); leanRollProgress = leanRollFilter.process(turnSign * leanRollProgress);
@ -520,12 +561,13 @@ function playFootstep(side) {
var options = new AudioInjectionOptions(); var options = new AudioInjectionOptions();
options.position = Camera.getPosition(); options.position = Camera.getPosition();
options.volume = 0.2; options.volume = 0.3;
var soundNumber = 2; // 0 to 2 var soundNumber = 2; // 0 to 2
if (side === RIGHT && motion.makesFootStepSounds) if (side === RIGHT && motion.makesFootStepSounds) {
Audio.playSound(walkAssets.footsteps[soundNumber + 1], options); Audio.playSound(walkAssets.footsteps[soundNumber + 1], options);
else if (side === LEFT && motion.makesFootStepSounds) } else if (side === LEFT && motion.makesFootStepSounds) {
Audio.playSound(walkAssets.footsteps[soundNumber], options); Audio.playSound(walkAssets.footsteps[soundNumber], options);
}
} }
// animate the avatar using sine wave generators. inspired by Victorian clockwork dolls // animate the avatar using sine wave generators. inspired by Victorian clockwork dolls
@ -545,13 +587,15 @@ function animateAvatar(deltaTime, speed) {
// don't lean into the direction of travel if going up // don't lean into the direction of travel if going up
var leanMod = 1; var leanMod = 1;
if (motion.direction === UP) if (motion.direction === UP) {
leanMod = 0; leanMod = 0;
}
// adjust leaning direction for flying // adjust leaning direction for flying
var flyingModifier = 1; var flyingModifier = 1;
if (state.currentState.FLYING) if (state.currentState.FLYING) {
flyingModifier = -1; flyingModifier = -1;
}
if (motion.curTransition !== nullTransition) { if (motion.curTransition !== nullTransition) {
@ -573,20 +617,22 @@ function animateAvatar(deltaTime, speed) {
// find the closest stop point from the walk wheel's angle // find the closest stop point from the walk wheel's angle
var angleToLeftStop = 180 - Math.abs(Math.abs(motion.walkWheelPos - leftStop) - 180); var angleToLeftStop = 180 - Math.abs(Math.abs(motion.walkWheelPos - leftStop) - 180);
var angleToRightStop = 180 - Math.abs(Math.abs(motion.walkWheelPos - rightStop) - 180); var angleToRightStop = 180 - Math.abs(Math.abs(motion.walkWheelPos - rightStop) - 180);
if (motion.walkWheelPos > angleToLeftStop) angleToLeftStop = 360 - angleToLeftStop; if (motion.walkWheelPos > angleToLeftStop) {
if (motion.walkWheelPos > angleToRightStop) angleToRightStop = 360 - angleToRightStop; angleToLeftStop = 360 - angleToLeftStop;
}
if (motion.walkWheelPos > angleToRightStop) {
angleToRightStop = 360 - angleToRightStop;
}
motion.curTransition.walkWheelIncrement = 3; motion.curTransition.walkWheelIncrement = 3;
// keep the walkwheel turning by setting the walkWheelIncrement // keep the walkwheel turning by setting the walkWheelIncrement
// until our feet are tucked nicely underneath us. // until our feet are tucked nicely underneath us.
if (angleToLeftStop < angleToRightStop) if (angleToLeftStop < angleToRightStop) {
motion.curTransition.walkStopAngle = leftStop; motion.curTransition.walkStopAngle = leftStop;
} else {
else
motion.curTransition.walkStopAngle = rightStop; motion.curTransition.walkStopAngle = rightStop;
}
} else { } else {
@ -622,11 +668,9 @@ function animateAvatar(deltaTime, speed) {
motion.curTransition.walkWheelIncrement = 0; motion.curTransition.walkWheelIncrement = 0;
} }
// keep turning walk wheel until both feet are below the avi // keep turning walk wheel until both feet are below the avi
motion.advanceWalkWheel(motion.curTransition.walkWheelIncrement); motion.advanceWalkWheel(motion.curTransition.walkWheelIncrement);
//motion.curTransition.walkWheelAdvance += motion.curTransition.walkWheelIncrement;
} } else motion.curTransition.walkWheelIncrement = 0; // sidestep
else motion.curTransition.walkWheelIncrement = 0; // sidestep
} }
} } // end motion.curTransition !== nullTransition } } // end motion.curTransition !== nullTransition
@ -636,8 +680,9 @@ function animateAvatar(deltaTime, speed) {
// if the timing's right, take a snapshot of the stride max and recalibrate // if the timing's right, take a snapshot of the stride max and recalibrate
var strideMaxAt = motion.curAnim.calibration.forwardStrideMaxAt; var strideMaxAt = motion.curAnim.calibration.forwardStrideMaxAt;
if (motion.direction === BACKWARDS) if (motion.direction === BACKWARDS) {
strideMaxAt = motion.curAnim.calibration.backwardsStrideMaxAt; strideMaxAt = motion.curAnim.calibration.backwardsStrideMaxAt;
}
var tolerance = 1.0; var tolerance = 1.0;
if (motion.walkWheelPos < (strideMaxAt + tolerance) && if (motion.walkWheelPos < (strideMaxAt + tolerance) &&
@ -648,18 +693,20 @@ function animateAvatar(deltaTime, speed) {
var footLPos = MyAvatar.getJointPosition("LeftFoot"); var footLPos = MyAvatar.getJointPosition("LeftFoot");
motion.strideLength = Vec3.distance(footRPos, footLPos); motion.strideLength = Vec3.distance(footRPos, footLPos);
if (motion.direction === FORWARDS) if (motion.direction === FORWARDS) {
motion.curAnim.calibration.strideLengthForwards = motion.strideLength; motion.curAnim.calibration.strideLengthForwards = motion.strideLength;
else if (motion.direction === BACKWARDS) } else if (motion.direction === BACKWARDS) {
motion.curAnim.calibration.strideLengthBackwards = motion.strideLength; motion.curAnim.calibration.strideLengthBackwards = motion.strideLength;
}
} else { } else {
// use the saved value for stride length // use the saved value for stride length
if (motion.direction === FORWARDS) if (motion.direction === FORWARDS) {
motion.strideLength = motion.curAnim.calibration.strideLengthForwards; motion.strideLength = motion.curAnim.calibration.strideLengthForwards;
else if (motion.direction === BACKWARDS) } else if (motion.direction === BACKWARDS) {
motion.strideLength = motion.curAnim.calibration.strideLengthBackwards; motion.strideLength = motion.curAnim.calibration.strideLengthBackwards;
}
} }
} // end get walk stride length } // end get walk stride length
@ -714,8 +761,9 @@ function animateAvatar(deltaTime, speed) {
// if we are in an edit mode, we will need fake time to turn the wheel // if we are in an edit mode, we will need fake time to turn the wheel
if (state.currentState !== state.WALKING && if (state.currentState !== state.WALKING &&
state.currentState !== state.SIDE_STEP) state.currentState !== state.SIDE_STEP) {
degreesTurnedSinceLastFrame = motion.curAnim.calibration.frequency / 70; degreesTurnedSinceLastFrame = motion.curAnim.calibration.frequency / 70;
}
// advance the walk wheel the appropriate amount // advance the walk wheel the appropriate amount
motion.advanceWalkWheel(degreesTurnedSinceLastFrame); motion.advanceWalkWheel(degreesTurnedSinceLastFrame);
@ -758,12 +806,6 @@ function animateAvatar(deltaTime, speed) {
var sideStepFootPitchModifier = 1; var sideStepFootPitchModifier = 1;
var sideStepHandPitchSign = 1; var sideStepHandPitchSign = 1;
// The below code should probably be optimised into some sort of loop, where
// the joints are iterated through. However, this has not been done yet, as there
// are still some quite fundamental changes to be made (e.g. turning on the spot
// animation and sidestepping transitions) so it's been left as is for ease of
// understanding and editing.
// calculate hips translation // calculate hips translation
if (motion.curTransition !== nullTransition) { if (motion.curTransition !== nullTransition) {
@ -774,7 +816,9 @@ function animateAvatar(deltaTime, speed) {
motion.curAnim.joints[0].swayPhase)) + motion.curAnim.joints[0].swayOffset; motion.curAnim.joints[0].swayPhase)) + motion.curAnim.joints[0].swayOffset;
var bobPhase = motion.curAnim.joints[0].bobPhase; var bobPhase = motion.curAnim.joints[0].bobPhase;
if (motion.direction === motion.BACKWARDS) bobPhase += 90; if (motion.direction === motion.BACKWARDS) {
bobPhase += 90;
}
bobOsc = motion.curAnim.joints[0].bob * bobOsc = motion.curAnim.joints[0].bob *
Math.sin(filter.degToRad(motion.cumulativeTime * Math.sin(filter.degToRad(motion.cumulativeTime *
motion.curAnim.calibration.frequency + bobPhase)) + motion.curAnim.calibration.frequency + bobPhase)) +
@ -792,7 +836,9 @@ function animateAvatar(deltaTime, speed) {
motion.curTransition.lastAnim.joints[0].swayOffset; motion.curTransition.lastAnim.joints[0].swayOffset;
var bobPhaseLast = motion.curTransition.lastAnim.joints[0].bobPhase; var bobPhaseLast = motion.curTransition.lastAnim.joints[0].bobPhase;
if (motion.direction === motion.BACKWARDS) bobPhaseLast +=90; if (motion.direction === motion.BACKWARDS) {
bobPhaseLast +=90;
}
bobOscLast = motion.curTransition.lastAnim.joints[0].bob * bobOscLast = motion.curTransition.lastAnim.joints[0].bob *
Math.sin(filter.degToRad(motion.walkWheelPos + bobPhaseLast)); Math.sin(filter.degToRad(motion.walkWheelPos + bobPhaseLast));
bobOscLast = filter.clipTrough(bobOscLast, motion.curTransition.lastAnim.joints[0].bob , 2); bobOscLast = filter.clipTrough(bobOscLast, motion.curTransition.lastAnim.joints[0].bob , 2);
@ -804,15 +850,18 @@ function animateAvatar(deltaTime, speed) {
motion.curTransition.lastAnim.joints[0].thrustPhase)) + motion.curTransition.lastAnim.joints[0].thrustPhase)) +
motion.curTransition.lastAnim.joints[0].thrustOffset; motion.curTransition.lastAnim.joints[0].thrustOffset;
} // end if walking at start of transition // end if walking at start of transition
else {
} else {
swayOsc = motion.curAnim.joints[0].sway * swayOsc = motion.curAnim.joints[0].sway *
Math.sin(filter.degToRad(cycle * adjFreq + motion.curAnim.joints[0].swayPhase)) + Math.sin(filter.degToRad(cycle * adjFreq + motion.curAnim.joints[0].swayPhase)) +
motion.curAnim.joints[0].swayOffset; motion.curAnim.joints[0].swayOffset;
var bobPhase = motion.curAnim.joints[0].bobPhase; var bobPhase = motion.curAnim.joints[0].bobPhase;
if (motion.direction === motion.BACKWARDS) bobPhase += 90; if (motion.direction === motion.BACKWARDS) {
bobPhase += 90;
}
bobOsc = motion.curAnim.joints[0].bob * bobOsc = motion.curAnim.joints[0].bob *
Math.sin(filter.degToRad(cycle * adjFreq * 2 + bobPhase)); Math.sin(filter.degToRad(cycle * adjFreq * 2 + bobPhase));
if (state.currentState === state.WALKING || if (state.currentState === state.WALKING ||
@ -854,8 +903,9 @@ function animateAvatar(deltaTime, speed) {
bobOsc = (transProgress * bobOsc) + ((1 - transProgress) * bobOscLast); bobOsc = (transProgress * bobOsc) + ((1 - transProgress) * bobOscLast);
thrustOsc = (transProgress * thrustOsc) + ((1 - transProgress) * thrustOscLast); thrustOsc = (transProgress * thrustOsc) + ((1 - transProgress) * thrustOscLast);
}// if current transition active // end if walking at start of transition
else {
} else {
swayOsc = motion.curAnim.joints[0].sway * swayOsc = motion.curAnim.joints[0].sway *
Math.sin(filter.degToRad(cycle * adjFreq + motion.curAnim.joints[0].swayPhase)) + Math.sin(filter.degToRad(cycle * adjFreq + motion.curAnim.joints[0].swayPhase)) +