mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 23:49:55 +02:00
Add ability to set injector properties during playing, and orbitingSound.js
This commit is contained in:
parent
47c2ea95f4
commit
c5247ca65b
3 changed files with 58 additions and 0 deletions
49
examples/orbitingSound.js
Normal file
49
examples/orbitingSound.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// orbitingSound.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Philip Rosedale on December 4, 2014
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// An object playing a sound appears and circles you, changing brightness with the audio playing.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
var RADIUS = 2.0;
|
||||||
|
var orbitCenter = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.getOrientation()), RADIUS));
|
||||||
|
var time = 0;
|
||||||
|
var SPEED = 1.0;
|
||||||
|
var currentPosition = { x: 0, y: 0, z: 0 };
|
||||||
|
var trailingLoudness = 0.0;
|
||||||
|
|
||||||
|
var soundClip = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Tabla+Loops/Tabla1.wav");
|
||||||
|
|
||||||
|
var properties = {
|
||||||
|
type: "Box",
|
||||||
|
position: orbitCenter,
|
||||||
|
dimensions: { x: 0.25, y: 0.25, z: 0.25 },
|
||||||
|
color: { red: 100, green: 0, blue : 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
var objectId = Entities.addEntity(properties);
|
||||||
|
var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volume: 0.5 });
|
||||||
|
|
||||||
|
function update(deltaTime) {
|
||||||
|
time += deltaTime;
|
||||||
|
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
|
||||||
|
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound);
|
||||||
|
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
|
||||||
|
//if (Audio.isInjectorPlaying(sound)) {
|
||||||
|
Audio.setInjectorOptions(sound, { position: currentPosition });
|
||||||
|
//} else {
|
||||||
|
// sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volume: 0.5 });
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function() {
|
||||||
|
Entities.deleteEntity(objectId);
|
||||||
|
Audio.stopInjector(sound);
|
||||||
|
});
|
||||||
|
|
||||||
|
Script.update.connect(update);
|
|
@ -85,6 +85,13 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) {
|
||||||
return (injector != NULL);
|
return (injector != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioScriptingInterface::setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions) {
|
||||||
|
AudioInjectorOptions optionsCopy = injectorOptions;
|
||||||
|
if (injector) {
|
||||||
|
injector->setOptions(optionsCopy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float AudioScriptingInterface::getLoudness(AudioInjector* injector) {
|
float AudioScriptingInterface::getLoudness(AudioInjector* injector) {
|
||||||
if (injector) {
|
if (injector) {
|
||||||
return injector->getLoudness();
|
return injector->getLoudness();
|
||||||
|
|
|
@ -35,6 +35,8 @@ public slots:
|
||||||
void stopInjector(AudioInjector* injector);
|
void stopInjector(AudioInjector* injector);
|
||||||
bool isInjectorPlaying(AudioInjector* injector);
|
bool isInjectorPlaying(AudioInjector* injector);
|
||||||
|
|
||||||
|
void setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions);
|
||||||
|
|
||||||
void injectorStopped();
|
void injectorStopped();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in a new issue