mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #2807 from PhilipRosedale/master
AirGuitar.js, arrow keys move fwd/back in mirror view
This commit is contained in:
commit
fec2ba71b5
4 changed files with 102 additions and 5 deletions
87
examples/airGuitar.js
Normal file
87
examples/airGuitar.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// airGuitar.js
|
||||
// examples
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This example musical instrument script plays guitar chords based on a strum motion and hand position
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
function length(v) {
|
||||
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||
}
|
||||
|
||||
|
||||
function printVector(v) {
|
||||
print(v.x + ", " + v.y + ", " + v.z);
|
||||
return;
|
||||
}
|
||||
|
||||
function vMinus(a, b) {
|
||||
var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
||||
return rval;
|
||||
}
|
||||
|
||||
// First, load two percussion sounds to be used on the sticks
|
||||
|
||||
var chord1 = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw");
|
||||
var chord2 = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+B.raw");
|
||||
var chord3 = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+E.raw");
|
||||
|
||||
var whichChord = chord1;
|
||||
|
||||
var leftHanded = false;
|
||||
if (leftHanded) {
|
||||
var strumHand = 0;
|
||||
var chordHand = 1;
|
||||
} else {
|
||||
var strumHand = 1;
|
||||
var chordHand = 0;
|
||||
}
|
||||
|
||||
var lastPosition = { x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0 };
|
||||
|
||||
|
||||
function checkHands(deltaTime) {
|
||||
for (var palm = 0; palm < 2; palm++) {
|
||||
var palmVelocity = Controller.getSpatialControlVelocity(palm * 2 + 1);
|
||||
var speed = length(palmVelocity);
|
||||
var position = Controller.getSpatialControlPosition(palm * 2 + 1);
|
||||
var myPelvis = MyAvatar.position;
|
||||
|
||||
if (palm == strumHand) {
|
||||
|
||||
var STRUM_HEIGHT_ABOVE_PELVIS = 0.15;
|
||||
var strumTriggerHeight = myPelvis.y + STRUM_HEIGHT_ABOVE_PELVIS;
|
||||
//printVector(position);
|
||||
if ((position.y < strumTriggerHeight) && (lastPosition.y >= strumTriggerHeight)) {
|
||||
// If hand passes downward through guitar strings, play a chord!
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = position;
|
||||
if (speed > 1.0) { speed = 1.0; }
|
||||
options.volume = speed;
|
||||
Audio.playSound(whichChord, options);
|
||||
}
|
||||
lastPosition = Controller.getSpatialControlPosition(palm * 2 + 1);
|
||||
} else {
|
||||
// This is the chord controller
|
||||
var distanceFromPelvis = Vec3.length(Vec3.subtract(position, myPelvis));
|
||||
//print(distanceFromPelvis);
|
||||
if (distanceFromPelvis > 0.50) {
|
||||
whichChord = chord3;
|
||||
} else if (distanceFromPelvis > 0.35) {
|
||||
whichChord = chord2;
|
||||
} else {
|
||||
whichChord = chord1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect a call back that happens every frame
|
||||
Script.update.connect(checkHands);
|
|
@ -37,7 +37,7 @@ var radiusMinimum = 0.05;
|
|||
var radiusMaximum = 0.5;
|
||||
|
||||
var modelURLs = [
|
||||
"https://s3-us-west-1.amazonaws.com/highfidelity-public/models/music/EVHFrankenstein.fbx",
|
||||
"https://s3-us-west-1.amazonaws.com/highfidelity-public/models/attachments/topHat.fst",
|
||||
"http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX",
|
||||
"http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/birarda/birarda_head.fbx",
|
||||
"http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/pug.fbx",
|
||||
|
@ -72,7 +72,6 @@ function keyPressEvent(event) {
|
|||
}
|
||||
} else if (event.text == "m") {
|
||||
var URL = Window.prompt("Model URL", "Enter URL, e.g. http://foo.com/model.fbx");
|
||||
Window.alert("Your response was: " + prompt);
|
||||
var modelPosition = getNewVoxelPosition();
|
||||
var properties = { position: { x: modelPosition.x,
|
||||
y: modelPosition.y,
|
||||
|
|
|
@ -151,6 +151,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_lastQueriedTime(usecTimestampNow()),
|
||||
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
|
||||
_cameraPushback(0.0f),
|
||||
_scaleMirror(1.0f),
|
||||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
_lastMouseMove(usecTimestampNow()),
|
||||
|
@ -570,7 +571,7 @@ void Application::paintGL() {
|
|||
_myCamera.setTightness(0.0f);
|
||||
glm::vec3 eyePosition = _myAvatar->getHead()->calculateAverageEyePosition();
|
||||
float headHeight = eyePosition.y - _myAvatar->getPosition().y;
|
||||
_myCamera.setDistance(MIRROR_FULLSCREEN_DISTANCE * _myAvatar->getScale());
|
||||
_myCamera.setDistance(MIRROR_FULLSCREEN_DISTANCE * _myAvatar->getScale() * _scaleMirror);
|
||||
_myCamera.setTargetPosition(_myAvatar->getPosition() + glm::vec3(0, headHeight, 0));
|
||||
_myCamera.setTargetRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
|
||||
|
||||
|
@ -868,11 +869,19 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
break;
|
||||
|
||||
case Qt::Key_Up:
|
||||
_myAvatar->setDriveKeys(isShifted ? UP : FWD, 1.f);
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
_scaleMirror *= 0.95;
|
||||
} else {
|
||||
_myAvatar->setDriveKeys(isShifted ? UP : FWD, 1.f);
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::Key_Down:
|
||||
_myAvatar->setDriveKeys(isShifted ? DOWN : BACK, 1.f);
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
_scaleMirror *= 1.05;
|
||||
} else {
|
||||
_myAvatar->setDriveKeys(isShifted ? DOWN : BACK, 1.f);
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::Key_Left:
|
||||
|
|
|
@ -455,6 +455,8 @@ private:
|
|||
glm::mat4 _untranslatedViewMatrix;
|
||||
glm::vec3 _viewMatrixTranslation;
|
||||
glm::mat4 _projectionMatrix;
|
||||
|
||||
float _scaleMirror;
|
||||
|
||||
glm::mat4 _shadowMatrix;
|
||||
|
||||
|
|
Loading…
Reference in a new issue