Merge branch 'master' of https://github.com/worklist/hifi into 19507

This commit is contained in:
Stojce Slavkovski 2014-05-11 09:53:22 +02:00
commit ac8d27ee3a
7 changed files with 157 additions and 95 deletions

View file

@ -35,16 +35,26 @@ var chords = new Array();
chords[1] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw");
chords[2] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+B.raw");
chords[3] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+E.raw");
chords[4] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+G.raw");
// Electric guitar
chords[4] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+A+short.raw");
chords[5] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+B+short.raw");
chords[6] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+E+short.raw");
chords[5] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+A+short.raw");
chords[6] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+B+short.raw");
chords[7] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+E+short.raw");
chords[8] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Metal+G+short.raw");
var guitarSelector = 3;
// Steel Guitar
chords[9] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+A.raw");
chords[10] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+B.raw");
chords[11] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+E.raw");
chords[12] = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Steel+G.raw");
var whichChord = chords[guitarSelector + 1];
var NUM_CHORDS = 4;
var NUM_GUITARS = 3;
var guitarSelector = NUM_CHORDS;
var whichChord = 1;
var leftHanded = false;
var leftHanded = true;
if (leftHanded) {
var strumHand = 0;
var chordHand = 1;
@ -59,20 +69,23 @@ var lastPosition = { x: 0.0,
var soundPlaying = false;
var selectorPressed = false;
var position;
MyAvatar.attach(guitarModel, "Hips", {x: -0.0, y: -0.0, z: 0.0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.0);
function checkHands(deltaTime) {
for (var palm = 0; palm < 2; palm++) {
var palmVelocity = Controller.getSpatialControlVelocity(palm * 2 + 1);
var speed = length(palmVelocity) / 4.0;
var volume = length(palmVelocity) / 5.0;
var position = Controller.getSpatialControlPosition(palm * 2 + 1);
var myPelvis = MyAvatar.position;
var trigger = Controller.getTriggerValue(strumHand);
var chord = Controller.getTriggerValue(chordHand);
if (volume > 1.0) volume = 1.0;
if ((chord > 0.1) && Audio.isInjectorPlaying(soundPlaying)) {
// If chord finger trigger pulled, stop current chord
print("stopped sound");
Audio.stopInjector(soundPlaying);
}
@ -81,11 +94,10 @@ function checkHands(deltaTime) {
// Change guitars if button FWD (5) pressed
if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 5)) {
if (!selectorPressed) {
if (guitarSelector == 0) {
guitarSelector = 3;
} else {
guitarSelector += NUM_CHORDS;
if (guitarSelector >= NUM_CHORDS * NUM_GUITARS) {
guitarSelector = 0;
}
}
selectorPressed = true;
}
} else {
@ -93,38 +105,65 @@ function checkHands(deltaTime) {
}
if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 1)) {
whichChord = chords[guitarSelector + 1];
whichChord = 1;
} else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 2)) {
whichChord = chords[guitarSelector + 2];
whichChord = 2;
} else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 3)) {
whichChord = chords[guitarSelector + 3];
whichChord = 3;
} else if (Controller.isButtonPressed(chordHand * BUTTON_COUNT + 4)) {
whichChord = 4;
}
if (palm == strumHand) {
var STRUM_HEIGHT_ABOVE_PELVIS = 0.00;
var STRUM_HEIGHT_ABOVE_PELVIS = 0.10;
var strumTriggerHeight = myPelvis.y + STRUM_HEIGHT_ABOVE_PELVIS;
//printVector(position);
if ( ( ((position.y < strumTriggerHeight) && (lastPosition.y >= strumTriggerHeight)) ||
((position.y > strumTriggerHeight) && (lastPosition.y <= strumTriggerHeight)) ) && (trigger > 0.1) ){
// If hand passes downward or upward through 'strings', and finger trigger pulled, play
var options = new AudioInjectionOptions();
options.position = position;
if (speed > 1.0) { speed = 1.0; }
options.volume = speed;
if (Audio.isInjectorPlaying(soundPlaying)) {
Audio.stopInjector(soundPlaying);
}
soundPlaying = Audio.playSound(whichChord, options);
playChord(position, volume);
}
lastPosition = Controller.getSpatialControlPosition(palm * 2 + 1);
}
}
}
function playChord(position, volume) {
var options = new AudioInjectionOptions();
options.position = position;
options.volume = volume;
if (Audio.isInjectorPlaying(soundPlaying)) {
print("stopped sound");
Audio.stopInjector(soundPlaying);
}
print("Played sound: " + whichChord + " at volume " + options.volume);
soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], options);
}
function keyPressEvent(event) {
// check for keypresses and use those to trigger sounds if not hydra
keyVolume = 0.4;
if (event.text == "1") {
whichChord = 1;
playChord(MyAvatar.position, keyVolume);
} else if (event.text == "2") {
whichChord = 2;
playChord(MyAvatar.position, keyVolume);
} else if (event.text == "3") {
whichChord = 3;
playChord(MyAvatar.position, keyVolume);
} else if (event.text == "4") {
whichChord = 4;
playChord(MyAvatar.position, keyVolume);
}
}
function scriptEnding() {
MyAvatar.detachOne(guitarModel);
}
// Connect a call back that happens every frame
Script.update.connect(checkHands);
Script.scriptEnding.connect(scriptEnding);
Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -152,6 +152,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
_cameraPushback(0.0f),
_scaleMirror(1.0f),
_rotateMirror(0.0f),
_raiseMirror(0.0f),
_mouseX(0),
_mouseY(0),
_lastMouseMove(usecTimestampNow()),
@ -3374,71 +3376,6 @@ void Application::saveScripts() {
_settings->endArray();
}
void Application::stopAllScripts() {
// stops all current running scripts
for (int i = 0; i < _scriptEnginesHash.size(); ++i) {
_scriptEnginesHash.values().at(i)->stop();
qDebug() << "stopping script..." << getRunningScripts().at(i);
}
_scriptEnginesHash.clear();
_runningScriptsWidget->setRunningScripts(getRunningScripts());
bumpSettings();
}
void Application::stopScript(const QString &scriptName) {
if (_scriptEnginesHash.contains(scriptName)) {
_scriptEnginesHash.value(scriptName)->stop();
qDebug() << "stopping script..." << scriptName;
_scriptEnginesHash.remove(scriptName);
_runningScriptsWidget->setRunningScripts(getRunningScripts());
bumpSettings();
}
}
void Application::reloadAllScripts() {
// remember all the current scripts so we can reload them
QStringList reloadList = getRunningScripts();
// reloads all current running scripts
stopAllScripts();
foreach (QString scriptName, reloadList){
qDebug() << "reloading script..." << scriptName;
loadScript(scriptName);
}
}
void Application::manageRunningScriptsWidgetVisibility(bool shown) {
if (_runningScriptsWidgetWasVisible && shown) {
_runningScriptsWidget->show();
} else if (_runningScriptsWidgetWasVisible && !shown) {
_runningScriptsWidget->hide();
}
}
void Application::toggleRunningScriptsWidget() {
if (_runningScriptsWidgetWasVisible) {
_runningScriptsWidget->hide();
_runningScriptsWidgetWasVisible = false;
} else {
_runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(),
_window->size()));
_runningScriptsWidget->show();
_runningScriptsWidgetWasVisible = true;
}
}
void Application::uploadHead() {
uploadModel(HEAD_MODEL);
}
void Application::uploadSkeleton() {
uploadModel(SKELETON_MODEL);
}
void Application::uploadAttachment() {
uploadModel(ATTACHMENT_MODEL);
}
ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScriptFromEditor) {
if(loadScriptFromEditor && _scriptEnginesHash.contains(scriptName) && !_scriptEnginesHash[scriptName]->isFinished()){
return _scriptEnginesHash[scriptName];
@ -3518,6 +3455,67 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
return scriptEngine;
}
void Application::stopAllScripts(bool restart) {
// stops all current running scripts
for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
it != _scriptEnginesHash.constEnd(); it++) {
if (restart) {
connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));
}
it.value()->stop();
qDebug() << "stopping script..." << it.key();
}
_scriptEnginesHash.clear();
_runningScriptsWidget->setRunningScripts(getRunningScripts());
bumpSettings();
}
void Application::stopScript(const QString &scriptName) {
if (_scriptEnginesHash.contains(scriptName)) {
_scriptEnginesHash.value(scriptName)->stop();
qDebug() << "stopping script..." << scriptName;
_scriptEnginesHash.remove(scriptName);
_runningScriptsWidget->setRunningScripts(getRunningScripts());
bumpSettings();
}
}
void Application::reloadAllScripts() {
stopAllScripts(true);
}
void Application::manageRunningScriptsWidgetVisibility(bool shown) {
if (_runningScriptsWidgetWasVisible && shown) {
_runningScriptsWidget->show();
} else if (_runningScriptsWidgetWasVisible && !shown) {
_runningScriptsWidget->hide();
}
}
void Application::toggleRunningScriptsWidget() {
if (_runningScriptsWidgetWasVisible) {
_runningScriptsWidget->hide();
_runningScriptsWidgetWasVisible = false;
} else {
_runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(),
_window->size()));
_runningScriptsWidget->show();
_runningScriptsWidgetWasVisible = true;
}
}
void Application::uploadHead() {
uploadModel(HEAD_MODEL);
}
void Application::uploadSkeleton() {
uploadModel(SKELETON_MODEL);
}
void Application::uploadAttachment() {
uploadModel(ATTACHMENT_MODEL);
}
QString Application::getPreviousScriptLocation() {
QString suggestedName;
if (_previousScriptLocation.isEmpty()) {

View file

@ -127,7 +127,6 @@ public:
~Application();
void restoreSizeAndPosition();
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
void loadScripts();
QString getPreviousScriptLocation();
void setPreviousScriptLocation(const QString& previousScriptLocation);
@ -292,7 +291,8 @@ public slots:
void loadScriptURLDialog();
void toggleLogDialog();
void initAvatarAndViewFrustum();
void stopAllScripts();
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
void stopAllScripts(bool restart = false);
void stopScript(const QString& scriptName);
void reloadAllScripts();
void toggleRunningScriptsWidget();

View file

@ -353,7 +353,7 @@ void Avatar::renderBody(RenderMode renderMode, float glowLevel) {
return;
}
_skeletonModel.render(1.0f, modelRenderMode);
renderAttachments(modelRenderMode);
renderAttachments(renderMode);
getHand()->render(false, modelRenderMode);
}
getHead()->render(1.0f, modelRenderMode);
@ -370,6 +370,9 @@ void Avatar::simulateAttachments(float deltaTime) {
int jointIndex = getJointIndex(attachment.jointName);
glm::vec3 jointPosition;
glm::quat jointRotation;
if (!isMyAvatar()) {
model->setLODDistance(getLODDistance());
}
if (_skeletonModel.getJointPosition(jointIndex, jointPosition) &&
_skeletonModel.getJointRotation(jointIndex, jointRotation)) {
model->setTranslation(jointPosition + jointRotation * attachment.translation * _scale);
@ -380,9 +383,11 @@ void Avatar::simulateAttachments(float deltaTime) {
}
}
void Avatar::renderAttachments(Model::RenderMode renderMode) {
void Avatar::renderAttachments(RenderMode renderMode) {
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
foreach (Model* model, _attachmentModels) {
model->render(1.0f, renderMode);
model->render(1.0f, modelRenderMode);
}
}

View file

@ -192,7 +192,7 @@ protected:
virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const;
void simulateAttachments(float deltaTime);
void renderAttachments(Model::RenderMode renderMode);
virtual void renderAttachments(RenderMode renderMode);
virtual void updateJointMappings();

View file

@ -669,7 +669,7 @@ void MyAvatar::renderBody(RenderMode renderMode, float glowLevel) {
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
_skeletonModel.render(1.0f, modelRenderMode);
renderAttachments(modelRenderMode);
renderAttachments(renderMode);
// Render head so long as the camera isn't inside it
if (shouldRenderHead(Application::getInstance()->getCamera()->getPosition(), renderMode)) {
@ -1489,6 +1489,23 @@ void MyAvatar::updateMotionBehaviorsFromMenu() {
}
}
void MyAvatar::renderAttachments(RenderMode renderMode) {
if (!Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON || renderMode == MIRROR_RENDER_MODE) {
Avatar::renderAttachments(renderMode);
return;
}
const FBXGeometry& geometry = _skeletonModel.getGeometry()->getFBXGeometry();
QString headJointName = (geometry.headJointIndex == -1) ? QString() : geometry.joints.at(geometry.headJointIndex).name;
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
for (int i = 0; i < _attachmentData.size(); i++) {
const QString& jointName = _attachmentData.at(i).jointName;
if (jointName != headJointName && jointName != "Head") {
_attachmentModels.at(i)->render(1.0f, modelRenderMode);
}
}
}
void MyAvatar::setCollisionGroups(quint32 collisionGroups) {
Avatar::setCollisionGroups(collisionGroups & VALID_COLLISION_GROUPS);
Menu* menu = Menu::getInstance();

View file

@ -121,6 +121,9 @@ public slots:
signals:
void transformChanged();
protected:
virtual void renderAttachments(RenderMode renderMode);
private:
bool _mousePressed;
float _bodyPitchDelta; // degrees