overte/examples/crazylegs.js
Andrzej Kapolka fa05a48270 Provide a means of supplying the joint mappings in the FST file so that agent
scripts can address joints by name.  Closes #2526.
2014-04-07 17:55:36 -07:00

37 lines
1.3 KiB
JavaScript

//
// crazylegs.js
// hifi
//
// Created by Andrzej Kapolka on 3/6/14.
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
var FREQUENCY = 5.0;
var AMPLITUDE = 45.0;
var cumulativeTime = 0.0;
print("# Joint list start");
var jointList = MyAvatar.getJointNames();
for (var i = 0; i < jointList.length; i++) {
print("jointIndex = " + jointList[i] + " = " + i);
}
print("# Joint list end");
Script.update.connect(function(deltaTime) {
cumulativeTime += deltaTime;
MyAvatar.setJointData("joint_R_hip", Quat.fromPitchYawRollDegrees(0.0, 0.0, AMPLITUDE * Math.sin(cumulativeTime * FREQUENCY)));
MyAvatar.setJointData("joint_L_hip", Quat.fromPitchYawRollDegrees(0.0, 0.0, -AMPLITUDE * Math.sin(cumulativeTime * FREQUENCY)));
MyAvatar.setJointData("joint_R_knee", Quat.fromPitchYawRollDegrees(0.0, 0.0,
AMPLITUDE * (1.0 + Math.sin(cumulativeTime * FREQUENCY))));
MyAvatar.setJointData("joint_L_knee", Quat.fromPitchYawRollDegrees(0.0, 0.0,
AMPLITUDE * (1.0 - Math.sin(cumulativeTime * FREQUENCY))));
});
Script.scriptEnding.connect(function() {
MyAvatar.clearJointData("joint_R_hip");
MyAvatar.clearJointData("joint_L_hip");
MyAvatar.clearJointData("joint_R_knee");
MyAvatar.clearJointData("joint_L_knee");
});