From f97109f6a4042365b4943302b61c340080d1fe6e Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Jan 2015 16:00:07 -0800 Subject: [PATCH 01/52] Add outputBufferSizeFrames property to Audio --- interface/src/Audio.cpp | 22 +++++++++++++++++++--- interface/src/Audio.h | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 5bcd9bb647..a75c5b04d2 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -60,6 +60,8 @@ static const int MUTE_ICON_SIZE = 24; static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100; +static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; + Audio::Audio(QObject* parent) : AbstractAudioInterface(parent), _audioInput(NULL), @@ -123,6 +125,7 @@ Audio::Audio(QObject* parent) : _inputRingBufferMsecsAvailableStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS), _audioOutputMsecsUnplayedStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS), _lastSentAudioPacket(0), + _outputBufferSizeFrames(DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES), _packetSentTimeGaps(1, APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS), _audioOutputIODevice(_receivedAudioStream) { @@ -443,6 +446,7 @@ void Audio::start() { QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput); qDebug() << "The default audio output device is" << outputDeviceInfo.deviceName(); bool outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo); + outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo); if (!inputFormatSupported) { qDebug() << "Unable to set up audio input because of a problem with input format."; @@ -1852,11 +1856,9 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo) outputFormatChanged(); - const int AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; - // setup our general output device for audio-mixer audio _audioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this); - _audioOutput->setBufferSize(AUDIO_OUTPUT_BUFFER_SIZE_FRAMES * _outputFrameSize * sizeof(int16_t)); + _audioOutput->setBufferSize(_outputBufferSizeFrames * _outputFrameSize * sizeof(int16_t)); qDebug() << "Output Buffer capacity in frames: " << _audioOutput->bufferSize() / sizeof(int16_t) / (float)_outputFrameSize; _audioOutputIODevice.start(); @@ -1877,6 +1879,20 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo) return supportedFormat; } +void Audio::setOutputBufferSize(int numFrames) { + if (numFrames != _outputBufferSizeFrames) { + qDebug() << "Audio output buffer size (frames): " << numFrames; + _outputBufferSizeFrames = numFrames; + + if (_audioOutput) { + // The buffer size can't be adjusted after QAudioOutput::start() has been called, so + // recreate the device by switching to the default. + QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput); + switchOutputToAudioDevice(outputDeviceInfo); + } + } +} + // The following constant is operating system dependent due to differences in // the way input audio is handled. The audio input buffer size is inversely // proportional to the accelerator ratio. diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 47fe00a84c..3ce5e4c180 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -123,6 +123,8 @@ public: void setRecorder(RecorderPointer recorder) { _recorder = recorder; } + int getOutputBufferSize() { return _outputBufferSizeFrames; } + public slots: void start(); void stop(); @@ -150,6 +152,7 @@ public slots: void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel); void addStereoSamplesToScope(const QByteArray& samples); void processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer); + void setOutputBufferSize(int numFrames); virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector); @@ -201,6 +204,8 @@ private: QString _inputAudioDeviceName; QString _outputAudioDeviceName; + + int _outputBufferSizeFrames; StDev _stdev; QElapsedTimer _timeSinceLastReceived; From 4c5bb66bd7e6f68b3d92729f17ea981d2435e2aa Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Jan 2015 16:01:04 -0800 Subject: [PATCH 02/52] Add audio output buffer size to preferences --- interface/src/ui/PreferencesDialog.cpp | 7 + interface/ui/preferencesDialog.ui | 281 ++++++++++++++++++------- 2 files changed, 211 insertions(+), 77 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 7baacd3d5a..947f6dea70 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -135,6 +135,8 @@ void PreferencesDialog::loadPreferences() { ui.windowSecondsForDesiredReductionSpin->setValue(streamSettings._windowSecondsForDesiredReduction); ui.repetitionWithFadeCheckBox->setChecked(streamSettings._repetitionWithFade); + ui.outputBufferSizeSpinner->setValue(Application::getInstance()->getAudio()->getOutputBufferSize()); + ui.realWorldFieldOfViewSpin->setValue(menuInstance->getRealWorldFieldOfView()); ui.fieldOfViewSpin->setValue(menuInstance->getFieldOfView()); @@ -245,9 +247,14 @@ void PreferencesDialog::savePreferences() { streamSettings._windowSecondsForDesiredReduction = ui.windowSecondsForDesiredReductionSpin->value(); streamSettings._repetitionWithFade = ui.repetitionWithFadeCheckBox->isChecked(); + Audio* audio = Application::getInstance()->getAudio(); + Menu::getInstance()->setReceivedAudioStreamSettings(streamSettings); + audio->setReceivedAudioStreamSettings(streamSettings); Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings); + QMetaObject::invokeMethod(audio, "setOutputBufferSize", Q_ARG(int, ui.outputBufferSizeSpinner->value())); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Application::getInstance()->bumpSettings(); diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 0108437c1f..864f8aa282 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -59,9 +59,9 @@ 0 - 0 - 500 - 1386 + -690 + 485 + 1499 @@ -1126,6 +1126,185 @@ + + + + 0 + + + 7 + + + 0 + + + 7 + + + + + + Arial + + + + Faceshift eye detection + + + 0 + + + faceshiftEyeDeflectionSider + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 130 + 0 + + + + + Arial + + + + Qt::Horizontal + + + + + + + + + 0 + + + 7 + + + 0 + + + 7 + + + + + + Arial + + + + Faceshift hostname + + + 0 + + + faceshiftHostnameEdit + + + + + + + + Arial + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + Arial + + + + Qt::LeftToRight + + + + + + localhost + + + + + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + Arial + 18 + 75 + true + + + + color:#29967e + + + Audio + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + @@ -1651,7 +1830,7 @@ - + 0 @@ -1664,26 +1843,26 @@ 7 - - + + Arial - Faceshift eye detection + Output Buffer Size (Frames) 0 - faceshiftEyeDeflectionSider + windowSecondsForDesiredReductionSpin - + Arial @@ -1701,7 +1880,7 @@ - + 0 @@ -1710,86 +1889,34 @@ - 130 + 100 0 + + + 70 + 16777215 + + Arial - - Qt::Horizontal + + 1 + + + 20 + + + 1 - - - - 0 - - - 7 - - - 0 - - - 7 - - - - - - Arial - - - - Faceshift hostname - - - 0 - - - faceshiftHostnameEdit - - - - - - - - Arial - - - - Qt::Horizontal - - - - - - - - Arial - - - - Qt::LeftToRight - - - - - - localhost - - - - - From 0d71d25063925e73fd558856f2456af127e6bc1f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Jan 2015 17:02:44 -0800 Subject: [PATCH 03/52] Add min/max for audio buffer size --- interface/src/Audio.cpp | 3 +-- interface/src/Audio.h | 3 +++ interface/src/ui/PreferencesDialog.cpp | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index a75c5b04d2..a57d9d4376 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -60,8 +60,6 @@ static const int MUTE_ICON_SIZE = 24; static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100; -static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; - Audio::Audio(QObject* parent) : AbstractAudioInterface(parent), _audioInput(NULL), @@ -1880,6 +1878,7 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo) } void Audio::setOutputBufferSize(int numFrames) { + numFrames = std::min(std::max(numFrames, MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES), MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES); if (numFrames != _outputBufferSizeFrames) { qDebug() << "Audio output buffer size (frames): " << numFrames; _outputBufferSizeFrames = numFrames; diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 3ce5e4c180..7ec730d0e3 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -61,6 +61,9 @@ static const int NUM_AUDIO_CHANNELS = 2; static const int MAX_16_BIT_AUDIO_SAMPLE = 32767; +static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; +static const int MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 1; +static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 50; class QAudioInput; class QAudioOutput; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 947f6dea70..d8a6040106 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -11,6 +11,7 @@ #include "Application.h" +#include "Audio.h" #include "MainWindow.h" #include "Menu.h" #include "ModelsBrowser.h" @@ -27,6 +28,9 @@ PreferencesDialog::PreferencesDialog() : ui.setupUi(this); loadPreferences(); + ui.outputBufferSizeSpinner->setMinimum(MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES); + ui.outputBufferSizeSpinner->setMaximum(MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES); + connect(ui.buttonBrowseHead, &QPushButton::clicked, this, &PreferencesDialog::openHeadModelBrowser); connect(ui.buttonBrowseBody, &QPushButton::clicked, this, &PreferencesDialog::openBodyModelBrowser); connect(ui.buttonBrowseLocation, &QPushButton::clicked, this, &PreferencesDialog::openSnapshotLocationBrowser); From 4a72a4be834bcf33eb9f6ab6e2d4bc810270984a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Jan 2015 17:03:01 -0800 Subject: [PATCH 04/52] Add audio output buffer size to settings --- interface/src/Menu.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 3e9bdde1ff..88841921c3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -41,6 +41,7 @@ #include "Application.h" #include "AccountManager.h" +#include "Audio.h" #include "devices/Faceshift.h" #include "devices/OculusManager.h" #include "devices/Visage.h" @@ -671,6 +672,10 @@ void Menu::loadSettings(QSettings* settings) { _receivedAudioStreamSettings._windowSecondsForDesiredCalcOnTooManyStarves = settings->value("windowSecondsForDesiredCalcOnTooManyStarves", DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES).toInt(); _receivedAudioStreamSettings._windowSecondsForDesiredReduction = settings->value("windowSecondsForDesiredReduction", DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION).toInt(); _receivedAudioStreamSettings._repetitionWithFade = settings->value("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE).toBool(); + + Audio* audio = Application::getInstance()->getAudio(); + int bufferSize = settings->value("audioOutputBufferSize", DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES).toInt(); + QMetaObject::invokeMethod(audio, "setOutputBufferSize", Q_ARG(int, bufferSize)); _fieldOfView = loadSetting(settings, "fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES); _realWorldFieldOfView = loadSetting(settings, "realWorldFieldOfView", DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES); @@ -740,6 +745,8 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("windowSecondsForDesiredReduction", _receivedAudioStreamSettings._windowSecondsForDesiredReduction); settings->setValue("repetitionWithFade", _receivedAudioStreamSettings._repetitionWithFade); + settings->setValue("audioOutputBufferSize", Application::getInstance()->getAudio()->getOutputBufferSize()); + settings->setValue("fieldOfView", _fieldOfView); settings->setValue("faceshiftEyeDeflection", _faceshiftEyeDeflection); settings->setValue("faceshiftHostname", _faceshiftHostname); From bd38df2a152daca5a0ad83fe1ef4ca63a4befb64 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 13:58:58 -0800 Subject: [PATCH 05/52] replace GL_LINES with a call to renderWireBox for node bounds --- interface/src/ui/NodeBounds.cpp | 44 ++------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index fe8a394fe4..a342fe8ada 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include "Application.h" @@ -155,52 +156,11 @@ void NodeBounds::draw() { void NodeBounds::drawNodeBorder(const glm::vec3& center, float scale, float red, float green, float blue) { glPushMatrix(); - glTranslatef(center.x, center.y, center.z); glScalef(scale, scale, scale); - glLineWidth(2.5); glColor3f(red, green, blue); - glBegin(GL_LINES); - - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f( 0.5, -0.5, -0.5); - - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f(-0.5, 0.5, -0.5); - - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f(-0.5, -0.5, 0.5); - - glVertex3f(-0.5, 0.5, -0.5); - glVertex3f( 0.5, 0.5, -0.5); - - glVertex3f(-0.5, 0.5, -0.5); - glVertex3f(-0.5, 0.5, 0.5); - - glVertex3f( 0.5, 0.5, 0.5); - glVertex3f(-0.5, 0.5, 0.5); - - glVertex3f( 0.5, 0.5, 0.5); - glVertex3f( 0.5, -0.5, 0.5); - - glVertex3f( 0.5, 0.5, 0.5); - glVertex3f( 0.5, 0.5, -0.5); - - glVertex3f( 0.5, -0.5, 0.5); - glVertex3f(-0.5, -0.5, 0.5); - - glVertex3f( 0.5, -0.5, 0.5); - glVertex3f( 0.5, -0.5, -0.5); - - glVertex3f( 0.5, 0.5, -0.5); - glVertex3f( 0.5, -0.5, -0.5); - - glVertex3f(-0.5, 0.5, 0.5); - glVertex3f(-0.5, -0.5, 0.5); - - glEnd(); - + DependencyManager::get()->renderWireCube(1.0f); glPopMatrix(); } From c2d45df541783973288ea850ce2a551c03a39a91 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 14:39:14 -0800 Subject: [PATCH 06/52] add renderBevelCornersRect to GeometryCache --- interface/src/Util.cpp | 22 +-- interface/src/ui/ApplicationOverlay.cpp | 34 ++--- libraries/render-utils/src/GeometryCache.cpp | 153 +++++++++++++++---- libraries/render-utils/src/GeometryCache.h | 27 ++-- 4 files changed, 162 insertions(+), 74 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 45a7dabb40..61d00dbff4 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -135,29 +135,9 @@ void renderCollisionOverlay(int width, int height, float magnitude, float red, f } void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance) { - glBegin(GL_POLYGON); - - // left side - glVertex2f(x, y + bevelDistance); - glVertex2f(x, y + height - bevelDistance); - - // top side - glVertex2f(x + bevelDistance, y + height); - glVertex2f(x + width - bevelDistance, y + height); - - // right - glVertex2f(x + width, y + height - bevelDistance); - glVertex2f(x + width, y + bevelDistance); - - // bottom - glVertex2f(x + width - bevelDistance, y); - glVertex2f(x +bevelDistance, y); - - glEnd(); + DependencyManager::get()->renderBevelCornersRect(x, y, width, height, bevelDistance); } - - void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) { glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; glm::vec3 pUp = position + orientation * IDENTITY_UP * size; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 6b45d792d0..d9194e54be 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -114,8 +114,8 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f); glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f); glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha); - if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _reticleQuad = DependencyManager::get()->allocateQuad(); + if (_reticleQuad == GeometryCache::UNKNOWN_ID) { + _reticleQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(topLeft, bottomLeft, bottomRight, topRight, glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), @@ -130,11 +130,11 @@ ApplicationOverlay::ApplicationOverlay() : _alpha(1.0f), _oculusUIRadius(1.0f), _crosshairTexture(0), - _reticleQuad(GeometryCache::UNKNOWN_QUAD_ID), - _magnifierQuad(GeometryCache::UNKNOWN_QUAD_ID), - _audioRedQuad(GeometryCache::UNKNOWN_QUAD_ID), - _audioGreenQuad(GeometryCache::UNKNOWN_QUAD_ID), - _audioBlueQuad(GeometryCache::UNKNOWN_QUAD_ID) + _reticleQuad(GeometryCache::UNKNOWN_ID), + _magnifierQuad(GeometryCache::UNKNOWN_ID), + _audioRedQuad(GeometryCache::UNKNOWN_ID), + _audioGreenQuad(GeometryCache::UNKNOWN_ID), + _audioBlueQuad(GeometryCache::UNKNOWN_ID) { memset(_reticleActive, 0, sizeof(_reticleActive)); memset(_magActive, 0, sizeof(_reticleActive)); @@ -399,8 +399,8 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _reticleQuad = DependencyManager::get()->allocateQuad(); + if (_reticleQuad == GeometryCache::UNKNOWN_ID) { + _reticleQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance), @@ -757,8 +757,8 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool } glColor4f(1.0f, 1.0f, 1.0f, _alpha); - if (_magnifierQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _magnifierQuad = DependencyManager::get()->allocateQuad(); + if (_magnifierQuad == GeometryCache::UNKNOWN_ID) { + _magnifierQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(bottomLeft, bottomRight, topRight, topLeft, @@ -865,8 +865,8 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Red Quad - if (_audioRedQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _audioRedQuad = DependencyManager::get()->allocateQuad(); + if (_audioRedQuad == GeometryCache::UNKNOWN_ID) { + _audioRedQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET, @@ -884,8 +884,8 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Green Quad - if (_audioGreenQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _audioGreenQuad = DependencyManager::get()->allocateQuad(); + if (_audioGreenQuad == GeometryCache::UNKNOWN_ID) { + _audioGreenQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET, @@ -902,8 +902,8 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Blue (low level) quad - if (_audioBlueQuad == GeometryCache::UNKNOWN_QUAD_ID) { - _audioBlueQuad = DependencyManager::get()->allocateQuad(); + if (_audioBlueQuad == GeometryCache::UNKNOWN_ID) { + _audioBlueQuad = DependencyManager::get()->allocateID(); } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET, diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 7e415a5d0d..bb7244f07e 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -25,10 +25,10 @@ //#define WANT_DEBUG -const int GeometryCache::UNKNOWN_QUAD_ID = -1; +const int GeometryCache::UNKNOWN_ID = -1; GeometryCache::GeometryCache() : - _nextQuadID(0) + _nextID(0) { } @@ -667,15 +667,116 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID) { +void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, int id) { + bool registeredRect = (id != UNKNOWN_ID); + Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); + VerticesIndices& vbo = registeredRect ? _registeredRectVBOs[id] : _rectVBOs[key]; - bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed + if (registeredRect && vbo.first != 0) { + Vec3Pair& lastKey = _lastRegisteredRect[id]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderBevelCornersRect()... RELEASING REGISTERED RECT"; + #endif // def WANT_DEBUG + } + #ifdef WANT_DEBUG + else { + qDebug() << "renderBevelCornersRect()... REUSING PREVIOUSLY REGISTERED RECT"; + } + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 2; + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int vertices = 8; + const int indices = 8; + if (vbo.first == 0) { + _lastRegisteredRect[id] = key; + + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat* vertex = vertexData; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3, 4, 5, 6, 7}; + + int vertexPoint = 0; + + // left side + vertex[vertexPoint++] = x; + vertex[vertexPoint++] = y + bevelDistance; + + vertex[vertexPoint++] = x; + vertex[vertexPoint++] = y + height - bevelDistance; + + // top side + vertex[vertexPoint++] = x + bevelDistance; + vertex[vertexPoint++] = y + height; + + vertex[vertexPoint++] = x + width - bevelDistance; + vertex[vertexPoint++] = y + height; + + // right + vertex[vertexPoint++] = x + width; + vertex[vertexPoint++] = y + height - bevelDistance; + vertex[vertexPoint++] = x + width; + vertex[vertexPoint++] = y + bevelDistance; + + // bottom + vertex[vertexPoint++] = x + width - bevelDistance; + vertex[vertexPoint++] = y; + vertex[vertexPoint++] = x +bevelDistance; + vertex[vertexPoint++] = y; + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + #ifdef WANT_DEBUG + if (id == UNKNOWN_ID) { + qDebug() << "new rect VBO made -- _rectVBOs.size():" << _rectVBOs.size(); + } else { + qDebug() << "new registered rect VBO made -- _registeredRectVBOs.size():" << _registeredRectVBOs.size(); + } + #endif + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); + glDrawRangeElementsEXT(GL_POLYGON, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glDisableClientState(GL_VERTEX_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + +} + +void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id) { + + bool registeredQuad = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad2DVBOs[key]; // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { - Vec2Pair& lastKey = _lastRegisteredQuad2D[quadID]; + Vec2Pair& lastKey = _lastRegisteredQuad2D[id]; if (lastKey != key) { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); @@ -696,7 +797,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC const int vertices = 4; const int indices = 4; if (vbo.first == 0) { - _lastRegisteredQuad2D[quadID] = key; + _lastRegisteredQuad2D[id] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad GLfloat* vertex = vertexData; @@ -728,7 +829,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC delete[] indexData; #ifdef WANT_DEBUG - if (quadID == UNKNOWN_QUAD_ID) { + if (id == UNKNOWN_ID) { qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); } else { qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); @@ -750,15 +851,15 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, - const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID) { + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int id) { - bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); + bool registeredQuad = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad2DTextureVBOs[key]; // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { - Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[quadID]; + Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[id]; if (lastKey != key) { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); @@ -779,7 +880,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC const int vertices = 4; const int indices = 4; if (vbo.first == 0) { - _lastRegisteredQuad2DTexture[quadID] = key; + _lastRegisteredQuad2DTexture[id] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices GLfloat* vertex = vertexData; @@ -823,7 +924,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC delete[] indexData; #ifdef WANT_DEBUG - if (quadID == UNKNOWN_QUAD_ID) { + if (id == UNKNOWN_ID) { qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); } else { qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); @@ -848,15 +949,15 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID) { +void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int id) { - bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); + bool registeredQuad = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DVBOs[key]; // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { - Vec3Pair& lastKey = _lastRegisteredQuad3D[quadID]; + Vec3Pair& lastKey = _lastRegisteredQuad3D[id]; if (lastKey != key) { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); @@ -877,7 +978,7 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC const int vertices = 4; const int indices = 4; if (vbo.first == 0) { - _lastRegisteredQuad3D[quadID] = key; + _lastRegisteredQuad3D[id] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices GLfloat* vertex = vertexData; @@ -917,7 +1018,7 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC delete[] indexData; #ifdef WANT_DEBUG - if (quadID == UNKNOWN_QUAD_ID) { + if (id == UNKNOWN_ID) { qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); } else { qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); @@ -941,7 +1042,7 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID) { + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id) { #ifdef WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; @@ -953,13 +1054,13 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom qDebug() << " texCoordBottomRight:" << texCoordBottomRight; #endif //def WANT_DEBUG - bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); + bool registeredQuad = (id != UNKNOWN_ID); Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DTextureVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DTextureVBOs[key]; // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { - Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[quadID]; + Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[id]; if (lastKey != key) { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); @@ -980,7 +1081,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const int vertices = 4; const int indices = 4; if (vbo.first == 0) { - _lastRegisteredQuad3DTexture[quadID] = key; + _lastRegisteredQuad3DTexture[id] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices GLfloat* vertex = vertexData; @@ -1028,7 +1129,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom delete[] indexData; #ifdef WANT_DEBUG - if (quadID == UNKNOWN_QUAD_ID) { + if (id == UNKNOWN_ID) { qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); } else { qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index f7b4489cc8..4a62c296db 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -81,6 +81,9 @@ class GeometryCache : public ResourceCache { SINGLETON_DEPENDENCY(GeometryCache) public: + int allocateID() { return _nextID++; } + static const int UNKNOWN_ID; + void renderHemisphere(int slices, int stacks); void renderSphere(float radius, int slices, int stacks, bool solid = true); void renderSquare(int xDivisions, int yDivisions); @@ -89,24 +92,22 @@ public: void renderGrid(int xDivisions, int yDivisions); void renderSolidCube(float size); void renderWireCube(float size); + void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, int id = UNKNOWN_ID); - int allocateQuad() { return _nextQuadID++; } - static const int UNKNOWN_QUAD_ID; - - void renderQuad(int x, int y, int width, int height, int quadID = UNKNOWN_QUAD_ID) - { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), quadID); } + void renderQuad(int x, int y, int width, int height, int id = UNKNOWN_ID) + { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), id); } - void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID = UNKNOWN_QUAD_ID); + void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id = UNKNOWN_ID); void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, - const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID = UNKNOWN_QUAD_ID); + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int id = UNKNOWN_ID); - void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID = UNKNOWN_QUAD_ID); + void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int id = UNKNOWN_ID); void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID = UNKNOWN_QUAD_ID); + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id = UNKNOWN_ID); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable @@ -137,13 +138,19 @@ private: QHash _quad3DVBOs; QHash _quad3DTextureVBOs; QHash _registeredQuadVBOs; - int _nextQuadID; + int _nextID; QHash _lastRegisteredQuad2D; QHash _lastRegisteredQuad2DTexture; QHash _lastRegisteredQuad3D; QHash _lastRegisteredQuad3DTexture; + QHash _lastRegisteredRect; + QHash _rectVBOs; + QHash _registeredRectVBOs; + + + QHash _gridBuffers; QHash > _networkGeometry; From a20fa1242d21bbe42db02ddba218444eaa775588 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 15:46:48 -0800 Subject: [PATCH 07/52] first cut are removing immediate mode GL_LINES --- interface/src/Util.cpp | 46 +---- interface/src/Util.h | 3 - interface/src/avatar/SkeletonModel.cpp | 32 +++- interface/src/avatar/SkeletonModel.h | 8 + interface/src/ui/overlays/Line3DOverlay.cpp | 9 +- interface/src/ui/overlays/Line3DOverlay.h | 1 + libraries/render-utils/src/GeometryCache.cpp | 171 ++++++++++++++++++- libraries/render-utils/src/GeometryCache.h | 12 ++ 8 files changed, 234 insertions(+), 48 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 61d00dbff4..a3c49e4c1f 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -34,6 +34,8 @@ using namespace std; void renderWorldBox() { + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + // Show edge of world float red[] = {1, 0, 0}; float green[] = {0, 1, 0}; @@ -42,22 +44,17 @@ void renderWorldBox() { glDisable(GL_LIGHTING); glLineWidth(1.0); - glBegin(GL_LINES); glColor3fv(red); - glVertex3f(0, 0, 0); - glVertex3f(TREE_SCALE, 0, 0); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(TREE_SCALE, 0, 0)); glColor3fv(green); - glVertex3f(0, 0, 0); - glVertex3f(0, TREE_SCALE, 0); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, TREE_SCALE, 0)); glColor3fv(blue); - glVertex3f(0, 0, 0); - glVertex3f(0, 0, TREE_SCALE); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, TREE_SCALE)); glColor3fv(gray); - glVertex3f(0, 0, TREE_SCALE); - glVertex3f(TREE_SCALE, 0, TREE_SCALE); - glVertex3f(TREE_SCALE, 0, TREE_SCALE); - glVertex3f(TREE_SCALE, 0, 0); - glEnd(); + geometryCache->renderLine(glm::vec3(0, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, TREE_SCALE)); + geometryCache->renderLine(glm::vec3(TREE_SCALE, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, 0)); + + // Draw meter markers along the 3 axis to help with measuring things const float MARKER_DISTANCE = 1.0f; const float MARKER_RADIUS = 0.05f; @@ -65,7 +62,6 @@ void renderWorldBox() { glPushMatrix(); glTranslatef(MARKER_DISTANCE, 0, 0); glColor3fv(red); - GeometryCache::SharedPointer geometryCache = DependencyManager::get(); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); @@ -138,30 +134,6 @@ void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistan DependencyManager::get()->renderBevelCornersRect(x, y, width, height, bevelDistance); } -void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) { - glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; - glm::vec3 pUp = position + orientation * IDENTITY_UP * size; - glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; - - glColor3f(1.0f, 0.0f, 0.0f); - glBegin(GL_LINE_STRIP); - glVertex3f(position.x, position.y, position.z); - glVertex3f(pRight.x, pRight.y, pRight.z); - glEnd(); - - glColor3f(0.0f, 1.0f, 0.0f); - glBegin(GL_LINE_STRIP); - glVertex3f(position.x, position.y, position.z); - glVertex3f(pUp.x, pUp.y, pUp.z); - glEnd(); - - glColor3f(0.0f, 0.0f, 1.0f); - glBegin(GL_LINE_STRIP); - glVertex3f(position.x, position.y, position.z); - glVertex3f(pFront.x, pFront.y, pFront.z); - glEnd(); -} - // Do some basic timing tests and report the results void runTimingTests() { // How long does it take to make a call to get the time? diff --git a/interface/src/Util.h b/interface/src/Util.h index b2c5ee3b2f..74336168c0 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -27,9 +27,6 @@ void drawText(int x, int y, float scale, float radians, int mono, void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0); -void renderOrientationDirections( glm::vec3 position, const glm::quat& orientation, float size ); - - void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance); void runTimingTests(); diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 89fea913e7..b95abc381f 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -319,7 +319,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { return; } const FBXGeometry& geometry = _geometry->getFBXGeometry(); - const float BASE_DIRECTION_SIZE = 300.0f; + const float BASE_DIRECTION_SIZE = 0.3f; float directionSize = BASE_DIRECTION_SIZE * extractUniformScale(_scale); glLineWidth(3.0f); do { @@ -362,7 +362,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { } glPopMatrix(); - renderOrientationDirections(position, _rotation * jointState.getRotation(), directionSize); + renderOrientationDirections(jointIndex, position, _rotation * jointState.getRotation(), directionSize); jointIndex = joint.parentIndex; } while (jointIndex != -1 && geometry.joints.at(jointIndex).isFree); @@ -370,6 +370,34 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { glLineWidth(1.0f); } +void SkeletonModel::renderOrientationDirections(int jointIndex, glm::vec3 position, const glm::quat& orientation, float size) { + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + + if (!_jointOrientationLines.contains(jointIndex)) { + OrientationLineIDs jointLineIDs; + jointLineIDs._up = geometryCache->allocateID(); + jointLineIDs._front = geometryCache->allocateID(); + jointLineIDs._right = geometryCache->allocateID(); + _jointOrientationLines[jointIndex] = jointLineIDs; + } + OrientationLineIDs& jointLineIDs = _jointOrientationLines[jointIndex]; + + glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; + glm::vec3 pUp = position + orientation * IDENTITY_UP * size; + glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; + + glColor3f(1.0f, 0.0f, 0.0f); + geometryCache->renderLine(position, pRight, jointLineIDs._right); + + glColor3f(0.0f, 1.0f, 0.0f); + geometryCache->renderLine(position, pUp, jointLineIDs._up); + + glColor3f(0.0f, 0.0f, 1.0f); + geometryCache->renderLine(position, pFront, jointLineIDs._front); +} + + + void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation) { // this algorithm is from sample code from sixense const FBXGeometry& geometry = _geometry->getFBXGeometry(); diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index 0956d27b3f..dc5e521cb7 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -144,6 +144,14 @@ protected: private: void renderJointConstraints(int jointIndex); + void renderOrientationDirections(int jointIndex, glm::vec3 position, const glm::quat& orientation, float size); + + struct OrientationLineIDs { + int _up; + int _front; + int _right; + }; + QHash _jointOrientationLines; /// \param jointIndex index of joint in model /// \param position position of joint in model-frame diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 83cb48899c..58b5fd6edd 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -12,6 +12,7 @@ #include "InterfaceConfig.h" #include +#include #include "Line3DOverlay.h" @@ -21,7 +22,8 @@ Line3DOverlay::Line3DOverlay() { Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) : Base3DOverlay(line3DOverlay), - _end(line3DOverlay->_end) + _end(line3DOverlay->_end), + _geometryCacheID(DependencyManager::get()->allocateID()) { } @@ -59,10 +61,7 @@ void Line3DOverlay::render(RenderArgs* args) { if (getIsDashedLine()) { drawDashedLine(_position, _end); } else { - glBegin(GL_LINES); - glVertex3f(_start.x, _start.y, _start.z); - glVertex3f(_end.x, _end.y, _end.z); - glEnd(); + DependencyManager::get()->renderLine(_start, _end, _geometryCacheID); } glEnable(GL_LIGHTING); diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index afe0ade585..9f4c9d8b4b 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -38,6 +38,7 @@ public: protected: glm::vec3 _start; glm::vec3 _end; + int _geometryCacheID; }; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index bb7244f07e..c13b8b78cf 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -765,7 +765,6 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id) { @@ -1153,6 +1152,176 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } + +void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) { + bool registeredLine = (id != UNKNOWN_ID); + Vec3Pair key(p1, p2); + VerticesIndices& vbo = registeredLine ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; + + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed + if (registeredLine && vbo.first != 0) { + Vec3Pair& lastKey = _lastRegisteredLine3D[id]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #if 1 // def WANT_DEBUG + qDebug() << "renderLine() 3D ... RELEASING REGISTERED line"; + #endif // def WANT_DEBUG + } + #if 1 // def WANT_DEBUG + else { + qDebug() << "renderLine() 3D ... REUSING PREVIOUSLY REGISTERED line"; + } + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 3; + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int vertices = 2; + const int indices = 2; + if (vbo.first == 0) { + _lastRegisteredLine3D[id] = key; + + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat* vertex = vertexData; + static GLubyte cannonicalIndices[indices] = {0, 1}; + + int vertexPoint = 0; + + // p1 + vertex[vertexPoint++] = p1.x; + vertex[vertexPoint++] = p1.y; + vertex[vertexPoint++] = p1.z; + + // p2 + vertex[vertexPoint++] = p2.x; + vertex[vertexPoint++] = p2.y; + vertex[vertexPoint++] = p2.z; + + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + #if 1 // def WANT_DEBUG + if (id == UNKNOWN_ID) { + qDebug() << "new renderLine() 3D VBO made -- _line3DVBOs.size():" << _line3DVBOs.size(); + } else { + qDebug() << "new registered renderLine() 3D VBO made -- _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); + } + #endif + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glDisableClientState(GL_VERTEX_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + +void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) { + bool registeredLine = (id != UNKNOWN_ID); + Vec2Pair key(p1, p2); + VerticesIndices& vbo = registeredLine ? _registeredLine2DVBOs[id] : _line2DVBOs[key]; + + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed + if (registeredLine && vbo.first != 0) { + Vec2Pair& lastKey = _lastRegisteredLine2D[id]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #if 1 // def WANT_DEBUG + qDebug() << "renderLine() 2D... RELEASING REGISTERED line"; + #endif // def WANT_DEBUG + } + #if 1 // def WANT_DEBUG + else { + qDebug() << "renderLine() 2D... REUSING PREVIOUSLY REGISTERED line"; + } + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 2; + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int vertices = 2; + const int indices = 2; + if (vbo.first == 0) { + _lastRegisteredLine2D[id] = key; + + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat* vertex = vertexData; + static GLubyte cannonicalIndices[indices] = {0, 1}; + + int vertexPoint = 0; + + // p1 + vertex[vertexPoint++] = p1.x; + vertex[vertexPoint++] = p1.y; + + // p2 + vertex[vertexPoint++] = p2.x; + vertex[vertexPoint++] = p2.y; + + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + #if 1 // def WANT_DEBUG + if (id == UNKNOWN_ID) { + qDebug() << "new renderLine() 2D VBO made -- _line2DVBOs.size():" << _line2DVBOs.size(); + } else { + qDebug() << "new registered renderLine() 2D VBO made -- _registeredLine2DVBOs.size():" << _registeredLine2DVBOs.size(); + } + #endif + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); + glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glDisableClientState(GL_VERTEX_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + + QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { return getResource(url, fallback, delayLoad).staticCast(); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 4a62c296db..60ce8a1beb 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -109,6 +109,10 @@ public: const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id = UNKNOWN_ID); + + void renderLine(const glm::vec3& p1, const glm::vec3& p2, int id = UNKNOWN_ID); + void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); + /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param delayLoad if true, don't load the geometry immediately; wait until load is first requested @@ -149,6 +153,14 @@ private: QHash _rectVBOs; QHash _registeredRectVBOs; + QHash _lastRegisteredLine3D; + QHash _line3DVBOs; + QHash _registeredLine3DVBOs; + + QHash _lastRegisteredLine2D; + QHash _line2DVBOs; + QHash _registeredLine2DVBOs; + QHash _gridBuffers; From 8b22b166ac2911d8df472c53aaf9dda8f81de9d1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 16:06:35 -0800 Subject: [PATCH 08/52] convert lookat vectors and laser pointers to use renderLine() --- interface/src/avatar/Avatar.cpp | 15 +++++++-------- interface/src/avatar/Head.cpp | 22 ++++++++++------------ interface/src/avatar/Head.h | 3 +++ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 3e57fc7dba..bdb37596a3 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -271,6 +271,8 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool } if (postLighting && glm::distance(Application::getInstance()->getAvatar()->getPosition(), _position) < 10.0f) { + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + // render pointing lasers glm::vec3 laserColor = glm::vec3(1.0f, 0.0f, 1.0f); float laserLength = 50.0f; @@ -297,11 +299,10 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool float angle = glm::degrees(glm::angle(rotation)); glm::vec3 axis = glm::axis(rotation); glRotatef(angle, axis.x, axis.y, axis.z); - glBegin(GL_LINES); + glColor3f(laserColor.x, laserColor.y, laserColor.z); - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(0.0f, laserLength, 0.0f); - glEnd(); + geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f)); + } glPopMatrix(); } } @@ -325,11 +326,9 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool float angle = glm::degrees(glm::angle(rotation)); glm::vec3 axis = glm::axis(rotation); glRotatef(angle, axis.x, axis.y, axis.z); - glBegin(GL_LINES); glColor3f(laserColor.x, laserColor.y, laserColor.z); - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(0.0f, laserLength, 0.0f); - glEnd(); + geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f)); + } glPopMatrix(); } } diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index a7315a348b..32594a7225 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -57,7 +57,9 @@ Head::Head(Avatar* owningAvatar) : _torsoTwist(0.0f), _isCameraMoving(false), _isLookingAtMe(false), - _faceModel(this) + _faceModel(this), + _leftEyeLookAtID(DependencyManager::get()->allocateID()), + _rightEyeLookAtID(DependencyManager::get()->allocateID()) { } @@ -338,21 +340,17 @@ void Head::addLeanDeltas(float sideways, float forward) { } void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition) { - + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); DependencyManager::get()->begin(); glLineWidth(2.0); - glBegin(GL_LINES); - glColor4f(0.2f, 0.2f, 0.2f, 1.0f); - glVertex3f(leftEyePosition.x, leftEyePosition.y, leftEyePosition.z); - glColor4f(1.0f, 1.0f, 1.0f, 0.0f); - glVertex3f(lookatPosition.x, lookatPosition.y, lookatPosition.z); - glColor4f(0.2f, 0.2f, 0.2f, 1.0f); - glVertex3f(rightEyePosition.x, rightEyePosition.y, rightEyePosition.z); - glColor4f(1.0f, 1.0f, 1.0f, 0.0f); - glVertex3f(lookatPosition.x, lookatPosition.y, lookatPosition.z); - glEnd(); + // TODO: implement support for lines with gradient colors + // glColor4f(0.2f, 0.2f, 0.2f, 1.0f); --> to --> glColor4f(1.0f, 1.0f, 1.0f, 0.0f); + glColor4f(0.5f, 0.5f, 0.5f, 0.5f); + geometryCache->renderLine(leftEyePosition, lookatPosition, _leftEyeLookAtID); + geometryCache->renderLine(rightEyePosition, lookatPosition, _rightEyeLookAtID); + DependencyManager::get()->end(); } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 43b380eac8..eee1d1bac6 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -160,6 +160,9 @@ private: glm::vec3 _correctedLookAtPosition; + int _leftEyeLookAtID; + int _rightEyeLookAtID; + // private methods void renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition); From 7cf4bd1860eb07b4090a8e43be2ce63b6fd8b79d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 16:29:02 -0800 Subject: [PATCH 09/52] remove head mouse --- interface/src/Menu.cpp | 1 - interface/src/Menu.h | 1 - interface/src/avatar/MyAvatar.cpp | 43 ------------------------- interface/src/avatar/MyAvatar.h | 1 - interface/src/ui/ApplicationOverlay.cpp | 4 --- 5 files changed, 50 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 3e9bdde1ff..9d40183a89 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -372,7 +372,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::OffAxisProjection, 0, false); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::TurnWithHead, 0, false); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::HeadMouse, 0, false); addDisabledActionAndSeparator(viewMenu, "Stats"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index a3e32b3682..649553dfaf 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -401,7 +401,6 @@ namespace MenuOption { const QString GlowWhenSpeaking = "Glow When Speaking"; const QString NamesAboveHeads = "Names Above Heads"; const QString GoToUser = "Go To User"; - const QString HeadMouse = "Head Mouse"; const QString HMDTools = "HMD Tools"; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IncreaseVoxelSize = "Increase Voxel Size"; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 81d00bae74..86652c9c3d 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -410,49 +410,6 @@ void MyAvatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bo } } -void MyAvatar::renderHeadMouse(int screenWidth, int screenHeight) const { - Faceshift::SharedPointer faceshift = DependencyManager::get(); - - float pixelsPerDegree = screenHeight / Menu::getInstance()->getFieldOfView(); - - // Display small target box at center or head mouse target that can also be used to measure LOD - float headPitch = getHead()->getFinalPitch(); - float headYaw = getHead()->getFinalYaw(); - - float aspectRatio = (float) screenWidth / (float) screenHeight; - int headMouseX = (int)((float)screenWidth / 2.0f - headYaw * aspectRatio * pixelsPerDegree); - int headMouseY = (int)((float)screenHeight / 2.0f - headPitch * pixelsPerDegree); - - glColor3f(1.0f, 1.0f, 1.0f); - glDisable(GL_LINE_SMOOTH); - const int PIXEL_BOX = 16; - glBegin(GL_LINES); - glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY); - glVertex2f(headMouseX + PIXEL_BOX/2, headMouseY); - glVertex2f(headMouseX, headMouseY - PIXEL_BOX/2); - glVertex2f(headMouseX, headMouseY + PIXEL_BOX/2); - glEnd(); - glEnable(GL_LINE_SMOOTH); - // If Faceshift is active, show eye pitch and yaw as separate pointer - if (faceshift->isActive()) { - - float avgEyePitch = faceshift->getEstimatedEyePitch(); - float avgEyeYaw = faceshift->getEstimatedEyeYaw(); - int eyeTargetX = (int)((float)(screenWidth) / 2.0f - avgEyeYaw * aspectRatio * pixelsPerDegree); - int eyeTargetY = (int)((float)(screenHeight) / 2.0f - avgEyePitch * pixelsPerDegree); - - glColor3f(0.0f, 1.0f, 1.0f); - glDisable(GL_LINE_SMOOTH); - glBegin(GL_LINES); - glVertex2f(eyeTargetX - PIXEL_BOX/2, eyeTargetY); - glVertex2f(eyeTargetX + PIXEL_BOX/2, eyeTargetY); - glVertex2f(eyeTargetX, eyeTargetY - PIXEL_BOX/2); - glVertex2f(eyeTargetX, eyeTargetY + PIXEL_BOX/2); - glEnd(); - - } -} - const glm::vec3 HAND_TO_PALM_OFFSET(0.0f, 0.12f, 0.08f); glm::vec3 MyAvatar::getLeftPalmPosition() { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 7bf6d057da..9342aacc00 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -43,7 +43,6 @@ public: void renderBody(RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; void renderDebugBodyPoints(); - void renderHeadMouse(int screenWidth, int screenHeight) const; // setters void setLeanScale(float scale) { _leanScale = scale; } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index d9194e54be..46adc630ab 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -188,10 +188,6 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { renderAudioMeter(); - if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - myAvatar->renderHeadMouse(glCanvas->width(), glCanvas->height()); - } - renderStatsAndLogs(); // give external parties a change to hook in From 0e943ae2408086f44aa97c6a0071a9dcf1a818a3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 17:23:10 -0800 Subject: [PATCH 10/52] remove render view frustum mode --- interface/src/Application.cpp | 276 +++------------------------------- interface/src/Application.h | 2 - interface/src/Menu.cpp | 121 --------------- interface/src/Menu.h | 29 ---- 4 files changed, 22 insertions(+), 406 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c2ce4c9077..82daf2bae7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -531,12 +531,6 @@ void Application::initializeGL() { }*/ #endif - // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large - // field of view and near and far clip to make it interesting. - //viewFrustumOffsetCamera.setFieldOfView(90.0); - _viewFrustumOffsetCamera.setNearClip(DEFAULT_NEAR_CLIP); - _viewFrustumOffsetCamera.setFarClip(DEFAULT_FAR_CLIP); - initDisplay(); qDebug( "Initialized Display."); @@ -623,32 +617,6 @@ void Application::paintGL() { _myCamera.update(1.0f / _fps); } - // Note: whichCamera is used to pick between the normal camera myCamera for our - // main camera, vs, an alternate camera. The alternate camera we support right now - // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism - // to add other cameras. - // - // Why have two cameras? Well, one reason is that because in the case of the renderViewFrustum() - // code, we want to keep the state of "myCamera" intact, so we can render what the view frustum of - // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera - Camera* whichCamera = &_myCamera; - - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum)) { - - ViewFrustumOffset viewFrustumOffset = Menu::getInstance()->getViewFrustumOffset(); - - // set the camera to third-person view but offset so we can see the frustum - glm::quat frustumRotation = glm::quat(glm::radians(glm::vec3(viewFrustumOffset.pitch, viewFrustumOffset.yaw, viewFrustumOffset.roll))); - - _viewFrustumOffsetCamera.setPosition(_myCamera.getPosition() + - frustumRotation * glm::vec3(0.0f, viewFrustumOffset.up, -viewFrustumOffset.distance)); - - _viewFrustumOffsetCamera.setRotation(_myCamera.getRotation() * frustumRotation); - - _viewFrustumOffsetCamera.update(1.0f/_fps); - whichCamera = &_viewFrustumOffsetCamera; - } - if (Menu::getInstance()->getShadowsEnabled()) { updateShadowMap(); } @@ -659,16 +627,16 @@ void Application::paintGL() { glClear(GL_COLOR_BUFFER_BIT); //When in mirror mode, use camera rotation. Otherwise, use body rotation - if (whichCamera->getMode() == CAMERA_MODE_MIRROR) { - OculusManager::display(whichCamera->getRotation(), whichCamera->getPosition(), *whichCamera); + if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { + OculusManager::display(_myCamera.getRotation(), _myCamera.getPosition(), _myCamera); } else { - OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), *whichCamera); + OculusManager::display(_myAvatar->getWorldAlignedOrientation(), _myAvatar->getDefaultEyePosition(), _myCamera); } _myCamera.update(1.0f / _fps); } else if (TV3DManager::isConnected()) { - TV3DManager::display(*whichCamera); + TV3DManager::display(_myCamera); } else { DependencyManager::get()->prepare(); @@ -680,7 +648,7 @@ void Application::paintGL() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - displaySide(*whichCamera); + displaySide(_myCamera); glPopMatrix(); if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { @@ -717,7 +685,6 @@ void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) } void Application::resizeGL(int width, int height) { - resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); resetCamerasOnResizeGL(_myCamera, width, height); glViewport(0, 0, width, height); // shouldn't this account for the menu??? @@ -746,13 +713,6 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) if (updateViewFrustum) { loadViewFrustum(camera, _viewFrustum); _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); - - // If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the - // _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum)) { - nearVal = _viewFrustumOffsetCamera.getNearClip(); - farVal = _viewFrustumOffsetCamera.getFarClip(); - } } else { ViewFrustum tempViewFrustum; loadViewFrustum(camera, tempViewFrustum); @@ -840,19 +800,6 @@ void Application::keyPressEvent(QKeyEvent* event) { bool isOption = event->modifiers().testFlag(Qt::AltModifier); switch (event->key()) { break; - case Qt::Key_BracketLeft: - case Qt::Key_BracketRight: - case Qt::Key_BraceLeft: - case Qt::Key_BraceRight: - case Qt::Key_ParenLeft: - case Qt::Key_ParenRight: - case Qt::Key_Less: - case Qt::Key_Greater: - case Qt::Key_Comma: - case Qt::Key_Period: - case Qt::Key_QuoteDbl: - Menu::getInstance()->handleViewFrustumOffsetKeyModifier(event->key()); - break; case Qt::Key_L: if (isShifted) { Menu::getInstance()->triggerOption(MenuOption::LodTools); @@ -1054,19 +1001,9 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_Slash: Menu::getInstance()->triggerOption(MenuOption::UserInterface); break; - case Qt::Key_F: - if (isShifted) { - Menu::getInstance()->triggerOption(MenuOption::DisplayFrustum); - } - break; case Qt::Key_P: Menu::getInstance()->triggerOption(MenuOption::FirstPerson); break; - case Qt::Key_R: - if (isShifted) { - Menu::getInstance()->triggerOption(MenuOption::FrustumRenderMode); - } - break; case Qt::Key_Percent: Menu::getInstance()->triggerOption(MenuOption::Stats); break; @@ -2713,17 +2650,17 @@ QImage Application::renderAvatarBillboard() { return image; } -void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { +void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("display"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()"); // transform by eye offset // load the view frustum - loadViewFrustum(whichCamera, _displayViewFrustum); + loadViewFrustum(theCamera, _displayViewFrustum); // flip x if in mirror mode (also requires reversing winding order for backface culling) - if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { + if (theCamera.getMode() == CAMERA_MODE_MIRROR) { glScalef(-1.0f, 1.0f, 1.0f); glFrontFace(GL_CW); @@ -2731,32 +2668,32 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr glFrontFace(GL_CCW); } - glm::vec3 eyeOffsetPos = whichCamera.getEyeOffsetPosition(); - glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); + glm::vec3 eyeOffsetPos = theCamera.getEyeOffsetPosition(); + glm::quat eyeOffsetOrient = theCamera.getEyeOffsetOrientation(); glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z); glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); - // transform view according to whichCamera + // transform view according to theCamera // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode - glm::quat rotation = whichCamera.getRotation(); + glm::quat rotation = theCamera.getRotation(); glm::vec3 axis = glm::axis(rotation); glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); // store view matrix without translation, which we'll use for precision-sensitive objects - updateUntranslatedViewMatrix(-whichCamera.getPosition()); + updateUntranslatedViewMatrix(-theCamera.getPosition()); // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation // the viewTransofmr object is updatded with the correct values and saved, // this is what is used for rendering the Entities and avatars Transform viewTransform; - viewTransform.setTranslation(whichCamera.getPosition()); + viewTransform.setTranslation(theCamera.getPosition()); viewTransform.setRotation(rotation); viewTransform.postTranslate(eyeOffsetPos); viewTransform.postRotate(eyeOffsetOrient); - if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { + if (theCamera.getMode() == CAMERA_MODE_MIRROR) { viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f)); } if (renderSide != RenderArgs::MONO) { @@ -2802,9 +2739,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr // compute starfield alpha based on distance from atmosphere float alpha = 1.0f; if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { - const EnvironmentData& closestData = _environment.getClosestData(whichCamera.getPosition()); - float height = glm::distance(whichCamera.getPosition(), - closestData.getAtmosphereCenter(whichCamera.getPosition())); + const EnvironmentData& closestData = _environment.getClosestData(theCamera.getPosition()); + float height = glm::distance(theCamera.getPosition(), + closestData.getAtmosphereCenter(theCamera.getPosition())); if (height < closestData.getAtmosphereInnerRadius()) { alpha = 0.0f; @@ -2815,7 +2752,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr } // finally render the starfield - _stars.render(whichCamera.getFieldOfView(), whichCamera.getAspectRatio(), whichCamera.getNearClip(), alpha); + _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha); } if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) { @@ -2827,7 +2764,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr PerformanceTimer perfTimer("atmosphere"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide() ... atmosphere..."); - _environment.renderAtmospheres(whichCamera); + _environment.renderAtmospheres(theCamera); } glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); @@ -2873,7 +2810,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr - bool mirrorMode = (whichCamera.getMode() == CAMERA_MODE_MIRROR); + bool mirrorMode = (theCamera.getMode() == CAMERA_MODE_MIRROR); { PerformanceTimer perfTimer("avatars"); _avatarManager.renderAvatars(mirrorMode ? Avatar::MIRROR_RENDER_MODE : Avatar::NORMAL_RENDER_MODE, @@ -2902,20 +2839,12 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr _nodeBoundsDisplay.draw(); // Render the world box - if (whichCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && + if (theCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface)) { PerformanceTimer perfTimer("worldBox"); renderWorldBox(); } - // view frustum for debugging - if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayFrustum) && whichCamera.getMode() != CAMERA_MODE_MIRROR) { - PerformanceTimer perfTimer("viewFrustum"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::displaySide() ... renderViewFrustum..."); - renderViewFrustum(_viewFrustum); - } - // render octree fades if they exist if (_octreeFades.size() > 0) { PerformanceTimer perfTimer("octreeFades"); @@ -3142,167 +3071,6 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { updateProjectionMatrix(_myCamera, updateViewFrustum); } -// renderViewFrustum() -// -// Description: this will render the view frustum bounds for EITHER the head -// or the "myCamera". -// -// Frustum rendering mode. For debug purposes, we allow drawing the frustum in a couple of different ways. -// We can draw it with each of these parts: -// * Origin Direction/Up/Right vectors - these will be drawn at the point of the camera -// * Near plane - this plane is drawn very close to the origin point. -// * Right/Left planes - these two planes are drawn between the near and far planes. -// * Far plane - the plane is drawn in the distance. -// Modes - the following modes, will draw the following parts. -// * All - draws all the parts listed above -// * Planes - draws the planes but not the origin vectors -// * Origin Vectors - draws the origin vectors ONLY -// * Near Plane - draws only the near plane -// * Far Plane - draws only the far plane -void Application::renderViewFrustum(ViewFrustum& viewFrustum) { - // Load it with the latest details! - loadViewFrustum(_myCamera, viewFrustum); - - glm::vec3 position = viewFrustum.getOffsetPosition(); - glm::vec3 direction = viewFrustum.getOffsetDirection(); - glm::vec3 up = viewFrustum.getOffsetUp(); - glm::vec3 right = viewFrustum.getOffsetRight(); - - // Get ready to draw some lines - glDisable(GL_LIGHTING); - glColor4f(1.0, 1.0, 1.0, 1.0); - glLineWidth(1.0); - glBegin(GL_LINES); - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_VECTORS) { - // Calculate the origin direction vectors - glm::vec3 lookingAt = position + (direction * 0.2f); - glm::vec3 lookingAtUp = position + (up * 0.2f); - glm::vec3 lookingAtRight = position + (right * 0.2f); - - // Looking At = white - glColor3f(1,1,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAt.x, lookingAt.y, lookingAt.z); - - // Looking At Up = purple - glColor3f(1,0,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z); - - // Looking At Right = cyan - glColor3f(0,1,1); - glVertex3f(position.x, position.y, position.z); - glVertex3f(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_NEAR_PLANE) { - // Drawing the bounds of the frustum - // viewFrustum.getNear plane - bottom edge - glColor3f(1,0,0); - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - - // viewFrustum.getNear plane - top edge - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - right edge - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - - // viewFrustum.getNear plane - left edge - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_FAR_PLANE) { - // viewFrustum.getFar plane - bottom edge - glColor3f(0,1,0); - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // viewFrustum.getFar plane - top edge - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - right edge - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // viewFrustum.getFar plane - left edge - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - } - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_PLANES) { - // RIGHT PLANE IS CYAN - // right plane - bottom edge - viewFrustum.getNear to distant - glColor3f(0,1,1); - glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); - glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); - - // right plane - top edge - viewFrustum.getNear to distant - glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); - glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); - - // LEFT PLANE IS BLUE - // left plane - bottom edge - viewFrustum.getNear to distant - glColor3f(0,0,1); - glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); - glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); - - // left plane - top edge - viewFrustum.getNear to distant - glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); - glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); - - // focal plane - bottom edge - glColor3f(1.0f, 0.0f, 1.0f); - float focalProportion = (viewFrustum.getFocalLength() - viewFrustum.getNearClip()) / - (viewFrustum.getFarClip() - viewFrustum.getNearClip()); - glm::vec3 focalBottomLeft = glm::mix(viewFrustum.getNearBottomLeft(), viewFrustum.getFarBottomLeft(), focalProportion); - glm::vec3 focalBottomRight = glm::mix(viewFrustum.getNearBottomRight(), - viewFrustum.getFarBottomRight(), focalProportion); - glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z); - glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z); - - // focal plane - top edge - glm::vec3 focalTopLeft = glm::mix(viewFrustum.getNearTopLeft(), viewFrustum.getFarTopLeft(), focalProportion); - glm::vec3 focalTopRight = glm::mix(viewFrustum.getNearTopRight(), viewFrustum.getFarTopRight(), focalProportion); - glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z); - glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z); - - // focal plane - left edge - glVertex3f(focalBottomLeft.x, focalBottomLeft.y, focalBottomLeft.z); - glVertex3f(focalTopLeft.x, focalTopLeft.y, focalTopLeft.z); - - // focal plane - right edge - glVertex3f(focalBottomRight.x, focalBottomRight.y, focalBottomRight.z); - glVertex3f(focalTopRight.x, focalTopRight.y, focalTopRight.z); - } - glEnd(); - glEnable(GL_LIGHTING); - - if (Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_ALL - || Menu::getInstance()->getFrustumDrawMode() == FRUSTUM_DRAW_MODE_KEYHOLE) { - // Draw the keyhole - float keyholeRadius = viewFrustum.getKeyholeRadius(); - if (keyholeRadius > 0.0f) { - glPushMatrix(); - glColor4f(1, 1, 0, 1); - glTranslatef(position.x, position.y, position.z); // where we actually want it! - DependencyManager::get()->renderSphere(keyholeRadius, 20, 20, false); - glPopMatrix(); - } - } -} - void Application::resetSensors() { DependencyManager::get()->reset(); DependencyManager::get()->reset(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 58fb3fc342..5d3a906079 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -418,7 +418,6 @@ private: void updateShadowMap(); void renderRearViewMirror(const QRect& region, bool billboard = false); - void renderViewFrustum(ViewFrustum& viewFrustum); void checkBandwidthMeterClick(); void setMenuShortcutsEnabled(bool enabled); @@ -482,7 +481,6 @@ private: PrioVR _prioVR; Camera _myCamera; // My view onto the world - Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode Camera _mirrorCamera; // Cammera for mirror view QRect _mirrorViewRect; RearMirrorTools* _rearMirrorTools; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 3a6bd40477..3bdd4ae1dd 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -76,7 +76,6 @@ Menu* Menu::getInstance() { return _instance; } -const ViewFrustumOffset DEFAULT_FRUSTUM_OFFSET = {-135.0f, 0.0f, 0.0f, 25.0f, 0.0f}; const float DEFAULT_FACESHIFT_EYE_DEFLECTION = 0.25f; const QString DEFAULT_FACESHIFT_HOSTNAME = "localhost"; const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f; @@ -97,8 +96,6 @@ Menu::Menu() : _realWorldFieldOfView(DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), _faceshiftEyeDeflection(DEFAULT_FACESHIFT_EYE_DEFLECTION), _faceshiftHostname(DEFAULT_FACESHIFT_HOSTNAME), - _frustumDrawMode(FRUSTUM_DRAW_MODE_ALL), - _viewFrustumOffset(DEFAULT_FRUSTUM_OFFSET), _jsConsole(NULL), _octreeStatsDialog(NULL), _lodToolsDialog(NULL), @@ -516,16 +513,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::PipelineWarnings); addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::SuppressShortTimings); - QMenu* frustumMenu = developerMenu->addMenu("View Frustum"); - addCheckableActionToQMenuAndActionHash(frustumMenu, MenuOption::DisplayFrustum, Qt::SHIFT | Qt::Key_F); - addActionToQMenuAndActionHash(frustumMenu, - MenuOption::FrustumRenderMode, - Qt::SHIFT | Qt::Key_R, - this, - SLOT(cycleFrustumRenderMode())); - updateFrustumRenderModeAction(); - - QMenu* audioDebugMenu = developerMenu->addMenu("Audio"); addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioNoiseReduction, 0, @@ -674,15 +661,6 @@ void Menu::loadSettings(QSettings* settings) { _speechRecognizer.setEnabled(settings->value("speechRecognitionEnabled", false).toBool()); #endif - settings->beginGroup("View Frustum Offset Camera"); - // in case settings is corrupt or missing loadSetting() will check for NaN - _viewFrustumOffset.yaw = loadSetting(settings, "viewFrustumOffsetYaw", 0.0f); - _viewFrustumOffset.pitch = loadSetting(settings, "viewFrustumOffsetPitch", 0.0f); - _viewFrustumOffset.roll = loadSetting(settings, "viewFrustumOffsetRoll", 0.0f); - _viewFrustumOffset.distance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f); - _viewFrustumOffset.up = loadSetting(settings, "viewFrustumOffsetUp", 0.0f); - settings->endGroup(); - _walletPrivateKey = settings->value("privateKey").toByteArray(); scanMenuBar(&loadAction, settings); @@ -736,13 +714,6 @@ void Menu::saveSettings(QSettings* settings) { #if defined(Q_OS_MAC) || defined(Q_OS_WIN) settings->setValue("speechRecognitionEnabled", _speechRecognizer.getEnabled()); #endif - settings->beginGroup("View Frustum Offset Camera"); - settings->setValue("viewFrustumOffsetYaw", _viewFrustumOffset.yaw); - settings->setValue("viewFrustumOffsetPitch", _viewFrustumOffset.pitch); - settings->setValue("viewFrustumOffsetRoll", _viewFrustumOffset.roll); - settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffset.distance); - settings->setValue("viewFrustumOffsetUp", _viewFrustumOffset.up); - settings->endGroup(); settings->setValue("privateKey", _walletPrivateKey); scanMenuBar(&saveAction, settings); @@ -817,66 +788,6 @@ bool Menu::getShadowsEnabled() const { return isOptionChecked(MenuOption::SimpleShadows) || isOptionChecked(MenuOption::CascadedShadows); } -void Menu::handleViewFrustumOffsetKeyModifier(int key) { - const float VIEW_FRUSTUM_OFFSET_DELTA = 0.5f; - const float VIEW_FRUSTUM_OFFSET_UP_DELTA = 0.05f; - - switch (key) { - case Qt::Key_QuoteDbl: - _viewFrustumOffset.yaw = 0.0f; - _viewFrustumOffset.pitch = 0.0f; - _viewFrustumOffset.roll = 0.0f; - _viewFrustumOffset.up = 0.0f; - _viewFrustumOffset.distance = 0.0f; - break; - - case Qt::Key_BracketLeft: - _viewFrustumOffset.yaw -= VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_BracketRight: - _viewFrustumOffset.yaw += VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_BraceLeft: - _viewFrustumOffset.pitch -= VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_BraceRight: - _viewFrustumOffset.pitch += VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_ParenLeft: - _viewFrustumOffset.roll -= VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_ParenRight: - _viewFrustumOffset.roll += VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_Less: - _viewFrustumOffset.distance -= VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_Greater: - _viewFrustumOffset.distance += VIEW_FRUSTUM_OFFSET_DELTA; - break; - - case Qt::Key_Comma: - _viewFrustumOffset.up -= VIEW_FRUSTUM_OFFSET_UP_DELTA; - break; - - case Qt::Key_Period: - _viewFrustumOffset.up += VIEW_FRUSTUM_OFFSET_UP_DELTA; - break; - - default: - break; - } - - bumpSettings(); -} - void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, int menuItemLocation) { QAction* actionBefore = NULL; if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) { @@ -1589,42 +1500,10 @@ void Menu::hmdToolsClosed() { _hmdToolsDialog->hide(); } -void Menu::cycleFrustumRenderMode() { - _frustumDrawMode = (FrustumDrawMode)((_frustumDrawMode + 1) % FRUSTUM_DRAW_MODE_COUNT); - updateFrustumRenderModeAction(); -} - void Menu::runTests() { runTimingTests(); } -void Menu::updateFrustumRenderModeAction() { - QAction* frustumRenderModeAction = _actionHash.value(MenuOption::FrustumRenderMode); - if (frustumRenderModeAction) { - switch (_frustumDrawMode) { - default: - case FRUSTUM_DRAW_MODE_ALL: - frustumRenderModeAction->setText("Render Mode - All"); - break; - case FRUSTUM_DRAW_MODE_VECTORS: - frustumRenderModeAction->setText("Render Mode - Vectors"); - break; - case FRUSTUM_DRAW_MODE_PLANES: - frustumRenderModeAction->setText("Render Mode - Planes"); - break; - case FRUSTUM_DRAW_MODE_NEAR_PLANE: - frustumRenderModeAction->setText("Render Mode - Near"); - break; - case FRUSTUM_DRAW_MODE_FAR_PLANE: - frustumRenderModeAction->setText("Render Mode - Far"); - break; - case FRUSTUM_DRAW_MODE_KEYHOLE: - frustumRenderModeAction->setText("Render Mode - Keyhole"); - break; - } - } -} - QAction* Menu::getActionFromName(const QString& menuName, QMenu* menu) { QList menuActions; if (menu) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 8c2425c104..9e41e98621 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -53,24 +53,6 @@ const float MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER = 15.0f; const QString SETTINGS_ADDRESS_KEY = "address"; -enum FrustumDrawMode { - FRUSTUM_DRAW_MODE_ALL, - FRUSTUM_DRAW_MODE_VECTORS, - FRUSTUM_DRAW_MODE_PLANES, - FRUSTUM_DRAW_MODE_NEAR_PLANE, - FRUSTUM_DRAW_MODE_FAR_PLANE, - FRUSTUM_DRAW_MODE_KEYHOLE, - FRUSTUM_DRAW_MODE_COUNT -}; - -struct ViewFrustumOffset { - float yaw; - float pitch; - float roll; - float distance; - float up; -}; - class QSettings; class AnimationsDialog; @@ -117,16 +99,12 @@ public: void setScriptsLocation(const QString& scriptsLocation); BandwidthDialog* getBandwidthDialog() const { return _bandwidthDialog; } - FrustumDrawMode getFrustumDrawMode() const { return _frustumDrawMode; } - ViewFrustumOffset getViewFrustumOffset() const { return _viewFrustumOffset; } OctreeStatsDialog* getOctreeStatsDialog() const { return _octreeStatsDialog; } LodToolsDialog* getLodToolsDialog() const { return _lodToolsDialog; } HMDToolsDialog* getHMDToolsDialog() const { return _hmdToolsDialog; } bool getShadowsEnabled() const; - void handleViewFrustumOffsetKeyModifier(int key); - // User Tweakable LOD Items QString getLODFeedbackText(); void autoAdjustLOD(float currentFPS); @@ -218,7 +196,6 @@ private slots: void octreeStatsDetailsClosed(); void lodToolsClosed(); void hmdToolsClosed(); - void cycleFrustumRenderMode(); void runTests(); void showMetavoxelEditor(); void showMetavoxelNetworkSimulator(); @@ -257,8 +234,6 @@ private: const char* member = NULL, int menuItemLocation = UNSPECIFIED_POSITION); - void updateFrustumRenderModeAction(); - QAction* getActionFromName(const QString& menuName, QMenu* menu); QMenu* getSubMenuFromName(const QString& menuName, QMenu* menu); QMenu* getMenuParent(const QString& menuName, QString& finalMenuPart); @@ -276,8 +251,6 @@ private: float _realWorldFieldOfView; // The actual FOV set by the user's monitor size and view distance float _faceshiftEyeDeflection; QString _faceshiftHostname; - FrustumDrawMode _frustumDrawMode; - ViewFrustumOffset _viewFrustumOffset; QPointer _MetavoxelEditor; QPointer _metavoxelNetworkSimulator; QPointer _ScriptEditor; @@ -364,7 +337,6 @@ namespace MenuOption { const QString DisableAutoAdjustLOD = "Disable Automatically Adjusting LOD"; const QString DisableLightEntities = "Disable Light Entities"; const QString DisableNackPackets = "Disable NACK Packets"; - const QString DisplayFrustum = "Display Frustum"; const QString DisplayHands = "Show Hand Info"; const QString DisplayHandTargets = "Show Hand Targets"; const QString DisplayHermiteData = "Display Hermite Data"; @@ -390,7 +362,6 @@ namespace MenuOption { const QString FilterSixense = "Smooth Sixense Movement"; const QString FirstPerson = "First Person"; const QString FrameTimer = "Show Timer"; - const QString FrustumRenderMode = "Render Mode"; const QString Fullscreen = "Fullscreen"; const QString FullscreenMirror = "Fullscreen Mirror"; const QString GlowWhenSpeaking = "Glow When Speaking"; From 9545bd1907a3a9126dbd115020203c994c684449 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 19:34:37 -0800 Subject: [PATCH 11/52] add alternate renderGrid for audio scope --- interface/src/Audio.cpp | 25 +----- interface/src/Audio.h | 2 + interface/src/ui/ApplicationOverlay.cpp | 1 - libraries/render-utils/src/GeometryCache.cpp | 90 +++++++++++++++++++- libraries/render-utils/src/GeometryCache.h | 4 + 5 files changed, 96 insertions(+), 26 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index be382523ff..1c6145b18e 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -124,7 +124,8 @@ Audio::Audio(QObject* parent) : _audioOutputMsecsUnplayedStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS), _lastSentAudioPacket(0), _packetSentTimeGaps(1, APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS), - _audioOutputIODevice(_receivedAudioStream, this) + _audioOutputIODevice(_receivedAudioStream, this), + _audioScopeGrid(DependencyManager::get()->allocateID()) { // clear the array of locally injected samples memset(_localProceduralSamples, 0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL); @@ -1692,28 +1693,8 @@ void Audio::renderBackground(const float* color, int x, int y, int width, int he } void Audio::renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols) { - glColor4fv(color); - glBegin(GL_LINES); - - int dx = width / cols; - int dy = height / rows; - int tx = x; - int ty = y; - - // Draw horizontal grid lines - for (int i = rows + 1; --i >= 0; ) { - glVertex2i(x, ty); - glVertex2i(x + width, ty); - ty += dy; - } - // Draw vertical grid lines - for (int i = cols + 1; --i >= 0; ) { - glVertex2i(tx, y); - glVertex2i(tx, y + height); - tx += dx; - } - glEnd(); + DependencyManager::get()->renderGrid(x, y, width, height, rows, cols, _audioScopeGrid); glColor4f(1, 1, 1, 1); } diff --git a/interface/src/Audio.h b/interface/src/Audio.h index da21db27dc..6b11530e7c 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -364,6 +364,8 @@ private: AudioOutputIODevice _audioOutputIODevice; WeakRecorderPointer _recorder; + + int _audioScopeGrid; }; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 3a296b349d..9b1c52f816 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -151,7 +151,6 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { Application* application = Application::getInstance(); Overlays& overlays = application->getOverlays(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - MyAvatar* myAvatar = application->getAvatar(); _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize()); _textureAspectRatio = (float)glCanvas->getDeviceWidth() / (float)glCanvas->getDeviceHeight(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 484920adc1..94d853086b 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -513,6 +513,90 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { buffer.release(); } +void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, int id) { + bool registered = (id != UNKNOWN_ID); + Vec3Pair key(glm::vec3(x, y, width), glm::vec3(height, rows, cols)); + QOpenGLBuffer& buffer = registered ? _registeredAlternateGridBuffers[id] : _alternateGridBuffers[key]; + + // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed + if (registered && buffer.isCreated()) { + Vec3Pair& lastKey = _lastRegisteredGrid[id]; + if (lastKey != key) { + buffer.destroy(); + #if 1// def WANT_DEBUG + qDebug() << "renderGrid()... RELEASING REGISTERED"; + #endif // def WANT_DEBUG + } + #if 1// def WANT_DEBUG + else { + qDebug() << "renderGrid()... REUSING PREVIOUSLY REGISTERED"; + } + #endif // def WANT_DEBUG + } + + int vertices = (cols + 1 + rows + 1) * 2; + if (!buffer.isCreated()) { + + _lastRegisteredGrid[id] = key; + + GLfloat* vertexData = new GLfloat[vertices * 2]; + GLfloat* vertex = vertexData; + + int dx = width / cols; + int dy = height / rows; + int tx = x; + int ty = y; + + // Draw horizontal grid lines + for (int i = rows + 1; --i >= 0; ) { + *(vertex++) = x; + *(vertex++) = ty; + + *(vertex++) = x + width; + *(vertex++) = ty; + + ty += dy; + } + // Draw vertical grid lines + for (int i = cols + 1; --i >= 0; ) { + //glVertex2i(tx, y); + //glVertex2i(tx, y + height); + *(vertex++) = tx; + *(vertex++) = y; + + *(vertex++) = tx; + *(vertex++) = y + height; + tx += dx; + } + + buffer.create(); + buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); + buffer.bind(); + buffer.allocate(vertexData, vertices * 2 * sizeof(GLfloat)); + delete[] vertexData; + + #if 1 //def WANT_DEBUG + if (id == UNKNOWN_ID) { + qDebug() << "new grid buffer made -- _alternateGridBuffers.size():" << _alternateGridBuffers.size(); + } else { + qDebug() << "new registered grid buffer made -- _registeredAlternateGridBuffers.size():" << _registeredAlternateGridBuffers.size(); + } + #endif + + } else { + buffer.bind(); + } + glEnableClientState(GL_VERTEX_ARRAY); + + glVertexPointer(2, GL_FLOAT, 0, 0); + + glDrawArrays(GL_LINES, 0, vertices); + + glDisableClientState(GL_VERTEX_ARRAY); + + buffer.release(); +} + void GeometryCache::renderSolidCube(float size) { VerticesIndices& vbo = _solidCubeVBOs[size]; const int FLOATS_PER_VERTEX = 3; @@ -1165,11 +1249,11 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); vbo.first = vbo.second = 0; - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderLine() 3D ... RELEASING REGISTERED line"; #endif // def WANT_DEBUG } - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG else { qDebug() << "renderLine() 3D ... REUSING PREVIOUSLY REGISTERED line"; } @@ -1217,7 +1301,7 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG if (id == UNKNOWN_ID) { qDebug() << "new renderLine() 3D VBO made -- _line3DVBOs.size():" << _line3DVBOs.size(); } else { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 60ce8a1beb..a96c51dcf9 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -90,6 +90,7 @@ public: void renderHalfCylinder(int slices, int stacks); void renderCone(float base, float height, int slices, int stacks); void renderGrid(int xDivisions, int yDivisions); + void renderGrid(int x, int y, int width, int height, int rows, int cols, int id = UNKNOWN_ID); void renderSolidCube(float size); void renderWireCube(float size); void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, int id = UNKNOWN_ID); @@ -164,6 +165,9 @@ private: QHash _gridBuffers; + QHash _registeredAlternateGridBuffers; + QHash _alternateGridBuffers; + QHash _lastRegisteredGrid; QHash > _networkGeometry; }; From a9b7367fa96f88784004672f4d610f76970a3657 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 20:51:05 -0800 Subject: [PATCH 12/52] more work on eliminating immediate mode calls --- interface/src/ui/ApplicationOverlay.cpp | 98 ++++++++++--------- interface/src/ui/ApplicationOverlay.h | 11 +++ interface/src/ui/BandwidthMeter.cpp | 6 +- .../src/ui/overlays/Rectangle3DOverlay.cpp | 22 ++++- .../src/ui/overlays/Rectangle3DOverlay.h | 3 + libraries/render-utils/src/GeometryCache.cpp | 81 +++++++++++++++ libraries/render-utils/src/GeometryCache.h | 12 +++ 7 files changed, 182 insertions(+), 51 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 9b1c52f816..fda932ef7d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -115,9 +115,6 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f); glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f); glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha); - if (_reticleQuad == GeometryCache::UNKNOWN_ID) { - _reticleQuad = DependencyManager::get()->allocateID(); - } DependencyManager::get()->renderQuad(topLeft, bottomLeft, bottomRight, topRight, glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), _reticleQuad); @@ -131,15 +128,27 @@ ApplicationOverlay::ApplicationOverlay() : _alpha(1.0f), _oculusUIRadius(1.0f), _crosshairTexture(0), - _reticleQuad(GeometryCache::UNKNOWN_ID), - _magnifierQuad(GeometryCache::UNKNOWN_ID), - _audioRedQuad(GeometryCache::UNKNOWN_ID), - _audioGreenQuad(GeometryCache::UNKNOWN_ID), - _audioBlueQuad(GeometryCache::UNKNOWN_ID) + _previousBorderWidth(-1), + _previousBorderHeight(-1), + _previousMagnifierBottomLeft(), + _previousMagnifierBottomRight(), + _previousMagnifierTopLeft(), + _previousMagnifierTopRight() { memset(_reticleActive, 0, sizeof(_reticleActive)); memset(_magActive, 0, sizeof(_reticleActive)); memset(_magSizeMult, 0, sizeof(_magSizeMult)); + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + + _reticleQuad = geometryCache->allocateID(); + _magnifierQuad = geometryCache->allocateID(); + _audioRedQuad = geometryCache->allocateID(); + _audioGreenQuad = geometryCache->allocateID(); + _audioBlueQuad = geometryCache->allocateID(); + _domainStatusBorder = geometryCache->allocateID(); + _magnifierBorder = geometryCache->allocateID(); + } ApplicationOverlay::~ApplicationOverlay() { @@ -395,10 +404,6 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - if (_reticleQuad == GeometryCache::UNKNOWN_ID) { - _reticleQuad = DependencyManager::get()->allocateID(); - } - DependencyManager::get()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance), glm::vec3(x + mouseX + reticleSize, y + mouseY, -distance), glm::vec3(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance), @@ -733,30 +738,36 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool const glm::vec3 bottomRight = getPoint(bottomRightYawPitch.x, bottomRightYawPitch.y); const glm::vec3 topLeft = getPoint(topLeftYawPitch.x, topLeftYawPitch.y); const glm::vec3 topRight = getPoint(bottomRightYawPitch.x, topLeftYawPitch.y); + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + + if (bottomLeft != _previousMagnifierBottomLeft || bottomRight != _previousMagnifierBottomRight + || topLeft != _previousMagnifierTopLeft || topRight != _previousMagnifierTopRight) { + QVector border; + border << topLeft; + border << bottomLeft; + border << bottomRight; + border << topRight; + border << topLeft; + geometryCache->updateLinestrip(_magnifierBorder, border); + + _previousMagnifierBottomLeft = bottomLeft; + _previousMagnifierBottomRight = bottomRight; + _previousMagnifierTopLeft = topLeft; + _previousMagnifierTopRight = topRight; + } glPushMatrix(); { if (showBorder) { glDisable(GL_TEXTURE_2D); glLineWidth(1.0f); //Outer Line - glBegin(GL_LINE_STRIP); { - glColor4f(1.0f, 0.0f, 0.0f, _alpha); - - glVertex3f(topLeft.x, topLeft.y, topLeft.z); - glVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z); - glVertex3f(bottomRight.x, bottomRight.y, bottomRight.z); - glVertex3f(topRight.x, topRight.y, topRight.z); - glVertex3f(topLeft.x, topLeft.y, topLeft.z); - } glEnd(); - + glColor4f(1.0f, 0.0f, 0.0f, _alpha); + geometryCache->renderLinestrip(_magnifierBorder); glEnable(GL_TEXTURE_2D); } glColor4f(1.0f, 1.0f, 1.0f, _alpha); - if (_magnifierQuad == GeometryCache::UNKNOWN_ID) { - _magnifierQuad = DependencyManager::get()->allocateID(); - } - DependencyManager::get()->renderQuad(bottomLeft, bottomRight, topRight, topLeft, glm::vec2(magnifyULeft, magnifyVBottom), glm::vec2(magnifyURight, magnifyVBottom), @@ -861,9 +872,6 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Red Quad - if (_audioRedQuad == GeometryCache::UNKNOWN_ID) { - _audioRedQuad = DependencyManager::get()->allocateID(); - } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_RED_START, @@ -880,9 +888,6 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Green Quad - if (_audioGreenQuad == GeometryCache::UNKNOWN_ID) { - _audioGreenQuad = DependencyManager::get()->allocateID(); - } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_GREEN_START, @@ -898,9 +903,6 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Blue (low level) quad - if (_audioBlueQuad == GeometryCache::UNKNOWN_ID) { - _audioBlueQuad = DependencyManager::get()->allocateID(); - } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET, audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET, @@ -953,23 +955,29 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { NodeList* nodeList = NodeList::getInstance(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); - int right = glCanvas->width(); - int bottom = glCanvas->height(); + int width = glCanvas->width(); + int height = glCanvas->height(); + + if (width != _previousBorderWidth || height != _previousBorderHeight) { + QVector border; + border << glm::vec2(0, 0); + border << glm::vec2(0, height); + border << glm::vec2(width, height); + border << glm::vec2(width, 0); + border << glm::vec2(0, 0); + geometryCache->updateLinestrip(_domainStatusBorder, border); + _previousBorderWidth = width; + _previousBorderHeight = height; + } glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], CONNECTION_STATUS_BORDER_COLOR[1], CONNECTION_STATUS_BORDER_COLOR[2]); glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH); - glBegin(GL_LINE_LOOP); - - glVertex2i(0, 0); - glVertex2i(0, bottom); - glVertex2i(right, bottom); - glVertex2i(right, 0); - - glEnd(); + geometryCache->renderLinestrip(_domainStatusBorder); } } diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 20d38c879c..e2094f2a8e 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -113,6 +113,17 @@ private: int _audioRedQuad; int _audioGreenQuad; int _audioBlueQuad; + int _domainStatusBorder; + int _magnifierBorder; + + int _previousBorderWidth; + int _previousBorderHeight; + + glm::vec3 _previousMagnifierBottomLeft; + glm::vec3 _previousMagnifierBottomRight; + glm::vec3 _previousMagnifierTopLeft; + glm::vec3 _previousMagnifierTopRight; + }; #endif // hifi_ApplicationOverlay_h diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index 44c82afe38..69cd20d9a2 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -99,11 +99,7 @@ void BandwidthMeter::renderBox(int x, int y, int w, int h) { } void BandwidthMeter::renderVerticalLine(int x, int y, int h) { - - glBegin(GL_LINES); - glVertex2i(x, y); - glVertex2i(x, y + h); - glEnd(); + DependencyManager::get()->renderLine(glm::vec2(x, y), glm::vec2(x, y + h)); } inline int BandwidthMeter::centered(int subject, int object) { diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index c315723798..a7fc31ec23 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -23,7 +23,8 @@ Rectangle3DOverlay::Rectangle3DOverlay() { } Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) : - Planar3DOverlay(rectangle3DOverlay) + Planar3DOverlay(rectangle3DOverlay), + _geometryCacheID(DependencyManager::get()->allocateID()) { } @@ -84,6 +85,24 @@ void Rectangle3DOverlay::render(RenderArgs* args) { drawDashedLine(point4, point1); } else { + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + + if (halfDimensions != _previousHalfDimensions) { + QVector border; + border << glm::vec3(-halfDimensions.x, 0.0f, -halfDimensions.y); + border << glm::vec3(halfDimensions.x, 0.0f, -halfDimensions.y); + border << glm::vec3(halfDimensions.x, 0.0f, halfDimensions.y); + border << glm::vec3(-halfDimensions.x, 0.0f, halfDimensions.y); + border << glm::vec3(-halfDimensions.x, 0.0f, -halfDimensions.y); + geometryCache->updateLinestrip(_geometryCacheID, border); + + _previousHalfDimensions = halfDimensions; + + } + geometryCache->renderLinestrip(_geometryCacheID); + + /* glBegin(GL_LINE_STRIP); glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y); @@ -93,6 +112,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) { glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y); glEnd(); + */ } } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.h b/interface/src/ui/overlays/Rectangle3DOverlay.h index 5e75469f2d..f59ab21198 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.h +++ b/interface/src/ui/overlays/Rectangle3DOverlay.h @@ -24,6 +24,9 @@ public: virtual void setProperties(const QScriptValue& properties); virtual Rectangle3DOverlay* createClone() const; +private: + int _geometryCacheID; + glm::vec2 _previousHalfDimensions; }; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 94d853086b..8624dabfe7 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -597,6 +597,87 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in buffer.release(); } +void GeometryCache::updateLinestrip(int id, const QVector& points) { + BufferDetails& details = _registeredLinestrips[id]; + + // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed + if (details.buffer.isCreated()) { + details.buffer.destroy(); + #if 1// def WANT_DEBUG + qDebug() << "renderGrid()... RELEASING REGISTERED"; + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 2; + details.vertices = points.size(); + details.vertexSize = FLOATS_PER_VERTEX; + + GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; + GLfloat* vertex = vertexData; + + foreach (const glm::vec2& point, points) { + *(vertex++) = point.x; + *(vertex++) = point.y; + } + + details.buffer.create(); + details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); + details.buffer.bind(); + details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); + delete[] vertexData; + + #if 1 //def WANT_DEBUG + qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + #endif +} + +void GeometryCache::updateLinestrip(int id, const QVector& points) { + BufferDetails& details = _registeredLinestrips[id]; + + // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed + if (details.buffer.isCreated()) { + details.buffer.destroy(); + #if 1// def WANT_DEBUG + qDebug() << "renderGrid()... RELEASING REGISTERED"; + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 3; + details.vertices = points.size(); + details.vertexSize = FLOATS_PER_VERTEX; + + GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; + GLfloat* vertex = vertexData; + + foreach (const glm::vec3& point, points) { + *(vertex++) = point.x; + *(vertex++) = point.y; + *(vertex++) = point.z; + } + + details.buffer.create(); + details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); + details.buffer.bind(); + details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); + delete[] vertexData; + + #if 1 //def WANT_DEBUG + qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + #endif +} + +void GeometryCache::renderLinestrip(int id) { + BufferDetails& details = _registeredLinestrips[id]; + if (details.buffer.isCreated()) { + details.buffer.bind(); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); + glDrawArrays(GL_LINE_STRIP, 0, details.vertices); + glDisableClientState(GL_VERTEX_ARRAY); + details.buffer.release(); + } +} + void GeometryCache::renderSolidCube(float size) { VerticesIndices& vbo = _solidCubeVBOs[size]; const int FLOATS_PER_VERTEX = 3; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index a96c51dcf9..6e6fb68d07 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -114,6 +114,10 @@ public: void renderLine(const glm::vec3& p1, const glm::vec3& p2, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); + void updateLinestrip(int id, const QVector& points); + void updateLinestrip(int id, const QVector& points); + void renderLinestrip(int id); + /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param delayLoad if true, don't load the geometry immediately; wait until load is first requested @@ -161,6 +165,14 @@ private: QHash _lastRegisteredLine2D; QHash _line2DVBOs; QHash _registeredLine2DVBOs; + + struct BufferDetails { + QOpenGLBuffer buffer; + int vertices; + int vertexSize; + }; + + QHash _registeredLinestrips; From 56a3f98b2737dcabc1d54d21698dde9acd00905b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 21:04:56 -0800 Subject: [PATCH 13/52] renderLinestrip() for audio scope and 3d rectangle overlays --- interface/src/Audio.cpp | 31 +++++++++++++------ interface/src/Audio.h | 5 ++- .../src/ui/overlays/Rectangle3DOverlay.cpp | 12 ------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 1c6145b18e..5c5412c010 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -125,7 +125,10 @@ Audio::Audio(QObject* parent) : _lastSentAudioPacket(0), _packetSentTimeGaps(1, APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS), _audioOutputIODevice(_receivedAudioStream, this), - _audioScopeGrid(DependencyManager::get()->allocateID()) + _audioScopeGrid(DependencyManager::get()->allocateID()), + _inputID(DependencyManager::get()->allocateID()), + _outputLeftID(DependencyManager::get()->allocateID()), + _outputRightD(DependencyManager::get()->allocateID()) { // clear the array of locally injected samples memset(_localProceduralSamples, 0, NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL); @@ -1680,9 +1683,9 @@ void Audio::renderScope(int width, int height) { renderGrid(gridColor, x, y, w, h, gridRows, gridCols); QMutexLocker lock(&_guard); - renderLineStrip(inputColor, x, y, _samplesPerScope, _scopeInputOffset, _scopeInput); - renderLineStrip(outputLeftColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputLeft); - renderLineStrip(outputRightColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputRight); + renderLineStrip(_inputID, inputColor, x, y, _samplesPerScope, _scopeInputOffset, _scopeInput); + renderLineStrip(_outputLeftID, outputLeftColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputLeft); + renderLineStrip(_outputRightD, outputRightColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputRight); } void Audio::renderBackground(const float* color, int x, int y, int width, int height) { @@ -1698,10 +1701,9 @@ void Audio::renderGrid(const float* color, int x, int y, int width, int height, glColor4f(1, 1, 1, 1); } -void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray* byteArray) { +void Audio::renderLineStrip(int id, const float* color, int x, int y, int n, int offset, const QByteArray* byteArray) { glColor4fv(color); - glBegin(GL_LINE_STRIP); int16_t sample; int16_t* samples = ((int16_t*) byteArray->data()) + offset; @@ -1709,6 +1711,11 @@ void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, int count = (n - offset) / numSamplesToAverage; int remainder = (n - offset) % numSamplesToAverage; y += SCOPE_HEIGHT / 2; + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + + QVector points; + // Compute and draw the sample averages from the offset position for (int i = count; --i >= 0; ) { @@ -1717,7 +1724,7 @@ void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, sample += *samples++; } sample /= numSamplesToAverage; - glVertex2i(x++, y - sample); + points << glm::vec2(x++, y - sample); } // Compute and draw the sample average across the wrap boundary @@ -1733,7 +1740,7 @@ void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, sample += *samples++; } sample /= numSamplesToAverage; - glVertex2i(x++, y - sample); + points << glm::vec2(x++, y - sample); } else { samples = (int16_t*) byteArray->data(); } @@ -1746,9 +1753,13 @@ void Audio::renderLineStrip(const float* color, int x, int y, int n, int offset, sample += *samples++; } sample /= numSamplesToAverage; - glVertex2i(x++, y - sample); + points << glm::vec2(x++, y - sample); } - glEnd(); + + + geometryCache->updateLinestrip(id, points); + geometryCache->renderLinestrip(id); + glColor4f(1, 1, 1, 1); } diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 6b11530e7c..913aef7b86 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -297,7 +297,7 @@ private: // Audio scope methods for rendering void renderBackground(const float* color, int x, int y, int width, int height); void renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols); - void renderLineStrip(const float* color, int x, int y, int n, int offset, const QByteArray* byteArray); + void renderLineStrip(int id, const float* color, int x, int y, int n, int offset, const QByteArray* byteArray); // audio stats methods for rendering void renderAudioStreamStats(const AudioStreamStats& streamStats, int horizontalOffset, int& verticalOffset, @@ -366,6 +366,9 @@ private: WeakRecorderPointer _recorder; int _audioScopeGrid; + int _inputID; + int _outputLeftID; + int _outputRightD; }; diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index a7fc31ec23..5a70312dab 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -101,18 +101,6 @@ void Rectangle3DOverlay::render(RenderArgs* args) { } geometryCache->renderLinestrip(_geometryCacheID); - - /* - glBegin(GL_LINE_STRIP); - - glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y); - glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y); - glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y); - glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y); - glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y); - - glEnd(); - */ } } From 0606861b6684cfc05bbd0cdab646d5689d89df8e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 5 Jan 2015 21:45:17 -0800 Subject: [PATCH 14/52] dashed lines in GeometryCache --- interface/src/ui/overlays/Base3DOverlay.cpp | 31 -------- interface/src/ui/overlays/Base3DOverlay.h | 2 - interface/src/ui/overlays/Cube3DOverlay.cpp | 26 ++++--- interface/src/ui/overlays/Line3DOverlay.cpp | 2 +- .../src/ui/overlays/Rectangle3DOverlay.cpp | 12 +-- libraries/render-utils/src/GeometryCache.cpp | 77 +++++++++++++++++++ libraries/render-utils/src/GeometryCache.h | 6 ++ 7 files changed, 104 insertions(+), 52 deletions(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 12e593a1d0..96d6216266 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -186,34 +186,3 @@ bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3 float& distance, BoxFace& face) { return false; } - - -void Base3DOverlay::drawDashedLine(const glm::vec3& start, const glm::vec3& end) { - - glBegin(GL_LINES); - - // draw each line segment with appropriate gaps - const float DASH_LENGTH = 0.05f; - const float GAP_LENGTH = 0.025f; - const float SEGMENT_LENGTH = DASH_LENGTH + GAP_LENGTH; - float length = glm::distance(start, end); - float segmentCount = length / SEGMENT_LENGTH; - int segmentCountFloor = (int)glm::floor(segmentCount); - - glm::vec3 segmentVector = (end - start) / segmentCount; - glm::vec3 dashVector = segmentVector / SEGMENT_LENGTH * DASH_LENGTH; - glm::vec3 gapVector = segmentVector / SEGMENT_LENGTH * GAP_LENGTH; - - glm::vec3 point = start; - glVertex3f(point.x, point.y, point.z); - for (int i = 0; i < segmentCountFloor; i++) { - point += dashVector; - glVertex3f(point.x, point.y, point.z); - - point += gapVector; - glVertex3f(point.x, point.y, point.z); - } - glVertex3f(end.x, end.y, end.z); - - glEnd(); -} diff --git a/interface/src/ui/overlays/Base3DOverlay.h b/interface/src/ui/overlays/Base3DOverlay.h index 0e10a5f63b..38944f53ab 100644 --- a/interface/src/ui/overlays/Base3DOverlay.h +++ b/interface/src/ui/overlays/Base3DOverlay.h @@ -60,8 +60,6 @@ public: } protected: - void drawDashedLine(const glm::vec3& start, const glm::vec3& end); - glm::vec3 _position; float _lineWidth; glm::quat _rotation; diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 2242a642ca..62c2bea128 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -110,21 +110,23 @@ void Cube3DOverlay::render(RenderArgs* args) { glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z); glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z); glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z); + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); - drawDashedLine(bottomLeftNear, bottomRightNear); - drawDashedLine(bottomRightNear, bottomRightFar); - drawDashedLine(bottomRightFar, bottomLeftFar); - drawDashedLine(bottomLeftFar, bottomLeftNear); + geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear); + geometryCache->renderDashedLine(bottomRightNear, bottomRightFar); + geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar); + geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear); - drawDashedLine(topLeftNear, topRightNear); - drawDashedLine(topRightNear, topRightFar); - drawDashedLine(topRightFar, topLeftFar); - drawDashedLine(topLeftFar, topLeftNear); + geometryCache->renderDashedLine(topLeftNear, topRightNear); + geometryCache->renderDashedLine(topRightNear, topRightFar); + geometryCache->renderDashedLine(topRightFar, topLeftFar); + geometryCache->renderDashedLine(topLeftFar, topLeftNear); - drawDashedLine(bottomLeftNear, topLeftNear); - drawDashedLine(bottomRightNear, topRightNear); - drawDashedLine(bottomLeftFar, topLeftFar); - drawDashedLine(bottomRightFar, topRightFar); + geometryCache->renderDashedLine(bottomLeftNear, topLeftNear); + geometryCache->renderDashedLine(bottomRightNear, topRightNear); + geometryCache->renderDashedLine(bottomLeftFar, topLeftFar); + geometryCache->renderDashedLine(bottomRightFar, topRightFar); } else { glScalef(dimensions.x, dimensions.y, dimensions.z); diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 58b5fd6edd..48a995b80b 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -59,7 +59,7 @@ void Line3DOverlay::render(RenderArgs* args) { glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); if (getIsDashedLine()) { - drawDashedLine(_position, _end); + DependencyManager::get()->renderDashedLine(_position, _end, _geometryCacheID); } else { DependencyManager::get()->renderLine(_start, _end, _geometryCacheID); } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 5a70312dab..1257cc6952 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -65,6 +65,8 @@ void Rectangle3DOverlay::render(RenderArgs* args) { //glScalef(dimensions.x, dimensions.y, 1.0f); glLineWidth(_lineWidth); + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); // for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line... if (getIsSolid()) { @@ -79,14 +81,12 @@ void Rectangle3DOverlay::render(RenderArgs* args) { glm::vec3 point3(halfDimensions.x, 0.0f, halfDimensions.y); glm::vec3 point4(-halfDimensions.x, 0.0f, halfDimensions.y); - drawDashedLine(point1, point2); - drawDashedLine(point2, point3); - drawDashedLine(point3, point4); - drawDashedLine(point4, point1); + geometryCache->renderDashedLine(point1, point2); + geometryCache->renderDashedLine(point2, point3); + geometryCache->renderDashedLine(point3, point4); + geometryCache->renderDashedLine(point4, point1); } else { - - GeometryCache::SharedPointer geometryCache = DependencyManager::get(); if (halfDimensions != _previousHalfDimensions) { QVector border; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8624dabfe7..97270962fd 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1318,6 +1318,83 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } +void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id) { + bool registered = (id != UNKNOWN_ID); + Vec3Pair key(start, end); + BufferDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key]; + + // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed + if (registered && details.buffer.isCreated()) { + if (_lastRegisteredDashedLines[id] != key) { + details.buffer.destroy(); + _lastRegisteredDashedLines[id] = key; + #if 1// def WANT_DEBUG + qDebug() << "renderDashedLine()... RELEASING REGISTERED"; + #endif // def WANT_DEBUG + } + } + + if (!details.buffer.isCreated()) { + + // draw each line segment with appropriate gaps + const float DASH_LENGTH = 0.05f; + const float GAP_LENGTH = 0.025f; + const float SEGMENT_LENGTH = DASH_LENGTH + GAP_LENGTH; + float length = glm::distance(start, end); + float segmentCount = length / SEGMENT_LENGTH; + int segmentCountFloor = (int)glm::floor(segmentCount); + + glm::vec3 segmentVector = (end - start) / segmentCount; + glm::vec3 dashVector = segmentVector / SEGMENT_LENGTH * DASH_LENGTH; + glm::vec3 gapVector = segmentVector / SEGMENT_LENGTH * GAP_LENGTH; + + const int FLOATS_PER_VERTEX = 3; + details.vertices = (segmentCountFloor + 1) * 2; + details.vertexSize = FLOATS_PER_VERTEX; + + GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; + GLfloat* vertex = vertexData; + + glm::vec3 point = start; + *(vertex++) = point.x; + *(vertex++) = point.y; + *(vertex++) = point.z; + + for (int i = 0; i < segmentCountFloor; i++) { + point += dashVector; + *(vertex++) = point.x; + *(vertex++) = point.y; + *(vertex++) = point.z; + + point += gapVector; + *(vertex++) = point.x; + *(vertex++) = point.y; + *(vertex++) = point.z; + } + *(vertex++) = end.x; + *(vertex++) = end.y; + *(vertex++) = end.z; + + details.buffer.create(); + details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); + details.buffer.bind(); + details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); + delete[] vertexData; + + #if 1 //def WANT_DEBUG + qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + #endif + } else { + details.buffer.bind(); + } + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); + glDrawArrays(GL_LINES, 0, details.vertices); + glDisableClientState(GL_VERTEX_ARRAY); + details.buffer.release(); +} + void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) { bool registeredLine = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 6e6fb68d07..77338d4c42 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -112,6 +112,7 @@ public: void renderLine(const glm::vec3& p1, const glm::vec3& p2, int id = UNKNOWN_ID); + void renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); void updateLinestrip(int id, const QVector& points); @@ -174,6 +175,11 @@ private: QHash _registeredLinestrips; + QHash _lastRegisteredDashedLines; + QHash _dashedLines; + QHash _registeredDashedLines; + + QHash _gridBuffers; From 570607c044436ee2ad4f97313ddb109c17336c08 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 08:58:41 -0800 Subject: [PATCH 15/52] renderLines --- libraries/render-utils/src/GeometryCache.cpp | 16 ++++++++++++++-- libraries/render-utils/src/GeometryCache.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 97270962fd..f117b52343 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -604,7 +604,7 @@ void GeometryCache::updateLinestrip(int id, const QVector& points) { if (details.buffer.isCreated()) { details.buffer.destroy(); #if 1// def WANT_DEBUG - qDebug() << "renderGrid()... RELEASING REGISTERED"; + qDebug() << "updateLinestrip()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -638,7 +638,7 @@ void GeometryCache::updateLinestrip(int id, const QVector& points) { if (details.buffer.isCreated()) { details.buffer.destroy(); #if 1// def WANT_DEBUG - qDebug() << "renderGrid()... RELEASING REGISTERED"; + qDebug() << "updateLinestrip()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -678,6 +678,18 @@ void GeometryCache::renderLinestrip(int id) { } } +void GeometryCache::renderLines(int id) { + BufferDetails& details = _registeredLinestrips[id]; + if (details.buffer.isCreated()) { + details.buffer.bind(); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); + glDrawArrays(GL_LINES, 0, details.vertices); + glDisableClientState(GL_VERTEX_ARRAY); + details.buffer.release(); + } +} + void GeometryCache::renderSolidCube(float size) { VerticesIndices& vbo = _solidCubeVBOs[size]; const int FLOATS_PER_VERTEX = 3; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 77338d4c42..23a3d08765 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -118,6 +118,7 @@ public: void updateLinestrip(int id, const QVector& points); void updateLinestrip(int id, const QVector& points); void renderLinestrip(int id); + void renderLines(int id); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable From ac1f7c9a84647cda0ce4d837a4e7cb91df69627d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 09:52:27 -0800 Subject: [PATCH 16/52] multi-mode renderVertices --- interface/src/Audio.cpp | 4 +- interface/src/ui/ApplicationOverlay.cpp | 8 ++-- .../src/ui/overlays/Rectangle3DOverlay.cpp | 4 +- libraries/render-utils/src/GeometryCache.cpp | 42 +++++++------------ libraries/render-utils/src/GeometryCache.h | 9 ++-- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 5c5412c010..a66c6bbec1 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -1757,8 +1757,8 @@ void Audio::renderLineStrip(int id, const float* color, int x, int y, int n, int } - geometryCache->updateLinestrip(id, points); - geometryCache->renderLinestrip(id); + geometryCache->updateVertices(id, points); + geometryCache->renderVertices(GL_LINE_STRIP, id); glColor4f(1, 1, 1, 1); } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index fda932ef7d..08e285f67d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -749,7 +749,7 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool border << bottomRight; border << topRight; border << topLeft; - geometryCache->updateLinestrip(_magnifierBorder, border); + geometryCache->updateVertices(_magnifierBorder, border); _previousMagnifierBottomLeft = bottomLeft; _previousMagnifierBottomRight = bottomRight; @@ -763,7 +763,7 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool glLineWidth(1.0f); //Outer Line glColor4f(1.0f, 0.0f, 0.0f, _alpha); - geometryCache->renderLinestrip(_magnifierBorder); + geometryCache->renderVertices(GL_LINE_STRIP, _magnifierBorder); glEnable(GL_TEXTURE_2D); } glColor4f(1.0f, 1.0f, 1.0f, _alpha); @@ -967,7 +967,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { border << glm::vec2(width, height); border << glm::vec2(width, 0); border << glm::vec2(0, 0); - geometryCache->updateLinestrip(_domainStatusBorder, border); + geometryCache->updateVertices(_domainStatusBorder, border); _previousBorderWidth = width; _previousBorderHeight = height; } @@ -977,7 +977,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { CONNECTION_STATUS_BORDER_COLOR[2]); glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH); - geometryCache->renderLinestrip(_domainStatusBorder); + geometryCache->renderVertices(GL_LINE_STRIP, _domainStatusBorder); } } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 1257cc6952..2776754340 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -95,12 +95,12 @@ void Rectangle3DOverlay::render(RenderArgs* args) { border << glm::vec3(halfDimensions.x, 0.0f, halfDimensions.y); border << glm::vec3(-halfDimensions.x, 0.0f, halfDimensions.y); border << glm::vec3(-halfDimensions.x, 0.0f, -halfDimensions.y); - geometryCache->updateLinestrip(_geometryCacheID, border); + geometryCache->updateVertices(_geometryCacheID, border); _previousHalfDimensions = halfDimensions; } - geometryCache->renderLinestrip(_geometryCacheID); + geometryCache->renderVertices(GL_LINE_STRIP, _geometryCacheID); } } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f117b52343..491b70ceb8 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -597,14 +597,13 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in buffer.release(); } -void GeometryCache::updateLinestrip(int id, const QVector& points) { - BufferDetails& details = _registeredLinestrips[id]; +void GeometryCache::updateVertices(int id, const QVector& points) { + BufferDetails& details = _registeredVertices[id]; - // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed if (details.buffer.isCreated()) { details.buffer.destroy(); #if 1// def WANT_DEBUG - qDebug() << "updateLinestrip()... RELEASING REGISTERED"; + qDebug() << "updateVertices()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -627,18 +626,17 @@ void GeometryCache::updateLinestrip(int id, const QVector& points) { delete[] vertexData; #if 1 //def WANT_DEBUG - qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + qDebug() << "new registered vertices buffer made -- _registeredVertices.size():" << _registeredVertices.size(); #endif } -void GeometryCache::updateLinestrip(int id, const QVector& points) { - BufferDetails& details = _registeredLinestrips[id]; +void GeometryCache::updateVertices(int id, const QVector& points) { + BufferDetails& details = _registeredVertices[id]; - // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed if (details.buffer.isCreated()) { details.buffer.destroy(); #if 1// def WANT_DEBUG - qDebug() << "updateLinestrip()... RELEASING REGISTERED"; + qDebug() << "updateVertices()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -662,29 +660,17 @@ void GeometryCache::updateLinestrip(int id, const QVector& points) { delete[] vertexData; #if 1 //def WANT_DEBUG - qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + qDebug() << "new registered linestrip buffer made -- _registeredVertices.size():" << _registeredVertices.size(); #endif } -void GeometryCache::renderLinestrip(int id) { - BufferDetails& details = _registeredLinestrips[id]; +void GeometryCache::renderVertices(GLenum mode, int id) { + BufferDetails& details = _registeredVertices[id]; if (details.buffer.isCreated()) { details.buffer.bind(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); - glDrawArrays(GL_LINE_STRIP, 0, details.vertices); - glDisableClientState(GL_VERTEX_ARRAY); - details.buffer.release(); - } -} - -void GeometryCache::renderLines(int id) { - BufferDetails& details = _registeredLinestrips[id]; - if (details.buffer.isCreated()) { - details.buffer.bind(); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); - glDrawArrays(GL_LINES, 0, details.vertices); + glDrawArrays(mode, 0, details.vertices); glDisableClientState(GL_VERTEX_ARRAY); details.buffer.release(); } @@ -1394,7 +1380,11 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en delete[] vertexData; #if 1 //def WANT_DEBUG - qDebug() << "new registered linestrip buffer made -- _registeredLinestrips.size():" << _registeredLinestrips.size(); + if (registered) { + qDebug() << "new registered dashed line buffer made -- _registeredVertices:" << _registeredDashedLines.size(); + } else { + qDebug() << "new dashed lines buffer made -- _dashedLines:" << _dashedLines.size(); + } #endif } else { details.buffer.bind(); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 23a3d08765..17b23da945 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -115,10 +115,9 @@ public: void renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); - void updateLinestrip(int id, const QVector& points); - void updateLinestrip(int id, const QVector& points); - void renderLinestrip(int id); - void renderLines(int id); + void updateVertices(int id, const QVector& points); + void updateVertices(int id, const QVector& points); + void renderVertices(GLenum mode, int id); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable @@ -174,7 +173,7 @@ private: int vertexSize; }; - QHash _registeredLinestrips; + QHash _registeredVertices; QHash _lastRegisteredDashedLines; QHash _dashedLines; From 0d63391be85a3bf7daf58833d79f13ff43e06faf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 12:31:42 -0800 Subject: [PATCH 17/52] formatting --- interface/src/avatar/SkeletonModel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index db9140a67a..b3d34ce42e 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -383,17 +383,17 @@ void SkeletonModel::renderOrientationDirections(int jointIndex, glm::vec3 positi } OrientationLineIDs& jointLineIDs = _jointOrientationLines[jointIndex]; - glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; - glm::vec3 pUp = position + orientation * IDENTITY_UP * size; - glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; + glm::vec3 pRight = position + orientation * IDENTITY_RIGHT * size; + glm::vec3 pUp = position + orientation * IDENTITY_UP * size; + glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; - glColor3f(1.0f, 0.0f, 0.0f); + glColor3f(1.0f, 0.0f, 0.0f); geometryCache->renderLine(position, pRight, jointLineIDs._right); - glColor3f(0.0f, 1.0f, 0.0f); + glColor3f(0.0f, 1.0f, 0.0f); geometryCache->renderLine(position, pUp, jointLineIDs._up); - glColor3f(0.0f, 0.0f, 1.0f); + glColor3f(0.0f, 0.0f, 1.0f); geometryCache->renderLine(position, pFront, jointLineIDs._front); } From 1bfce7d876b3d19115a221c1e4fee2e759d5580c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 14:14:13 -0800 Subject: [PATCH 18/52] more removal of immediate mode --- interface/src/avatar/Avatar.cpp | 23 +++++++++++-------- interface/src/avatar/Avatar.h | 2 ++ interface/src/avatar/SkeletonModel.cpp | 21 ++++++++++++----- interface/src/avatar/SkeletonModel.h | 1 + libraries/render-utils/src/GeometryCache.cpp | 24 ++++++++++---------- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 9f8e5308a7..ddbaeece72 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -986,10 +986,16 @@ int Avatar::parseDataAtOffset(const QByteArray& packet, int offset) { return bytesRead; } +int Avatar::_jointConesID = GeometryCache::UNKNOWN_ID; + // render a makeshift cone section that serves as a body part connecting joint spheres void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2) { + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); - glBegin(GL_TRIANGLES); + if (_jointConesID == GeometryCache::UNKNOWN_ID) { + _jointConesID = geometryCache->allocateID(); + } glm::vec3 axis = position2 - position1; float length = glm::length(axis); @@ -1004,6 +1010,7 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float anglea = 0.0f; float angleb = 0.0f; + QVector points; for (int i = 0; i < NUM_BODY_CONE_SIDES; i ++) { @@ -1022,16 +1029,14 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, glm::vec3 p2a = position2 + perpSin * sa * radius2 + perpCos * ca * radius2; glm::vec3 p2b = position2 + perpSin * sb * radius2 + perpCos * cb * radius2; - glVertex3f(p1a.x, p1a.y, p1a.z); - glVertex3f(p1b.x, p1b.y, p1b.z); - glVertex3f(p2a.x, p2a.y, p2a.z); - glVertex3f(p1b.x, p1b.y, p1b.z); - glVertex3f(p2a.x, p2a.y, p2a.z); - glVertex3f(p2b.x, p2b.y, p2b.z); + points << p1a << p1b << p2a << p1b << p2a << p2b; } + + // TODO: this is really inefficient constantly recreating these vertices buffers. It would be + // better if the avatars cached these buffers for each of the joints they are rendering + geometryCache->updateVertices(_jointConesID, points); + geometryCache->renderVertices(GL_TRIANGLES, _jointConesID); } - - glEnd(); } void Avatar::updateCollisionGroups() { diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index f4727de94c..f975e8dac3 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -244,6 +244,8 @@ private: void renderBillboard(); float getBillboardSize() const; + + static int _jointConesID; }; #endif // hifi_Avatar_h diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index b3d34ce42e..54cd6c0bfe 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -31,6 +31,7 @@ enum StandingFootState { SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) : Model(parent), + _triangleFanID(DependencyManager::get()->allocateID()), _owningAvatar(owningAvatar), _boundingShape(), _boundingShapeLocalOffset(0.0f), @@ -38,7 +39,8 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) : _defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)), _standingFoot(NO_FOOT), _standingOffset(0.0f), - _clampedFootPosition(0.0f) { + _clampedFootPosition(0.0f) +{ } SkeletonModel::~SkeletonModel() { @@ -336,6 +338,9 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { float fanScale = directionSize * 0.75f; glScalef(fanScale, fanScale, fanScale); const int AXIS_COUNT = 3; + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); + for (int i = 0; i < AXIS_COUNT; i++) { if (joint.rotationMin[i] <= -PI + EPSILON && joint.rotationMax[i] >= PI - EPSILON) { continue; // unconstrained @@ -350,16 +355,20 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { otherAxis.x = 1.0f; } glColor4f(otherAxis.r, otherAxis.g, otherAxis.b, 0.75f); - - glBegin(GL_TRIANGLE_FAN); - glVertex3f(0.0f, 0.0f, 0.0f); + + QVector points; + points << glm::vec3(0.0f, 0.0f, 0.0f); const int FAN_SEGMENTS = 16; for (int j = 0; j < FAN_SEGMENTS; j++) { glm::vec3 rotated = glm::angleAxis(glm::mix(joint.rotationMin[i], joint.rotationMax[i], (float)j / (FAN_SEGMENTS - 1)), axis) * otherAxis; - glVertex3f(rotated.x, rotated.y, rotated.z); + points << rotated; } - glEnd(); + // TODO: this is really inefficient constantly recreating these vertices buffers. It would be + // better if the skeleton model cached these buffers for each of the joints they are rendering + geometryCache->updateVertices(_triangleFanID, points); + geometryCache->renderVertices(GL_TRIANGLE_FAN, _triangleFanID); + } glPopMatrix(); diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index dc5e521cb7..d28d1a8aef 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -152,6 +152,7 @@ private: int _right; }; QHash _jointOrientationLines; + int _triangleFanID; /// \param jointIndex index of joint in model /// \param position position of joint in model-frame diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 491b70ceb8..553e460a5c 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -523,11 +523,11 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in Vec3Pair& lastKey = _lastRegisteredGrid[id]; if (lastKey != key) { buffer.destroy(); - #if 1// def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderGrid()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } - #if 1// def WANT_DEBUG + #ifdef WANT_DEBUG else { qDebug() << "renderGrid()... REUSING PREVIOUSLY REGISTERED"; } @@ -575,7 +575,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in buffer.allocate(vertexData, vertices * 2 * sizeof(GLfloat)); delete[] vertexData; - #if 1 //def WANT_DEBUG + #ifdef WANT_DEBUG if (id == UNKNOWN_ID) { qDebug() << "new grid buffer made -- _alternateGridBuffers.size():" << _alternateGridBuffers.size(); } else { @@ -602,7 +602,7 @@ void GeometryCache::updateVertices(int id, const QVector& points) { if (details.buffer.isCreated()) { details.buffer.destroy(); - #if 1// def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "updateVertices()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -625,7 +625,7 @@ void GeometryCache::updateVertices(int id, const QVector& points) { details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); delete[] vertexData; - #if 1 //def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "new registered vertices buffer made -- _registeredVertices.size():" << _registeredVertices.size(); #endif } @@ -635,7 +635,7 @@ void GeometryCache::updateVertices(int id, const QVector& points) { if (details.buffer.isCreated()) { details.buffer.destroy(); - #if 1// def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "updateVertices()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -659,7 +659,7 @@ void GeometryCache::updateVertices(int id, const QVector& points) { details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); delete[] vertexData; - #if 1 //def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "new registered linestrip buffer made -- _registeredVertices.size():" << _registeredVertices.size(); #endif } @@ -1326,7 +1326,7 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en if (_lastRegisteredDashedLines[id] != key) { details.buffer.destroy(); _lastRegisteredDashedLines[id] = key; - #if 1// def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderDashedLine()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } @@ -1379,7 +1379,7 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); delete[] vertexData; - #if 1 //def WANT_DEBUG + #ifdef WANT_DEBUG if (registered) { qDebug() << "new registered dashed line buffer made -- _registeredVertices:" << _registeredDashedLines.size(); } else { @@ -1494,11 +1494,11 @@ void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); vbo.first = vbo.second = 0; - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderLine() 2D... RELEASING REGISTERED line"; #endif // def WANT_DEBUG } - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG else { qDebug() << "renderLine() 2D... REUSING PREVIOUSLY REGISTERED line"; } @@ -1544,7 +1544,7 @@ void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG if (id == UNKNOWN_ID) { qDebug() << "new renderLine() 2D VBO made -- _line2DVBOs.size():" << _line2DVBOs.size(); } else { From d796ebf63289183f91260ec1500f08ce4e48f090 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 14:43:42 -0800 Subject: [PATCH 19/52] migrate circle overlays to use renderVertices() --- interface/src/ui/overlays/Circle3DOverlay.cpp | 107 +++++++++++++----- interface/src/ui/overlays/Circle3DOverlay.h | 9 ++ 2 files changed, 85 insertions(+), 31 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 32ae7f0a07..bc3e1c72aa 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -12,6 +12,7 @@ #include "InterfaceConfig.h" #include +#include #include #include #include @@ -27,7 +28,14 @@ Circle3DOverlay::Circle3DOverlay() : _majorTickMarksAngle(0.0f), _minorTickMarksAngle(0.0f), _majorTickMarksLength(0.0f), - _minorTickMarksLength(0.0f) + _minorTickMarksLength(0.0f), + _quadVerticesID(GeometryCache::UNKNOWN_ID), + _lineVerticesID(GeometryCache::UNKNOWN_ID), + _ticksVerticesID(GeometryCache::UNKNOWN_ID), + _lastStartAt(-1.0f), + _lastEndAt(-1.0f), + _lastOuterRadius(-1.0f), + _lastInnerRadius(-1.0f) { _majorTickMarksColor.red = _majorTickMarksColor.green = _majorTickMarksColor.blue = (unsigned char)0; _minorTickMarksColor.red = _minorTickMarksColor.green = _minorTickMarksColor.blue = (unsigned char)0; @@ -45,7 +53,14 @@ Circle3DOverlay::Circle3DOverlay(const Circle3DOverlay* circle3DOverlay) : _majorTickMarksLength(circle3DOverlay->_majorTickMarksLength), _minorTickMarksLength(circle3DOverlay->_minorTickMarksLength), _majorTickMarksColor(circle3DOverlay->_majorTickMarksColor), - _minorTickMarksColor(circle3DOverlay->_minorTickMarksColor) + _minorTickMarksColor(circle3DOverlay->_minorTickMarksColor), + _quadVerticesID(GeometryCache::UNKNOWN_ID), + _lineVerticesID(GeometryCache::UNKNOWN_ID), + _ticksVerticesID(GeometryCache::UNKNOWN_ID), + _lastStartAt(-1.0f), + _lastEndAt(-1.0f), + _lastOuterRadius(-1.0f), + _lastInnerRadius(-1.0f) { } @@ -63,6 +78,8 @@ void Circle3DOverlay::render(RenderArgs* args) { return; // do nothing if our alpha is 0, we're not visible } + bool geometryChanged = false; + const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle const float SLICE_ANGLE = FULL_CIRCLE / SLICES; @@ -102,41 +119,62 @@ void Circle3DOverlay::render(RenderArgs* args) { float endAt = getEndAt(); glLineWidth(_lineWidth); + + GeometryCache::SharedPointer geometryCache = DependencyManager::get(); // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getIsSolid()) { - glBegin(GL_QUAD_STRIP); - - float angle = startAt; - float angleInRadians = glm::radians(angle); - glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); - glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - - glVertex2f(firstInnerPoint.x, firstInnerPoint.y); - glVertex2f(firstOuterPoint.x, firstOuterPoint.y); - - while (angle < endAt) { - angleInRadians = glm::radians(angle); - glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); - glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - - glVertex2f(thisOuterPoint.x, thisOuterPoint.y); - glVertex2f(thisInnerPoint.x, thisInnerPoint.y); - - angle += SLICE_ANGLE; + if (_quadVerticesID == GeometryCache::UNKNOWN_ID) { + _quadVerticesID = geometryCache->allocateID(); } - - // get the last slice portion.... - angle = endAt; - angleInRadians = glm::radians(angle); - glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); - glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - - glVertex2f(lastOuterPoint.x, lastOuterPoint.y); - glVertex2f(lastInnerPoint.x, lastInnerPoint.y); + //glBegin(GL_QUAD_STRIP); + + if (startAt != _lastStartAt || endAt != _lastEndAt || + innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius) { + + geometryChanged = true; + + QVector points; + + float angle = startAt; + float angleInRadians = glm::radians(angle); + glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); + glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + + //glVertex2f(firstInnerPoint.x, firstInnerPoint.y); + //glVertex2f(firstOuterPoint.x, firstOuterPoint.y); + points << firstInnerPoint << firstOuterPoint; + + while (angle < endAt) { + angleInRadians = glm::radians(angle); + glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); + glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + + //glVertex2f(thisOuterPoint.x, thisOuterPoint.y); + //glVertex2f(thisInnerPoint.x, thisInnerPoint.y); + + points << thisOuterPoint << thisInnerPoint; + + angle += SLICE_ANGLE; + } + + // get the last slice portion.... + angle = endAt; + angleInRadians = glm::radians(angle); + glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); + glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + + //glVertex2f(lastOuterPoint.x, lastOuterPoint.y); + //glVertex2f(lastInnerPoint.x, lastInnerPoint.y); + + points << lastOuterPoint << lastInnerPoint; + + geometryCache->updateVertices(_quadVerticesID, points); + } + + geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); - glEnd(); } else { if (getIsDashedLine()) { glBegin(GL_LINES); @@ -237,6 +275,13 @@ void Circle3DOverlay::render(RenderArgs* args) { glPopMatrix(); glPopMatrix(); + if (geometryChanged) { + _lastStartAt = startAt; + _lastEndAt = endAt; + _lastInnerRadius = innerRadius; + _lastOuterRadius = outerRadius; + } + if (glower) { delete glower; } diff --git a/interface/src/ui/overlays/Circle3DOverlay.h b/interface/src/ui/overlays/Circle3DOverlay.h index 92fdf54c82..f9cd5ebbf2 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.h +++ b/interface/src/ui/overlays/Circle3DOverlay.h @@ -64,6 +64,15 @@ protected: float _minorTickMarksLength; xColor _majorTickMarksColor; xColor _minorTickMarksColor; + + int _quadVerticesID; + int _lineVerticesID; + int _ticksVerticesID; + + float _lastStartAt; + float _lastEndAt; + float _lastOuterRadius; + float _lastInnerRadius; }; From 95f8447191a3bfd078f826d980b12e81a9113d65 Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 6 Jan 2015 15:47:25 -0800 Subject: [PATCH 20/52] Incremental update to scripts cleanup -Moved more of the scripts around -Fixed up the location on assets on start. e.g. gun.js -Removed additional Scripts. --- examples/avatarLocalLight.js | 139 -------- examples/{ => controllers/gamepad}/gamepad.js | 0 examples/{ => controllers/hydra}/airGuitar.js | 2 +- examples/{ => controllers/hydra}/drumStick.js | 2 +- examples/{ => controllers/hydra}/frisbee.js | 30 +- examples/{ => controllers/hydra}/gun.js | 6 +- .../{ => controllers/hydra}/squeezeHands.js | 2 +- examples/{ => controllers/leap}/leapHands.js | 0 .../{ => controllers/leap}/leapOfFaith.js | 0 .../oculus}/virtualKeyboard.js | 2 +- examples/entityBirds.js | 202 ----------- examples/{ => example}/audioBall.js | 2 +- examples/{ => example}/audioReverbOn.js | 6 +- examples/{ => example}/birdSongs.js | 0 examples/{ => example}/bot.js | 2 +- .../{ => example}/botProceduralWayPoints.js | 2 +- examples/{ => example}/bot_procedural.js | 2 +- .../{ => example}/bot_randomExpression.js | 2 +- examples/{ => example}/butterflies.js | 4 +- examples/example/editModelExample.js | 2 +- examples/{ => example}/flockingBirds.js | 0 examples/{ => example}/guidedTour.js | 0 examples/example/overlaysExample.js | 2 +- examples/example/radio.js | 2 +- examples/example/spaceInvadersExample.js | 10 +- examples/fountain.js | 77 ---- examples/grenadeLauncher.js | 328 ------------------ 27 files changed, 44 insertions(+), 782 deletions(-) delete mode 100644 examples/avatarLocalLight.js rename examples/{ => controllers/gamepad}/gamepad.js (100%) rename examples/{ => controllers/hydra}/airGuitar.js (99%) rename examples/{ => controllers/hydra}/drumStick.js (98%) rename examples/{ => controllers/hydra}/frisbee.js (95%) rename examples/{ => controllers/hydra}/gun.js (97%) rename examples/{ => controllers/hydra}/squeezeHands.js (98%) rename examples/{ => controllers/leap}/leapHands.js (100%) rename examples/{ => controllers/leap}/leapOfFaith.js (100%) rename examples/{ => controllers/oculus}/virtualKeyboard.js (99%) delete mode 100644 examples/entityBirds.js rename examples/{ => example}/audioBall.js (98%) rename examples/{ => example}/audioReverbOn.js (91%) rename examples/{ => example}/birdSongs.js (100%) rename examples/{ => example}/bot.js (99%) rename examples/{ => example}/botProceduralWayPoints.js (99%) rename examples/{ => example}/bot_procedural.js (99%) rename examples/{ => example}/bot_randomExpression.js (98%) rename examples/{ => example}/butterflies.js (95%) rename examples/{ => example}/flockingBirds.js (100%) rename examples/{ => example}/guidedTour.js (100%) delete mode 100644 examples/fountain.js delete mode 100644 examples/grenadeLauncher.js diff --git a/examples/avatarLocalLight.js b/examples/avatarLocalLight.js deleted file mode 100644 index b1f31888d8..0000000000 --- a/examples/avatarLocalLight.js +++ /dev/null @@ -1,139 +0,0 @@ -// -// avatarLocalLight.js -// -// Created by Tony Peng on July 2nd, 2014 -// Copyright 2014 High Fidelity, Inc. -// -// Set the local light direction and color on the avatar -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -var localLightDirections = [ {x: 1.0, y:0.0, z: 0.0}, {x: 0.0, y:0.0, z: 1.0} ]; -var localLightColors = [ {x: 0.4, y:0.335, z: 0.266}, {x: 0.4, y:0.335, z: 0.266} ]; - -var currentSelection = 0; -var currentNumLights = 2; -var maxNumLights = 2; -var currentNumAvatars = 0; -var changeDelta = 0.1; -var lightsDirty = true; - -function keyPressEvent(event) { - - var choice = parseInt(event.text); - - if (event.text == "1") { - currentSelection = 0; - print("light election = " + currentSelection); - } - else if (event.text == "2" ) { - currentSelection = 1; - print("light selection = " + currentSelection); - } - else if (event.text == "3" ) { - currentSelection = 2; - print("light selection = " + currentSelection); - } - else if (event.text == "4" ) { - currentSelection = 3; - print("light selection = " + currentSelection); - } - else if (event.text == "5" ) { - localLightColors[currentSelection].x += changeDelta; - if ( localLightColors[currentSelection].x > 1.0) { - localLightColors[currentSelection].x = 0.0; - } - - lightsDirty = true; - print("CHANGE RED light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" ); - } - else if (event.text == "6" ) { - localLightColors[currentSelection].y += changeDelta; - if ( localLightColors[currentSelection].y > 1.0) { - localLightColors[currentSelection].y = 0.0; - } - - lightsDirty = true; - print("CHANGE GREEN light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" ); - } - else if (event.text == "7" ) { - localLightColors[currentSelection].z += changeDelta; - if ( localLightColors[currentSelection].z > 1.0) { - localLightColors[currentSelection].z = 0.0; - } - - lightsDirty = true; - print("CHANGE BLUE light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" ); - } - else if (event.text == "8" ) { - localLightDirections[currentSelection].x += changeDelta; - if (localLightDirections[currentSelection].x > 1.0) { - localLightDirections[currentSelection].x = -1.0; - } - - lightsDirty = true; - print("PLUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" ); - } - else if (event.text == "9" ) { - localLightDirections[currentSelection].x -= changeDelta; - if (localLightDirections[currentSelection].x < -1.0) { - localLightDirections[currentSelection].x = 1.0; - } - - lightsDirty = true; - print("MINUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" ); - } - else if (event.text == "0" ) { - localLightDirections[currentSelection].y += changeDelta; - if (localLightDirections[currentSelection].y > 1.0) { - localLightDirections[currentSelection].y = -1.0; - } - - lightsDirty = true; - print("PLUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" ); - } - else if (event.text == "-" ) { - localLightDirections[currentSelection].y -= changeDelta; - if (localLightDirections[currentSelection].y < -1.0) { - localLightDirections[currentSelection].y = 1.0; - } - - lightsDirty = true; - print("MINUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" ); - } - else if (event.text == "," ) { - if (currentNumLights + 1 <= maxNumLights) { - ++currentNumLights; - lightsDirty = true; - } - - print("ADD LIGHT, number of lights " + currentNumLights); - } - else if (event.text == "." ) { - if (currentNumLights - 1 >= 0 ) { - --currentNumLights; - lightsDirty = true; - } - - print("REMOVE LIGHT, number of lights " + currentNumLights); - } -} - -function updateLocalLights() -{ - if (lightsDirty) { - var localLights = []; - for (var i = 0; i < currentNumLights; i++) { - localLights.push({ direction: localLightDirections[i], color: localLightColors[i] }); - } - AvatarManager.setLocalLights(localLights); - lightsDirty = false; - } -} - -// main -Script.update.connect(updateLocalLights); -Controller.keyPressEvent.connect(keyPressEvent); - diff --git a/examples/gamepad.js b/examples/controllers/gamepad/gamepad.js similarity index 100% rename from examples/gamepad.js rename to examples/controllers/gamepad/gamepad.js diff --git a/examples/airGuitar.js b/examples/controllers/hydra/airGuitar.js similarity index 99% rename from examples/airGuitar.js rename to examples/controllers/hydra/airGuitar.js index 5a62ee3e7b..91e4728933 100644 --- a/examples/airGuitar.js +++ b/examples/controllers/hydra/airGuitar.js @@ -10,7 +10,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); function length(v) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); diff --git a/examples/drumStick.js b/examples/controllers/hydra/drumStick.js similarity index 98% rename from examples/drumStick.js rename to examples/controllers/hydra/drumStick.js index 88ffa36c50..14e1413742 100644 --- a/examples/drumStick.js +++ b/examples/controllers/hydra/drumStick.js @@ -10,7 +10,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); function length(v) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); diff --git a/examples/frisbee.js b/examples/controllers/hydra/frisbee.js similarity index 95% rename from examples/frisbee.js rename to examples/controllers/hydra/frisbee.js index 2d60827858..a9fd74910d 100644 --- a/examples/frisbee.js +++ b/examples/controllers/hydra/frisbee.js @@ -15,8 +15,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); -Script.include("libraries/toolBars.js"); +Script.include("../../libraries/globals.js"); +Script.include("../../libraries/toolBars.js"); const LEFT_PALM = 0; const LEFT_TIP = 1; @@ -192,15 +192,18 @@ function cleanupFrisbees() { } function checkControllerSide(hand) { + // print("cCS"); // If I don't currently have a frisbee in my hand, then try to catch closest one if (!hand.holdingFrisbee && hand.grabButtonPressed()) { var closestEntity = Entities.findClosestEntity(hand.palmPosition(), CATCH_RADIUS); var modelUrl = Entities.getEntityProperties(closestEntity).modelURL; + print("lol2"+closestEntity.isKnownID); if (closestEntity.isKnownID && validFrisbeeURL(Entities.getEntityProperties(closestEntity).modelURL)) { + print("lol"); Entities.editEntity(closestEntity, {modelScale: 1, inHand: true, position: hand.holdPosition(), shouldDie: true}); Entities.deleteEntity(closestEntity); debugPrint(hand.message + " HAND- CAUGHT SOMETHING!!"); - + print("lol"); var properties = { type: "Model", position: hand.holdPosition(), @@ -208,10 +211,10 @@ function checkControllerSide(hand) { gravity: { x: 0, y: 0, z: 0}, inHand: true, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, - damping: 0.00001, + damping: 0.999, modelURL: modelUrl, - modelScale: FRISBEE_MODEL_SCALE, - modelRotation: hand.holdRotation(), + scale: FRISBEE_MODEL_SCALE, + rotation: hand.holdRotation(), lifetime: FRISBEE_LIFETIME }; @@ -235,10 +238,10 @@ function checkControllerSide(hand) { gravity: { x: 0, y: 0, z: 0}, inHand: true, dimensions: { x: FRISBEE_RADIUS, y: FRISBEE_RADIUS / 5, z: FRISBEE_RADIUS }, - damping: 0.00001, + damping: 0, modelURL: frisbeeURL(), - modelScale: FRISBEE_MODEL_SCALE, - modelRotation: hand.holdRotation(), + scale: FRISBEE_MODEL_SCALE, + rotation: hand.holdRotation(), lifetime: FRISBEE_LIFETIME }; @@ -270,7 +273,7 @@ function checkControllerSide(hand) { inHand: false, lifetime: FRISBEE_LIFETIME, gravity: { x: 0, y: -GRAVITY_STRENGTH, z: 0}, - modelRotation: hand.holdRotation() + rotation: hand.holdRotation() }; Entities.editEntity(hand.entity, properties); @@ -304,7 +307,7 @@ function hydraCheck() { var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; hydrasConnected = (numberOfButtons == 12 && numberOfTriggers == 2 && controllersPerTrigger == 2); - return hydrasConnected; + return true;//hydrasConnected; } function checkController(deltaTime) { @@ -314,6 +317,7 @@ function checkController(deltaTime) { } // this is expected for hydras if (hydraCheck()) { +///print("testrr "); checkControllerSide(leftHand); checkControllerSide(rightHand); } @@ -333,7 +337,7 @@ function controlFrisbees(deltaTime) { killSimulations.push(frisbee); continue; } - Entities.editEntity(simulatedFrisbees[frisbee], {modelRotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))}); + Entities.editEntity(simulatedFrisbees[frisbee], {rotation: Quat.multiply(properties.modelRotation, Quat.fromPitchYawRollDegrees(0, speed * deltaTime * SPIN_MULTIPLIER, 0))}); } for (var i = killSimulations.length - 1; i >= 0; i--) { @@ -444,4 +448,4 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Menu.menuItemEvent.connect(menuItemEvent); Script.scriptEnding.connect(scriptEnding); Script.update.connect(checkController); -Script.update.connect(controlFrisbees); +Script.update.connect(controlFrisbees); \ No newline at end of file diff --git a/examples/gun.js b/examples/controllers/hydra/gun.js similarity index 97% rename from examples/gun.js rename to examples/controllers/hydra/gun.js index af5447c2d6..de18317335 100644 --- a/examples/gun.js +++ b/examples/controllers/hydra/gun.js @@ -14,7 +14,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); function getRandomFloat(min, max) { return Math.random() * (max - min) + min; @@ -194,8 +194,8 @@ function playLoadSound() { Audio.playSound(loadSound, audioOptions); } -//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); -MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); +MyAvatar.attach(gunModel, "RightHand", {x:0.02, y: 0.11, z: 0.04}, Quat.fromPitchYawRollDegrees(-0, -160, -79), 0.20); +//MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); // Give a bit of time to load before playing sound Script.setTimeout(playLoadSound, 2000); diff --git a/examples/squeezeHands.js b/examples/controllers/hydra/squeezeHands.js similarity index 98% rename from examples/squeezeHands.js rename to examples/controllers/hydra/squeezeHands.js index 21da7f9c25..84e5aefb51 100644 --- a/examples/squeezeHands.js +++ b/examples/controllers/hydra/squeezeHands.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); var rightHandAnimation = HIFI_PUBLIC_BUCKET + "animations/RightHandAnimPhilip.fbx"; var leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx"; diff --git a/examples/leapHands.js b/examples/controllers/leap/leapHands.js similarity index 100% rename from examples/leapHands.js rename to examples/controllers/leap/leapHands.js diff --git a/examples/leapOfFaith.js b/examples/controllers/leap/leapOfFaith.js similarity index 100% rename from examples/leapOfFaith.js rename to examples/controllers/leap/leapOfFaith.js diff --git a/examples/virtualKeyboard.js b/examples/controllers/oculus/virtualKeyboard.js similarity index 99% rename from examples/virtualKeyboard.js rename to examples/controllers/oculus/virtualKeyboard.js index ce793c6ea0..dc3c2eb3cc 100644 --- a/examples/virtualKeyboard.js +++ b/examples/controllers/oculus/virtualKeyboard.js @@ -15,7 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); const KBD_UPPERCASE_DEFAULT = 0; const KBD_LOWERCASE_DEFAULT = 1; diff --git a/examples/entityBirds.js b/examples/entityBirds.js deleted file mode 100644 index 9512597af9..0000000000 --- a/examples/entityBirds.js +++ /dev/null @@ -1,202 +0,0 @@ -// -// particleBirds.js -// examples -// -// Created by Benjamin Arnold on May 29, 2014 -// Copyright 2014 High Fidelity, Inc. -// -// This sample script creates a swarm of tweeting bird entities that fly around the avatar. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("libraries/globals.js"); - -// Multiply vector by scalar -function vScalarMult(v, s) { - var rval = { x: v.x * s, y: v.y * s, z: v.z * s }; - return rval; -} - -function printVector(v) { - print(v.x + ", " + v.y + ", " + v.z + "\n"); -} -// Create a random vector with individual lengths between a,b -function randVector(a, b) { - var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) }; - return rval; -} - -// Returns a vector which is fraction of the way between a and b -function vInterpolate(a, b, fraction) { - var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction }; - return rval; -} - -var startTimeInSeconds = new Date().getTime() / 1000; - -var birdLifetime = 20; // lifetime of the birds in seconds! -var range = 1.0; // Over what distance in meters do you want the flock to fly around -var frame = 0; - -var CHANCE_OF_MOVING = 0.1; -var CHANCE_OF_TWEETING = 0.05; -var BIRD_GRAVITY = -0.1; -var BIRD_FLAP_SPEED = 10.0; -var BIRD_VELOCITY = 0.5; -var myPosition = MyAvatar.position; - -var range = 1.0; // Distance around avatar where I can move - -// This is our Bird object -function Bird (particleID, tweetSound, targetPosition) { - this.particleID = particleID; - this.tweetSound = tweetSound; - this.previousFlapOffset = 0; - this.targetPosition = targetPosition; - this.moving = false; - this.tweeting = -1; -} - -// Array of birds -var birds = []; - -function addBird() -{ - // Decide what kind of bird we are - var tweet; - var color; - var size; - var which = Math.random(); - if (which < 0.2) { - tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); - color = { red: 100, green: 50, blue: 120 }; - size = 0.08; - } else if (which < 0.4) { - tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/rosyfacedlovebird.raw"); - color = { red: 100, green: 150, blue: 75 }; - size = 0.09; - } else if (which < 0.6) { - tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/saysphoebe.raw"); - color = { red: 84, green: 121, blue: 36 }; - size = 0.05; - } else if (which < 0.8) { - tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); - color = { red: 23, green: 197, blue: 230 }; - size = 0.12; - } else { - tweet = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/westernscreechowl.raw"); - color = { red: 50, green: 67, blue: 144 }; - size = 0.15; - } - var properties = { - type: "Sphere", - lifetime: birdLifetime, - position: Vec3.sum(randVector(-range, range), myPosition), - velocity: { x: 0, y: 0, z: 0 }, - gravity: { x: 0, y: BIRD_GRAVITY, z: 0 }, - dimensions: { x: size * 2, y: size * 2, z: size * 2 }, - color: color - }; - - birds.push(new Bird(Entities.addEntity(properties), tweet, properties.position)); -} - -var numBirds = 30; - -// Generate the birds -for (var i = 0; i < numBirds; i++) { - addBird(); -} - -// Main update function -function updateBirds(deltaTime) { - - // Check to see if we've been running long enough that our birds are dead - var nowTimeInSeconds = new Date().getTime() / 1000; - if ((nowTimeInSeconds - startTimeInSeconds) >= birdLifetime) { - - print("our birds are dying, stop our script"); - Script.stop(); - return; - } - - frame++; - // Only update every third frame - if ((frame % 3) == 0) { - myPosition = MyAvatar.position; - - // Update all the birds - for (var i = 0; i < numBirds; i++) { - particleID = birds[i].particleID; - var properties = Entities.getEntityProperties(particleID); - - // Tweeting behavior - if (birds[i].tweeting == 0) { - if (Math.random() < CHANCE_OF_TWEETING) { - Audio.playSound(birds[i].tweetSound, { - position: properties.position, - volume: 0.75 - }); - birds[i].tweeting = 10; - } - } else { - birds[i].tweeting -= 1; - } - - // Begin movement by getting a target - if (birds[i].moving == false) { - if (Math.random() < CHANCE_OF_MOVING) { - var targetPosition = Vec3.sum(randVector(-range, range), myPosition); - - if (targetPosition.x < 0) { - targetPosition.x = 0; - } - if (targetPosition.y < 0) { - targetPosition.y = 0; - } - if (targetPosition.z < 0) { - targetPosition.z = 0; - } - if (targetPosition.x > TREE_SCALE) { - targetPosition.x = TREE_SCALE; - } - if (targetPosition.y > TREE_SCALE) { - targetPosition.y = TREE_SCALE; - } - if (targetPosition.z > TREE_SCALE) { - targetPosition.z = TREE_SCALE; - } - - birds[i].targetPosition = targetPosition; - - birds[i].moving = true; - } - } - // If we are moving, move towards the target - if (birds[i].moving) { - var desiredVelocity = Vec3.subtract(birds[i].targetPosition, properties.position); - desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BIRD_VELOCITY); - - properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2); - // If we are near the target, we should get a new target - if (Vec3.length(Vec3.subtract(properties.position, birds[i].targetPosition)) < (properties.dimensions.x / 5.0)) { - birds[i].moving = false; - } - } - - // Use a cosine wave offset to make it look like its flapping. - var offset = Math.cos(nowTimeInSeconds * BIRD_FLAP_SPEED) * properties.dimensions.x; - properties.position.y = properties.position.y + (offset - birds[i].previousFlapOffset); - // Change position relative to previous offset. - birds[i].previousFlapOffset = offset; - - // Update the particle - Entities.editEntity(particleID, properties); - } - } -} - -// register the call back so it fires before each data send -Script.update.connect(updateBirds); diff --git a/examples/audioBall.js b/examples/example/audioBall.js similarity index 98% rename from examples/audioBall.js rename to examples/example/audioBall.js index e0c0ce7976..c4b245fbf1 100644 --- a/examples/audioBall.js +++ b/examples/example/audioBall.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); var CHANCE_OF_PLAYING_SOUND = 0.01; diff --git a/examples/audioReverbOn.js b/examples/example/audioReverbOn.js similarity index 91% rename from examples/audioReverbOn.js rename to examples/example/audioReverbOn.js index 479f5bba74..72f2fa97bc 100644 --- a/examples/audioReverbOn.js +++ b/examples/example/audioReverbOn.js @@ -4,6 +4,10 @@ // // Copyright 2014 High Fidelity, Inc. // +// +// Gives the ability to be set various reverb settings. +// +// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -14,7 +18,7 @@ var audioOptions = new AudioEffectOptions({ roomSize: 50, // Seconds - reverbTime: 4, + reverbTime: 10, // Between 0 - 1 damping: 0.50, diff --git a/examples/birdSongs.js b/examples/example/birdSongs.js similarity index 100% rename from examples/birdSongs.js rename to examples/example/birdSongs.js diff --git a/examples/bot.js b/examples/example/bot.js similarity index 99% rename from examples/bot.js rename to examples/example/bot.js index aadd038eb6..fae6647ff3 100644 --- a/examples/bot.js +++ b/examples/example/bot.js @@ -12,7 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); function getRandomFloat(min, max) { return Math.random() * (max - min) + min; diff --git a/examples/botProceduralWayPoints.js b/examples/example/botProceduralWayPoints.js similarity index 99% rename from examples/botProceduralWayPoints.js rename to examples/example/botProceduralWayPoints.js index e20714bd27..b7c1fa1fe2 100644 --- a/examples/botProceduralWayPoints.js +++ b/examples/example/botProceduralWayPoints.js @@ -20,7 +20,7 @@ // //For procedural walk animation -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); var procAnimAPI = new ProcAnimAPI(); diff --git a/examples/bot_procedural.js b/examples/example/bot_procedural.js similarity index 99% rename from examples/bot_procedural.js rename to examples/example/bot_procedural.js index eec3c8906d..5ab867e150 100644 --- a/examples/bot_procedural.js +++ b/examples/example/bot_procedural.js @@ -11,7 +11,7 @@ // //For procedural walk animation -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); var procAnimAPI = new ProcAnimAPI(); diff --git a/examples/bot_randomExpression.js b/examples/example/bot_randomExpression.js similarity index 98% rename from examples/bot_randomExpression.js rename to examples/example/bot_randomExpression.js index 44d546e763..32bfb24065 100644 --- a/examples/bot_randomExpression.js +++ b/examples/example/bot_randomExpression.js @@ -12,7 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); function getRandomFloat(min, max) { return Math.random() * (max - min) + min; diff --git a/examples/butterflies.js b/examples/example/butterflies.js similarity index 95% rename from examples/butterflies.js rename to examples/example/butterflies.js index 6eaa4ba66d..336e128d83 100644 --- a/examples/butterflies.js +++ b/examples/example/butterflies.js @@ -82,9 +82,9 @@ function addButterfly() { damping: 0.00001, dimensions: dimensions, color: color, - animationURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx", + animationURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx", animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}", - modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx" + modelURL: "http://public.highfidelity.io/models/content/butterfly/butterfly.fbx" }; butterflies.push(Entities.addEntity(properties)); } diff --git a/examples/example/editModelExample.js b/examples/example/editModelExample.js index 5a4efc0746..f56edfdf3b 100644 --- a/examples/example/editModelExample.js +++ b/examples/example/editModelExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); var count = 0; var moveUntil = 2000; diff --git a/examples/flockingBirds.js b/examples/example/flockingBirds.js similarity index 100% rename from examples/flockingBirds.js rename to examples/example/flockingBirds.js diff --git a/examples/guidedTour.js b/examples/example/guidedTour.js similarity index 100% rename from examples/guidedTour.js rename to examples/example/guidedTour.js diff --git a/examples/example/overlaysExample.js b/examples/example/overlaysExample.js index 821f8a11d1..c72619a042 100644 --- a/examples/example/overlaysExample.js +++ b/examples/example/overlaysExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); // The "Swatches" example of this script will create 9 different image overlays, that use the color feature to // display different colors as color swatches. The overlays can be clicked on, to change the "selectedSwatch" variable diff --git a/examples/example/radio.js b/examples/example/radio.js index e8300c00b5..39409df377 100644 --- a/examples/example/radio.js +++ b/examples/example/radio.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); var modelURL = HIFI_PUBLIC_BUCKET + "models/entities/radio/Speakers.fbx"; var soundURL = HIFI_PUBLIC_BUCKET + "sounds/family.stereo.raw"; diff --git a/examples/example/spaceInvadersExample.js b/examples/example/spaceInvadersExample.js index 832efe7e75..6216c709c2 100644 --- a/examples/example/spaceInvadersExample.js +++ b/examples/example/spaceInvadersExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); var iteration = 0; @@ -59,7 +59,7 @@ var middleY = gameAt.y + (gameSize.y/2); var invaderSize = 0.4; var shipSize = 0.25; -var missileSize = 0.1; +var missileSize = 1.0; var myShip; var myShipProperties; @@ -101,7 +101,7 @@ var soundInMyHead = true; // models... var invaderModels = new Array(); invaderModels[0] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; @@ -141,7 +141,7 @@ function initializeMyShip() { damping: 0, dimensions: { x: shipSize * 2, y: shipSize * 2, z: shipSize * 2 }, color: { red: 0, green: 255, blue: 0 }, - modelURL: HIFI_PUBLIC_BUCKET + "meshes/myCannon16x16.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", lifetime: itemLifetimes }; myShip = Entities.addEntity(myShipProperties); @@ -360,7 +360,7 @@ function keyPressEvent(key) { myShipProperties.position.x = gameAt.x + gameSize.x; } moveShipTo(myShipProperties.position); - } else if (key.text == " ") { + } else if (key.text == "f") { fireMissile(); } else if (key.text == "q") { endGame(); diff --git a/examples/fountain.js b/examples/fountain.js deleted file mode 100644 index 0e6ab521f7..0000000000 --- a/examples/fountain.js +++ /dev/null @@ -1,77 +0,0 @@ -// -// fountain.js -// examples -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -function vLength(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 + "\n"); -} - -// Create a random vector with individual lengths between a,b -function randVector(a, b) { - var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) }; - return rval; -} - -function vMinus(a, b) { - var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z }; - return rval; -} - -function vPlus(a, b) { - var rval = { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z }; - return rval; -} - -function vCopy(a, b) { - a.x = b.x; - a.y = b.y; - a.z = b.z; - return; -} - -// Returns a vector which is fraction of the way between a and b -function vInterpolate(a, b, fraction) { - var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction }; - return rval; -} - -var position = { x: 5.0, y: 0.6, z: 5.0 }; -//Voxels.setVoxel(position.x, 0, position.z, 0.5, 0, 0, 255); - -var totalEntities = 0; -function makeFountain(deltaTime) { - if (Math.random() < 0.10) { - //print("Made entity!\n"); - var radius = (0.02 + (Math.random() * 0.05)); - var properties = { - type: "Sphere", - position: position, - dimensions: { x: radius, y: radius, z: radius}, - color: { red: 0, green: 0, blue: 128 }, - velocity: { x: (Math.random() * 1.0 - 0.5), - y: (1.0 + (Math.random() * 2.0)), - z: (Math.random() * 1.0 - 0.5) }, - gravity: { x: 0, y: -0.1, z: 0 }, - damping: 0.25, - lifetime: 1 - } - - Entities.addEntity(properties); - totalEntities++; - } - if (totalEntities > 100) { - Script.stop(); - } -} -// register the call back so it fires before each data send -Script.update.connect(makeFountain); \ No newline at end of file diff --git a/examples/grenadeLauncher.js b/examples/grenadeLauncher.js deleted file mode 100644 index b0f04fec9a..0000000000 --- a/examples/grenadeLauncher.js +++ /dev/null @@ -1,328 +0,0 @@ -// -// grenadeLauncher.js -// examples -// Created by Ben Arnold on 7/11/14. -// This is a modified version of gun.js by Brad Hefta-Gaub. -// -// Copyright 2013 High Fidelity, Inc. -// -// This is an example script that turns the hydra controllers and mouse into a entity gun. -// It reads the controller, watches for trigger pulls, and launches entities. -// When entities collide with voxels they blow big holes out of the voxels. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("libraries/globals.js"); - -function getRandomFloat(min, max) { - return Math.random() * (max - min) + min; -} - -var lastX = 0; -var lastY = 0; -var yawFromMouse = 0; -var pitchFromMouse = 0; -var isMouseDown = false; - -var BULLET_VELOCITY = 3.0; -var MIN_THROWER_DELAY = 1000; -var MAX_THROWER_DELAY = 1000; -var LEFT_BUTTON_1 = 1; -var LEFT_BUTTON_3 = 3; -var RELOAD_INTERVAL = 5; - -var showScore = false; - -// Load some sound to use for loading and firing -var fireSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/GUN-SHOT2.raw"); -var loadSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/Gun_Reload_Weapon22.raw"); -var impactSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guns/BulletImpact2.raw"); -var targetHitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/hit.raw"); -var targetLaunchSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Space%20Invaders/shoot.raw"); - -var gunModel = "http://public.highfidelity.io/models/attachments/HaloGun.fst"; - -var audioOptions { - volume: 0.9 -} - -var shotsFired = 0; - -var shotTime = new Date(); - -// initialize our triggers -var triggerPulled = new Array(); -var numberOfTriggers = Controller.getNumberOfTriggers(); -for (t = 0; t < numberOfTriggers; t++) { - triggerPulled[t] = false; -} - -var isLaunchButtonPressed = false; - -var score = 0; - -// Create a reticle image in center of screen -var screenSize = Controller.getViewportDimensions(); -var reticle = Overlays.addOverlay("image", { - x: screenSize.x / 2 - 16, - y: screenSize.y / 2 - 16, - width: 32, - height: 32, - imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png", - color: { red: 255, green: 255, blue: 255}, - alpha: 1 - }); - -if (showScore) { - var text = Overlays.addOverlay("text", { - x: screenSize.x / 2 - 100, - y: screenSize.y / 2 - 50, - width: 150, - height: 50, - color: { red: 0, green: 0, blue: 0}, - textColor: { red: 255, green: 0, blue: 0}, - topMargin: 4, - leftMargin: 4, - text: "Score: " + score - }); -} - -function printVector(string, vector) { - print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); -} - -function shootBullet(position, velocity) { - var BULLET_SIZE = 0.1; - var BULLET_GRAVITY = -3.0; - //Creates a grenade with a reasonable lifetime so that one is less likely to accidentally blow up - //far away voxels - Entities.addEntity( - { type: "Sphere", - position: position, - collisionsWillMove: true, - dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, - color: { red: 10, green: 10, blue: 10 }, - velocity: velocity, - gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, - lifetime: 10.0, - damping: 0 }); - - // Play firing sounds - audioOptions.position = position; - Audio.playSound(fireSound, audioOptions); - shotsFired++; - if ((shotsFired % RELOAD_INTERVAL) == 0) { - Audio.playSound(loadSound, audioOptions); - } -} - -function shootTarget() { - var TARGET_SIZE = 0.25; - var TARGET_GRAVITY = -0.6; - var TARGET_UP_VELOCITY = 3.0; - var TARGET_FWD_VELOCITY = 5.0; - var DISTANCE_TO_LAUNCH_FROM = 3.0; - var camera = Camera.getPosition(); - //printVector("camera", camera); - var targetDirection = Quat.angleAxis(getRandomFloat(-20.0, 20.0), { x:0, y:1, z:0 }); - targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection); - var forwardVector = Quat.getFront(targetDirection); - //printVector("forwardVector", forwardVector); - var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM)); - //printVector("newPosition", newPosition); - var velocity = Vec3.multiply(forwardVector, TARGET_FWD_VELOCITY); - velocity.y += TARGET_UP_VELOCITY; - //printVector("velocity", velocity); - - Entities.addEntity( - { type: "Sphere", - position: newPosition, - collisionsWillMove: true, - dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE }, - color: { red: 0, green: 200, blue: 200 }, - velocity: velocity, - gravity: { x: 0, y: TARGET_GRAVITY, z: 0 }, - lifetime: 1000.0, - damping: 0.0001 }); - - // Record start time - shotTime = new Date(); - - // Play target shoot sound - audioOptions.position = newPosition; - Audio.playSound(targetLaunchSound, audioOptions); -} - -function entityCollisionWithEntity(entity1, entity2, collision) { - score++; - if (showScore) { - Overlays.editOverlay(text, { text: "Score: " + score } ); - } - - // Record shot time - var endTime = new Date(); - var msecs = endTime.valueOf() - shotTime.valueOf(); - //print("hit, msecs = " + msecs); - //Vec3.print("penetration = ", collision.penetration); - //Vec3.print("contactPoint = ", collision.contactPoint); - Entities.deleteEntity(entity1); - Entities.deleteEntity(entity2); - // play the sound near the camera so the shooter can hear it - audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); - Audio.playSound(targetHitSound, audioOptions); -} - -function keyPressEvent(event) { - // if our tools are off, then don't do anything - if (event.text == "t") { - var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; - Script.setTimeout(shootTarget, time); - } else if (event.text == ".") { - shootFromMouse(); - } else if (event.text == "r") { - playLoadSound(); - } -} - -function playLoadSound() { - audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); - Audio.playSound(loadSound, audioOptions); -} - -//MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); -MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); - -// Give a bit of time to load before playing sound -Script.setTimeout(playLoadSound, 2000); - -function update(deltaTime) { - - // Check for mouseLook movement, update rotation - // rotate body yaw for yaw received from controller or mouse - var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } )); - MyAvatar.orientation = newOrientation; - yawFromMouse = 0; - - // apply pitch from controller or mouse - var newPitch = MyAvatar.headPitch + pitchFromMouse; - MyAvatar.headPitch = newPitch; - pitchFromMouse = 0; - - // Check hydra controller for launch button press - if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) { - isLaunchButtonPressed = true; - var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; - Script.setTimeout(shootTarget, time); - } else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) { - isLaunchButtonPressed = false; - - } - - // Check hydra controller for trigger press - - var numberOfTriggers = Controller.getNumberOfTriggers(); - var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); - var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; - - // this is expected for hydras - if (numberOfTriggers == 2 && controllersPerTrigger == 2) { - for (var t = 0; t < numberOfTriggers; t++) { - var shootABullet = false; - var triggerValue = Controller.getTriggerValue(t); - - if (triggerPulled[t]) { - // must release to at least 0.1 - if (triggerValue < 0.1) { - triggerPulled[t] = false; // unpulled - } - } else { - // must pull to at least 0.9 - if (triggerValue > 0.9) { - triggerPulled[t] = true; // pulled - shootABullet = true; - } - } - - if (shootABullet) { - - var palmController = t * controllersPerTrigger; - var palmPosition = Controller.getSpatialControlPosition(palmController); - - var fingerTipController = palmController + 1; - var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); - - var palmToFingerTipVector = - { x: (fingerTipPosition.x - palmPosition.x), - y: (fingerTipPosition.y - palmPosition.y), - z: (fingerTipPosition.z - palmPosition.z) }; - - // just off the front of the finger tip - var position = { x: fingerTipPosition.x + palmToFingerTipVector.x/2, - y: fingerTipPosition.y + palmToFingerTipVector.y/2, - z: fingerTipPosition.z + palmToFingerTipVector.z/2}; - - var linearVelocity = 25; - - var velocity = { x: palmToFingerTipVector.x * linearVelocity, - y: palmToFingerTipVector.y * linearVelocity, - z: palmToFingerTipVector.z * linearVelocity }; - - shootBullet(position, velocity); - } - } - } -} - -function mousePressEvent(event) { - isMouseDown = true; - lastX = event.x; - lastY = event.y; - //audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); - //Audio.playSound(loadSound, audioOptions); -} - -function shootFromMouse() { - var DISTANCE_FROM_CAMERA = 2.0; - var camera = Camera.getPosition(); - var forwardVector = Quat.getFront(Camera.getOrientation()); - var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA)); - var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY); - shootBullet(newPosition, velocity); -} - -function mouseReleaseEvent(event) { - // position - isMouseDown = false; -} - -function mouseMoveEvent(event) { - //Move the camera if LEFT_BUTTON_1 is pressed - if (Controller.isButtonPressed(LEFT_BUTTON_1)) { - var MOUSE_YAW_SCALE = -0.25; - var MOUSE_PITCH_SCALE = -12.5; - var FIXED_MOUSE_TIMESTEP = 0.016; - yawFromMouse += ((event.x - lastX) * MOUSE_YAW_SCALE * FIXED_MOUSE_TIMESTEP); - pitchFromMouse += ((event.y - lastY) * MOUSE_PITCH_SCALE * FIXED_MOUSE_TIMESTEP); - lastX = event.x; - lastY = event.y; - } -} - -function scriptEnding() { - Overlays.deleteOverlay(reticle); - Overlays.deleteOverlay(text); - MyAvatar.detachOne(gunModel); -} - -Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); -Script.scriptEnding.connect(scriptEnding); -Script.update.connect(update); -Controller.mousePressEvent.connect(mousePressEvent); -Controller.mouseReleaseEvent.connect(mouseReleaseEvent); -Controller.mouseMoveEvent.connect(mouseMoveEvent); -Controller.keyPressEvent.connect(keyPressEvent); - - - From fb68037b74fb36c2207ac5e8438a9b08cfa6991a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 15:51:39 -0800 Subject: [PATCH 21/52] more removal of immediate mode --- interface/src/ui/overlays/Circle3DOverlay.cpp | 202 ++++++++++-------- interface/src/ui/overlays/Circle3DOverlay.h | 3 +- 2 files changed, 109 insertions(+), 96 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index bc3e1c72aa..25bc8a0ddc 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -31,7 +31,8 @@ Circle3DOverlay::Circle3DOverlay() : _minorTickMarksLength(0.0f), _quadVerticesID(GeometryCache::UNKNOWN_ID), _lineVerticesID(GeometryCache::UNKNOWN_ID), - _ticksVerticesID(GeometryCache::UNKNOWN_ID), + _majorTicksVerticesID(GeometryCache::UNKNOWN_ID), + _minorTicksVerticesID(GeometryCache::UNKNOWN_ID), _lastStartAt(-1.0f), _lastEndAt(-1.0f), _lastOuterRadius(-1.0f), @@ -56,7 +57,8 @@ Circle3DOverlay::Circle3DOverlay(const Circle3DOverlay* circle3DOverlay) : _minorTickMarksColor(circle3DOverlay->_minorTickMarksColor), _quadVerticesID(GeometryCache::UNKNOWN_ID), _lineVerticesID(GeometryCache::UNKNOWN_ID), - _ticksVerticesID(GeometryCache::UNKNOWN_ID), + _majorTicksVerticesID(GeometryCache::UNKNOWN_ID), + _minorTicksVerticesID(GeometryCache::UNKNOWN_ID), _lastStartAt(-1.0f), _lastEndAt(-1.0f), _lastOuterRadius(-1.0f), @@ -78,7 +80,15 @@ void Circle3DOverlay::render(RenderArgs* args) { return; // do nothing if our alpha is 0, we're not visible } - bool geometryChanged = false; + // Create the circle in the coordinates origin + float outerRadius = getOuterRadius(); + float innerRadius = getInnerRadius(); // only used in solid case + float startAt = getStartAt(); + float endAt = getEndAt(); + + bool geometryChanged = (startAt != _lastStartAt || endAt != _lastEndAt || + innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius); + const float FULL_CIRCLE = 360.0f; const float SLICES = 180.0f; // The amount of segment to create the circle @@ -112,12 +122,6 @@ void Circle3DOverlay::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, 1.0f); - // Create the circle in the coordinates origin - float outerRadius = getOuterRadius(); - float innerRadius = getInnerRadius(); // only used in solid case - float startAt = getStartAt(); - float endAt = getEndAt(); - glLineWidth(_lineWidth); GeometryCache::SharedPointer geometryCache = DependencyManager::get(); @@ -128,12 +132,8 @@ void Circle3DOverlay::render(RenderArgs* args) { if (_quadVerticesID == GeometryCache::UNKNOWN_ID) { _quadVerticesID = geometryCache->allocateID(); } - //glBegin(GL_QUAD_STRIP); - if (startAt != _lastStartAt || endAt != _lastEndAt || - innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius) { - - geometryChanged = true; + if (geometryChanged) { QVector points; @@ -142,8 +142,6 @@ void Circle3DOverlay::render(RenderArgs* args) { glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - //glVertex2f(firstInnerPoint.x, firstInnerPoint.y); - //glVertex2f(firstOuterPoint.x, firstOuterPoint.y); points << firstInnerPoint << firstOuterPoint; while (angle < endAt) { @@ -151,9 +149,6 @@ void Circle3DOverlay::render(RenderArgs* args) { glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - //glVertex2f(thisOuterPoint.x, thisOuterPoint.y); - //glVertex2f(thisInnerPoint.x, thisInnerPoint.y); - points << thisOuterPoint << thisInnerPoint; angle += SLICE_ANGLE; @@ -165,9 +160,6 @@ void Circle3DOverlay::render(RenderArgs* args) { glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius); glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - //glVertex2f(lastOuterPoint.x, lastOuterPoint.y); - //glVertex2f(lastInnerPoint.x, lastInnerPoint.y); - points << lastOuterPoint << lastInnerPoint; geometryCache->updateVertices(_quadVerticesID, points); @@ -176,99 +168,119 @@ void Circle3DOverlay::render(RenderArgs* args) { geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); } else { - if (getIsDashedLine()) { - glBegin(GL_LINES); - } else { - glBegin(GL_LINE_STRIP); + if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { + _lineVerticesID = geometryCache->allocateID(); } - - float angle = startAt; - float angleInRadians = glm::radians(angle); - glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - glVertex2f(firstPoint.x, firstPoint.y); + if (geometryChanged) { + QVector points; + + float angle = startAt; + float angleInRadians = glm::radians(angle); + glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + points << firstPoint; - while (angle < endAt) { - angle += SLICE_ANGLE; - angleInRadians = glm::radians(angle); - glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - glVertex2f(thisPoint.x, thisPoint.y); - - if (getIsDashedLine()) { - angle += SLICE_ANGLE / 2.0f; // short gap + while (angle < endAt) { + angle += SLICE_ANGLE; angleInRadians = glm::radians(angle); - glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - glVertex2f(dashStartPoint.x, dashStartPoint.y); + glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + points << thisPoint; + + if (getIsDashedLine()) { + angle += SLICE_ANGLE / 2.0f; // short gap + angleInRadians = glm::radians(angle); + glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + points << dashStartPoint; + } } - } - // get the last slice portion.... - angle = endAt; - angleInRadians = glm::radians(angle); - glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); - glVertex2f(lastOuterPoint.x, lastOuterPoint.y); - glEnd(); + // get the last slice portion.... + angle = endAt; + angleInRadians = glm::radians(angle); + glm::vec2 lastPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); + points << lastPoint; + + geometryCache->updateVertices(_lineVerticesID, points); + } + + if (getIsDashedLine()) { + geometryCache->renderVertices(GL_LINES, _lineVerticesID); + } else { + geometryCache->renderVertices(GL_LINE_STRIP, _lineVerticesID); + } } // draw our tick marks // for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise // we just draw a line... if (getHasTickMarks()) { - glBegin(GL_LINES); - // draw our major tick marks - if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { - - xColor color = getMajorTickMarksColor(); - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - - float tickMarkAngle = getMajorTickMarksAngle(); - float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; - float angleInRadians = glm::radians(angle); - float tickMarkLength = getMajorTickMarksLength(); - float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; - float endRadius = startRadius + tickMarkLength; - - while (angle <= endAt) { - angleInRadians = glm::radians(angle); - - glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); - glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); - - glVertex2f(thisPointA.x, thisPointA.y); - glVertex2f(thisPointB.x, thisPointB.y); - - angle += tickMarkAngle; - } + if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) { + _majorTicksVerticesID = geometryCache->allocateID(); + } + if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) { + _minorTicksVerticesID = geometryCache->allocateID(); } - // draw our minor tick marks - if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { - - xColor color = getMinorTickMarksColor(); - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - - float tickMarkAngle = getMinorTickMarksAngle(); - float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; - float angleInRadians = glm::radians(angle); - float tickMarkLength = getMinorTickMarksLength(); - float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; - float endRadius = startRadius + tickMarkLength; + if (geometryChanged) { + QVector majorPoints; + QVector minorPoints; - while (angle <= endAt) { - angleInRadians = glm::radians(angle); - - glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); - glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); - - glVertex2f(thisPointA.x, thisPointA.y); - glVertex2f(thisPointB.x, thisPointB.y); + // draw our major tick marks + if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) { - angle += tickMarkAngle; + float tickMarkAngle = getMajorTickMarksAngle(); + float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; + float angleInRadians = glm::radians(angle); + float tickMarkLength = getMajorTickMarksLength(); + float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; + float endRadius = startRadius + tickMarkLength; + + while (angle <= endAt) { + angleInRadians = glm::radians(angle); + + glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); + glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); + + majorPoints << thisPointA << thisPointB; + + angle += tickMarkAngle; + } } + + // draw our minor tick marks + if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) { + + float tickMarkAngle = getMinorTickMarksAngle(); + float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle; + float angleInRadians = glm::radians(angle); + float tickMarkLength = getMinorTickMarksLength(); + float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius; + float endRadius = startRadius + tickMarkLength; + + while (angle <= endAt) { + angleInRadians = glm::radians(angle); + + glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius); + glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius); + + minorPoints << thisPointA << thisPointB; + + angle += tickMarkAngle; + } + } + + geometryCache->updateVertices(_majorTicksVerticesID, majorPoints); + geometryCache->updateVertices(_minorTicksVerticesID, minorPoints); } - glEnd(); + xColor majorColor = getMajorTickMarksColor(); + glColor4f(majorColor.red / MAX_COLOR, majorColor.green / MAX_COLOR, majorColor.blue / MAX_COLOR, alpha); + geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID); + + xColor minorColor = getMinorTickMarksColor(); + glColor4f(minorColor.red / MAX_COLOR, minorColor.green / MAX_COLOR, minorColor.blue / MAX_COLOR, alpha); + geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID); } diff --git a/interface/src/ui/overlays/Circle3DOverlay.h b/interface/src/ui/overlays/Circle3DOverlay.h index f9cd5ebbf2..10b7a5dbfa 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.h +++ b/interface/src/ui/overlays/Circle3DOverlay.h @@ -67,7 +67,8 @@ protected: int _quadVerticesID; int _lineVerticesID; - int _ticksVerticesID; + int _majorTicksVerticesID; + int _minorTicksVerticesID; float _lastStartAt; float _lastEndAt; From 1bc91e7d299f3ca300d501f4cd522e21326096ad Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 6 Jan 2015 16:01:06 -0800 Subject: [PATCH 22/52] removed renderTriangleProxies --- libraries/render-utils/src/Model.cpp | 53 ---------------------------- libraries/render-utils/src/Model.h | 1 - 2 files changed, 54 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 3d26db2c4f..46fc6a6e4d 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -447,59 +447,6 @@ void Model::setJointStates(QVector states) { _boundingRadius = radius; } -bool Model::renderTriangleProxies() { - if (!isActive()) { - return false; - } - if (_calculatedMeshTrianglesValid) { - int color = 0; - foreach (const QVector& meshTriangles, _calculatedMeshTriangles) { - switch(color) { - case 0: glColor3ub( 0, 0, 255); break; - case 1: glColor3ub( 0, 255, 0); break; - case 2: glColor3ub( 0, 255, 255); break; - case 3: glColor3ub(255, 0, 0); break; - case 4: glColor3ub(255, 0, 255); break; - case 5: glColor3ub(255, 255, 0); break; - case 6: glColor3ub( 0, 0, 128); break; - case 7: glColor3ub( 0, 128, 0); break; - case 8: glColor3ub( 0, 128, 128); break; - case 9: glColor3ub(128, 0, 0); break; - case 10: glColor3ub(128, 0, 128); break; - case 11: glColor3ub(128, 128, 0); break; - case 12: glColor3ub(128, 128, 255); break; - case 13: glColor3ub(128, 255, 128); break; - case 14: glColor3ub(128, 255, 255); break; - case 15: glColor3ub(255, 128, 128); break; - case 16: glColor3ub(255, 128, 255); break; - case 17: glColor3ub(255, 255, 128); break; - default: glColor3ub(255,255, 255); break; - } - - if (_calculatedMeshBoxes.size() > color) { - const AABox& box = _calculatedMeshBoxes[color]; - glm::vec3 center = box.calcCenter(); - glm::vec3 dimensions = box.getDimensions(); - glPushMatrix(); - glTranslatef(center.x, center.y, center.z); - glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireCube(1.0f); - glPopMatrix(); - } - - glBegin(GL_TRIANGLES); - foreach (const Triangle& triangle, meshTriangles) { - glVertex3f( triangle.v0.x, triangle.v0.y, triangle.v0.z); - glVertex3f( triangle.v1.x, triangle.v1.y, triangle.v1.z); - glVertex3f( triangle.v2.x, triangle.v2.y, triangle.v2.z); - } - glEnd(); - color++; - } - } - return _calculatedMeshTrianglesValid; -} - bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, QString& extraInfo, bool pickAgainstTriangles) { diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index 52b0a42211..83ceab109f 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -94,7 +94,6 @@ public: enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE }; bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL); - bool renderTriangleProxies(); // Scene rendering support static void startScene(RenderArgs::RenderSide renderSide); From 29839df9fe86902bee1a83ab832905605e057ae8 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 6 Jan 2015 16:35:30 -0800 Subject: [PATCH 23/52] Restored addReverb default arg --- interface/src/Audio.cpp | 6 +++--- interface/src/Audio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 045a3d42fb..d9d0972c84 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -507,9 +507,9 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) { } } -void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat) { +void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) { float wetFraction = DB_CO(_reverbOptions->getWetLevel()); - float dryFraction = (!_shouldEchoLocally) ? 0.0f : (1.0f - wetFraction); + float dryFraction = (noEcho) ? 0.0f : (1.0f - wetFraction); float lValue,rValue; for (int sample = 0; sample < numSamples; sample += audioFormat.channelCount()) { @@ -568,7 +568,7 @@ void Audio::handleLocalEchoAndReverb(QByteArray& inputByteArray) { int16_t* loopbackSamples = reinterpret_cast(loopBackByteArray.data()); int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t); updateGverbOptions(); - addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat); + addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat, !_shouldEchoLocally); } if (_loopbackOutputDevice) { diff --git a/interface/src/Audio.h b/interface/src/Audio.h index be0e86e0af..e4c02c2827 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -208,7 +208,7 @@ private: // Adds Reverb void initGverb(); void updateGverbOptions(); - void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format); + void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false); void handleLocalEchoAndReverb(QByteArray& inputByteArray); From 0a1a64b7e670dc0572daff4ae2eaabd35558c15f Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 6 Jan 2015 17:04:42 -0800 Subject: [PATCH 24/52] Script updates and fixes to highfidelity-public Script updates and fixes to highfidelity-public --- examples/editEntities.js | 4 +- examples/editModels.js | 4 +- examples/{ => example}/metavoxels.js | 0 .../{ => example}/textInputOverlayExample.js | 4 +- examples/libraries/entitySelectionTool.js | 22 ++-- examples/libraries/unitTest.js | 104 ++++++++++++++++++ examples/playSound.js | 27 ----- .../diagnostics/XMLHttpRequest.js} | 2 +- .../diagnostics}/inWorldTestTone.js | 2 +- .../diagnostics}/playSoundLoop.js | 2 +- .../diagnostics}/playSoundOrbit.js | 6 +- interface/external/rtmidi/readme.txt | 2 +- 12 files changed, 126 insertions(+), 53 deletions(-) rename examples/{ => example}/metavoxels.js (100%) rename examples/{ => example}/textInputOverlayExample.js (97%) create mode 100644 examples/libraries/unitTest.js delete mode 100644 examples/playSound.js rename examples/{testXMLHttpRequest.js => utilities/diagnostics/XMLHttpRequest.js} (99%) rename examples/{ => utilities/diagnostics}/inWorldTestTone.js (95%) rename examples/{ => utilities/diagnostics}/playSoundLoop.js (97%) rename examples/{ => utilities/diagnostics}/playSoundOrbit.js (88%) diff --git a/examples/editEntities.js b/examples/editEntities.js index 632fed088c..709014bdb8 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -77,7 +77,6 @@ var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", - HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -192,8 +191,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, diff --git a/examples/editModels.js b/examples/editModels.js index 8ec099650a..7cb911b490 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -56,7 +56,6 @@ var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", - HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -1215,8 +1214,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, diff --git a/examples/metavoxels.js b/examples/example/metavoxels.js similarity index 100% rename from examples/metavoxels.js rename to examples/example/metavoxels.js diff --git a/examples/textInputOverlayExample.js b/examples/example/textInputOverlayExample.js similarity index 97% rename from examples/textInputOverlayExample.js rename to examples/example/textInputOverlayExample.js index 258e07fcc8..d212a547cf 100644 --- a/examples/textInputOverlayExample.js +++ b/examples/example/textInputOverlayExample.js @@ -58,7 +58,7 @@ var button1 = Overlays.addOverlay("image", { // green button width: 40, height: 35, subImage: { x: 0, y: 0, width: 39, height: 35 }, - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + imageURL: "https://public.highfidelity.io/images/thumb.png", color: readyColor, visible: true }); @@ -69,7 +69,7 @@ var button2 = Overlays.addOverlay("image", { // red button width: 40, height: 35, subImage: { x: 0, y: 0, width: 39, height: 35 }, - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + imageURL: "https://public.highfidelity.io/images/thumb.png", color: { red: 250, green: 2, blue: 2}, visible: true, }); diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 8aff9c32ed..2b83d7740d 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -590,7 +590,7 @@ SelectionDisplay = (function () { }); var yawHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -603,7 +603,7 @@ SelectionDisplay = (function () { var pitchHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -616,7 +616,7 @@ SelectionDisplay = (function () { var rollHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -835,8 +835,8 @@ SelectionDisplay = (function () { rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far }; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" }); } else { @@ -867,8 +867,8 @@ SelectionDisplay = (function () { pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } else { @@ -899,8 +899,8 @@ SelectionDisplay = (function () { pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } else { @@ -928,8 +928,8 @@ SelectionDisplay = (function () { rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near }; pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } diff --git a/examples/libraries/unitTest.js b/examples/libraries/unitTest.js new file mode 100644 index 0000000000..530528e6a3 --- /dev/null +++ b/examples/libraries/unitTest.js @@ -0,0 +1,104 @@ +// +// Unittest.js +// examples +// +// Created by Ryan Huffman on 5/4/14 +// Copyright 2014 High Fidelity, Inc. +// +// This provides very basic unit testing functionality. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +test = function(name, func) { + print("Running test: " + name); + + var unitTest = new UnitTest(name, func); + + try { + unitTest.run(); + print(" Success: " + unitTest.numAssertions + " assertions passed"); + } catch (error) { + print(" Failure: " + error.name + " " + error.message); + } +}; + +AssertionException = function(expected, actual, message) { + print("Creating exception"); + this.message = message + "\n: " + actual + " != " + expected; + this.name = 'AssertionException'; +}; + +UnthrownException = function(message) { + print("Creating exception"); + this.message = message + "\n"; + this.name = 'UnthrownException'; +}; + +UnitTest = function(name, func) { + this.numAssertions = 0; + this.func = func; +}; + +UnitTest.prototype.run = function() { + this.func(); +}; + +UnitTest.prototype.assertNotEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected == actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected != actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertContains = function (expected, actual, message) { + this.numAssertions++; + if (actual.indexOf(expected) == -1) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertHasProperty = function(property, actual, message) { + this.numAssertions++; + if (actual[property] === undefined) { + throw new AssertionException(property, actual, message); + } +}; + +UnitTest.prototype.assertNull = function(value, message) { + this.numAssertions++; + if (value !== null) { + throw new AssertionException(value, null, message); + } +} + +UnitTest.prototype.arrayEqual = function(array1, array2, message) { + this.numAssertions++; + if (array1.length !== array2.length) { + throw new AssertionException(array1.length , array2.length , message); + } + for (var i = 0; i < array1.length; ++i) { + if (array1[i] !== array2[i]) { + throw new AssertionException(array1[i], array2[i], i + " " + message); + } + } +} + +UnitTest.prototype.raises = function(func, message) { + this.numAssertions++; + try { + func(); + } catch (error) { + return; + } + + throw new UnthrownException(message); +} \ No newline at end of file diff --git a/examples/playSound.js b/examples/playSound.js deleted file mode 100644 index bc21204665..0000000000 --- a/examples/playSound.js +++ /dev/null @@ -1,27 +0,0 @@ -// -// playSound.js -// examples -// -// Copyright 2014 High Fidelity, Inc. -// Plays a sample audio file at the avatar's current location -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - -Script.include("libraries/globals.js"); - -// First, load a sample sound from a URL -var bird = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); - -function maybePlaySound(deltaTime) { - if (Math.random() < 0.01) { - // Set the location and other info for the sound to play - Audio.playSound(bird, { - position: MyAvatar.position, - volume: 0.5 - }); - } -} - -// Connect a call back that happens every frame -Script.update.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/testXMLHttpRequest.js b/examples/utilities/diagnostics/XMLHttpRequest.js similarity index 99% rename from examples/testXMLHttpRequest.js rename to examples/utilities/diagnostics/XMLHttpRequest.js index 79d2842464..fb25cb4fad 100644 --- a/examples/testXMLHttpRequest.js +++ b/examples/utilities/diagnostics/XMLHttpRequest.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("Test.js"); +Script.include("../../libraries/unitTest.js"); test("Test default request values", function(finished) { var req = new XMLHttpRequest(); diff --git a/examples/inWorldTestTone.js b/examples/utilities/diagnostics/inWorldTestTone.js similarity index 95% rename from examples/inWorldTestTone.js rename to examples/utilities/diagnostics/inWorldTestTone.js index 660965569c..1fc3cbc2c8 100644 --- a/examples/inWorldTestTone.js +++ b/examples/utilities/diagnostics/inWorldTestTone.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); diff --git a/examples/playSoundLoop.js b/examples/utilities/diagnostics/playSoundLoop.js similarity index 97% rename from examples/playSoundLoop.js rename to examples/utilities/diagnostics/playSoundLoop.js index f7116cb615..b9d35141d1 100644 --- a/examples/playSoundLoop.js +++ b/examples/utilities/diagnostics/playSoundLoop.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); // A few sample files you may want to try: diff --git a/examples/playSoundOrbit.js b/examples/utilities/diagnostics/playSoundOrbit.js similarity index 88% rename from examples/playSoundOrbit.js rename to examples/utilities/diagnostics/playSoundOrbit.js index 16ba5e52af..d9885b7f34 100644 --- a/examples/playSoundOrbit.js +++ b/examples/utilities/diagnostics/playSoundOrbit.js @@ -9,9 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); -var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); +var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); var currentTime = 1.570079; // pi/2 var deltaTime = 0.05; @@ -38,6 +38,6 @@ function playSound() { }); } -Script.setInterval(playSound, 250); +Script.setInterval(playSound, 850); diff --git a/interface/external/rtmidi/readme.txt b/interface/external/rtmidi/readme.txt index d0480fce4a..3b9d6603a9 100644 --- a/interface/external/rtmidi/readme.txt +++ b/interface/external/rtmidi/readme.txt @@ -3,7 +3,7 @@ Instructions for adding the RtMidi library to Interface Stephen Birarda, June 30, 2014 1. Download the RtMidi tarball from High Fidelity S3. - http://highfidelity-public.s3.amazonaws.com/dependencies/rtmidi-2.1.0.tar.gz + http://public.highfidelity.io/dependencies/rtmidi-2.1.0.tar.gz 2. Copy RtMidi.h to externals/rtmidi/include. From 68a9d80ba3636de1605c693d22c2d30b94c04ac6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 6 Jan 2015 18:14:40 -0800 Subject: [PATCH 25/52] Update setting drawOnHUD and update to write lock for editOverlay --- interface/src/ui/overlays/Base3DOverlay.cpp | 7 --- interface/src/ui/overlays/Base3DOverlay.h | 2 +- interface/src/ui/overlays/Overlays.cpp | 54 ++++++++++----------- interface/src/ui/overlays/Overlays.h | 3 -- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 12e593a1d0..abfe35d31b 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -48,13 +48,6 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) : Base3DOverlay::~Base3DOverlay() { } -void Base3DOverlay::setDrawOnHUD(bool value) { - if (_drawOnHUD != value) { - _drawOnHUD = value; - Application::getInstance()->getOverlays().overlayDrawOnChanged(this); - } -} - void Base3DOverlay::setProperties(const QScriptValue& properties) { Overlay::setProperties(properties); diff --git a/interface/src/ui/overlays/Base3DOverlay.h b/interface/src/ui/overlays/Base3DOverlay.h index 0e10a5f63b..015b59d702 100644 --- a/interface/src/ui/overlays/Base3DOverlay.h +++ b/interface/src/ui/overlays/Base3DOverlay.h @@ -47,7 +47,7 @@ public: void setRotation(const glm::quat& value) { _rotation = value; } void setIgnoreRayIntersection(bool value) { _ignoreRayIntersection = value; } void setDrawInFront(bool value) { _drawInFront = value; } - void setDrawOnHUD(bool value); + void setDrawOnHUD(bool value) { _drawOnHUD = value; } virtual void setProperties(const QScriptValue& properties); virtual QScriptValue getProperty(const QString& property); diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index a9bd004576..8f9f54c591 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -224,17 +224,36 @@ unsigned int Overlays::cloneOverlay(unsigned int id) { } bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) { + QWriteLocker lock(&_lock); Overlay* thisOverlay = NULL; - { - QReadLocker lock(&_lock); - if (_overlaysHUD.contains(id)) { - thisOverlay = _overlaysHUD[id]; - } else if (_overlaysWorld.contains(id)) { - thisOverlay = _overlaysWorld[id]; - } + + if (_overlaysHUD.contains(id)) { + thisOverlay = _overlaysHUD[id]; + } else if (_overlaysWorld.contains(id)) { + thisOverlay = _overlaysWorld[id]; } + if (thisOverlay) { - thisOverlay->setProperties(properties); + if (thisOverlay->is3D()) { + Base3DOverlay* overlay3D = static_cast(thisOverlay); + + bool oldDrawOnHUD = overlay3D->getDrawOnHUD(); + thisOverlay->setProperties(properties); + bool drawOnHUD = overlay3D->getDrawOnHUD(); + + if (drawOnHUD != oldDrawOnHUD) { + if (drawOnHUD) { + _overlaysWorld.remove(id); + _overlaysHUD[id] = thisOverlay; + } else { + _overlaysHUD.remove(id); + _overlaysWorld[id] = thisOverlay; + } + } + } else { + thisOverlay->setProperties(properties); + } + return true; } return false; @@ -450,25 +469,6 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R value.extraInfo = object.property("extraInfo").toVariant().toString(); } -void Overlays::overlayDrawOnChanged(Base3DOverlay* overlay) { - QWriteLocker lock(&_lock); - if (overlay->getDrawOnHUD()) { - for (unsigned int id : _overlaysWorld.keys()) { - if (_overlaysWorld[id] == overlay) { - _overlaysWorld.remove(id); - _overlaysHUD[id] = overlay; - } - } - } else { - for (unsigned int id : _overlaysHUD.keys()) { - if (_overlaysHUD[id] == overlay) { - _overlaysHUD.remove(id); - _overlaysWorld[id] = overlay; - } - } - } -} - bool Overlays::isLoaded(unsigned int id) { QReadLocker lock(&_lock); Overlay* thisOverlay = NULL; diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index d3030b0ac1..94ac6f98bb 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -82,9 +82,6 @@ public slots: /// returns details about the closest 3D Overlay hit by the pick ray RayToOverlayIntersectionResult findRayIntersection(const PickRay& ray); - - // called by Base3DOverlay when drawOnHUD changes - void overlayDrawOnChanged(Base3DOverlay* overlay); /// returns whether the overlay's assets are loaded or not bool isLoaded(unsigned int id); From 816e369c08641a189bad79452d4773650184662b Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 6 Jan 2015 22:32:45 -0800 Subject: [PATCH 26/52] More Script updates More Script updates --- .../botProceduralWayPoints.js | 0 .../{example => acScripts}/bot_procedural.js | 2 +- .../bot_randomExpression.js | 0 .../{ => acScripts}/proceduralAnimationAPI.js | 0 examples/avatarCollision.js | 72 ----- .../{ => controllers/hydra}/laserPointer.js | 0 examples/{ => controllers/hydra}/toyball.js | 2 +- examples/controllers/leap/laserPointer.js | 93 ++++++ examples/example/{ => audio}/audioBall.js | 2 +- .../example/{ => audio}/audioDeviceExample.js | 0 .../example/{ => audio}/audioMuteExample.js | 0 examples/example/{ => audio}/audioReverbOn.js | 0 examples/example/{ => audio}/birdSongs.js | 0 examples/example/{ => audio}/radio.js | 0 examples/{ => example/audio}/speechControl.js | 0 .../{ => avatarcontrol}/cameraExample.js | 0 .../{ => avatarcontrol}/controllerExample.js | 0 .../example/{ => avatarcontrol}/guidedTour.js | 0 .../{ => avatarcontrol}/hideAvatarExample.js | 2 +- .../{ => avatarcontrol}/lookAtExample.js | 8 +- .../multipleCursorsExample.js | 0 .../{ => avatarcontrol}/multitouchExample.js | 0 examples/example/bot.js | 233 -------------- ...ZZZ-MOVE-TO_DOCS-animationStateExample.js} | 0 .../{ => entities}/animatedModelExample.js | 13 +- .../example/{ => entities}/butterflies.js | 0 .../{ => entities}/collidingEntities.js | 4 +- .../{ => entities}/editEntityExample.js | 9 +- .../{ => entities}/editModelExample.js | 22 +- .../{ => entities}/entityModelExample.js | 20 +- .../{ => entities}/findEntitiesExample.js | 0 .../example/{ => entities}/flockingBirds.js | 2 +- .../example/{ => entities}/lightExample.js | 2 +- .../rideAlongWithAnEntityExample.js | 0 .../{ => entities}/spotlightExample.js | 0 .../example/{ => games}/cleanupChessboards.js | 0 .../{ => games}/clonedOverlaysExample.js | 4 +- examples/example/{ => games}/playChess.js | 0 .../{ => games}/spaceInvadersExample.js | 10 +- examples/example/globalCollisionsExample.js | 8 - examples/example/localVoxelsExample.js | 63 ---- .../example/{ => metavoxels}/metavoxels.js | 0 .../{ => misc}/globalServicesExample.js | 0 .../example/{ => scripts}/includeExample.js | 4 +- .../scripts}/loadScriptFromMessage.js | 0 .../example/{ => scripts}/locationExample.js | 0 .../example/{ => scripts}/rayPickExample.js | 0 .../example/{ => scripts}/settingsExample.js | 2 +- .../{ => scripts}/streetAreaExample.js | 0 examples/{ => example/scripts}/timer.js | 0 examples/example/{ => ui}/dialogExample.js | 0 .../example/{ => ui}/fileBrowserExample.js | 0 examples/example/{ => ui}/menuExample.js | 0 examples/example/{ => ui}/overlaysExample.js | 2 +- .../{ => ui}/textInputOverlayExample.js | 0 examples/example/{ => ui}/windowExample.js | 0 examples/locationsMenu.js | 304 ------------------ examples/sit.js | 2 +- examples/testModelOverlaySubMeshes.js | 88 ----- examples/twoFallingEntities.js | 25 -- .../diagnostics}/orbitingSound.js | 0 .../utilities/diagnostics/playSoundOrbit.js | 43 --- .../diagnostics}/playSoundWave.js | 0 .../diagnostics}/typedArraysUnitTest.js | 2 +- .../record/recorder.js} | 0 examples/{ => utilities/tools}/crazylegs.js | 2 + examples/{ => utilities/tools}/currentAPI.js | 0 .../tools}/developerMenuItems.js | 0 68 files changed, 151 insertions(+), 894 deletions(-) rename examples/{example => acScripts}/botProceduralWayPoints.js (100%) rename examples/{example => acScripts}/bot_procedural.js (99%) rename examples/{example => acScripts}/bot_randomExpression.js (100%) rename examples/{ => acScripts}/proceduralAnimationAPI.js (100%) delete mode 100644 examples/avatarCollision.js rename examples/{ => controllers/hydra}/laserPointer.js (100%) rename examples/{ => controllers/hydra}/toyball.js (99%) create mode 100644 examples/controllers/leap/laserPointer.js rename examples/example/{ => audio}/audioBall.js (98%) rename examples/example/{ => audio}/audioDeviceExample.js (100%) rename examples/example/{ => audio}/audioMuteExample.js (100%) rename examples/example/{ => audio}/audioReverbOn.js (100%) rename examples/example/{ => audio}/birdSongs.js (100%) rename examples/example/{ => audio}/radio.js (100%) rename examples/{ => example/audio}/speechControl.js (100%) rename examples/example/{ => avatarcontrol}/cameraExample.js (100%) rename examples/example/{ => avatarcontrol}/controllerExample.js (100%) rename examples/example/{ => avatarcontrol}/guidedTour.js (100%) rename examples/example/{ => avatarcontrol}/hideAvatarExample.js (96%) rename examples/example/{ => avatarcontrol}/lookAtExample.js (89%) rename examples/example/{ => avatarcontrol}/multipleCursorsExample.js (100%) rename examples/example/{ => avatarcontrol}/multitouchExample.js (100%) delete mode 100644 examples/example/bot.js rename examples/example/{animationStateExample.js => entities/ZZZ-MOVE-TO_DOCS-animationStateExample.js} (100%) rename examples/example/{ => entities}/animatedModelExample.js (91%) rename examples/example/{ => entities}/butterflies.js (100%) rename examples/example/{ => entities}/collidingEntities.js (96%) rename examples/example/{ => entities}/editEntityExample.js (91%) rename examples/example/{ => entities}/editModelExample.js (78%) rename examples/example/{ => entities}/entityModelExample.js (75%) rename examples/example/{ => entities}/findEntitiesExample.js (100%) rename examples/example/{ => entities}/flockingBirds.js (99%) rename examples/example/{ => entities}/lightExample.js (98%) rename examples/example/{ => entities}/rideAlongWithAnEntityExample.js (100%) rename examples/example/{ => entities}/spotlightExample.js (100%) rename examples/example/{ => games}/cleanupChessboards.js (100%) rename examples/example/{ => games}/clonedOverlaysExample.js (97%) rename examples/example/{ => games}/playChess.js (100%) rename examples/example/{ => games}/spaceInvadersExample.js (97%) delete mode 100644 examples/example/localVoxelsExample.js rename examples/example/{ => metavoxels}/metavoxels.js (100%) rename examples/example/{ => misc}/globalServicesExample.js (100%) rename examples/example/{ => scripts}/includeExample.js (84%) rename examples/{ => example/scripts}/loadScriptFromMessage.js (100%) rename examples/example/{ => scripts}/locationExample.js (100%) rename examples/example/{ => scripts}/rayPickExample.js (100%) rename examples/example/{ => scripts}/settingsExample.js (96%) rename examples/example/{ => scripts}/streetAreaExample.js (100%) rename examples/{ => example/scripts}/timer.js (100%) rename examples/example/{ => ui}/dialogExample.js (100%) rename examples/example/{ => ui}/fileBrowserExample.js (100%) rename examples/example/{ => ui}/menuExample.js (100%) rename examples/example/{ => ui}/overlaysExample.js (99%) rename examples/example/{ => ui}/textInputOverlayExample.js (100%) rename examples/example/{ => ui}/windowExample.js (100%) delete mode 100644 examples/locationsMenu.js delete mode 100644 examples/testModelOverlaySubMeshes.js delete mode 100644 examples/twoFallingEntities.js rename examples/{ => utilities/diagnostics}/orbitingSound.js (100%) delete mode 100644 examples/utilities/diagnostics/playSoundOrbit.js rename examples/{ => utilities/diagnostics}/playSoundWave.js (100%) rename examples/{ => utilities/diagnostics}/typedArraysUnitTest.js (99%) rename examples/{Recorder.js => utilities/record/recorder.js} (100%) rename examples/{ => utilities/tools}/crazylegs.js (93%) rename examples/{ => utilities/tools}/currentAPI.js (100%) rename examples/{ => utilities/tools}/developerMenuItems.js (100%) diff --git a/examples/example/botProceduralWayPoints.js b/examples/acScripts/botProceduralWayPoints.js similarity index 100% rename from examples/example/botProceduralWayPoints.js rename to examples/acScripts/botProceduralWayPoints.js diff --git a/examples/example/bot_procedural.js b/examples/acScripts/bot_procedural.js similarity index 99% rename from examples/example/bot_procedural.js rename to examples/acScripts/bot_procedural.js index 5ab867e150..8b96ed36c2 100644 --- a/examples/example/bot_procedural.js +++ b/examples/acScripts/bot_procedural.js @@ -12,7 +12,7 @@ //For procedural walk animation Script.include("../libraries/globals.js"); -Script.include(HIFI_PUBLIC_BUCKET + "scripts/proceduralAnimationAPI.js"); +Script.include("proceduralAnimationAPI.js"); var procAnimAPI = new ProcAnimAPI(); diff --git a/examples/example/bot_randomExpression.js b/examples/acScripts/bot_randomExpression.js similarity index 100% rename from examples/example/bot_randomExpression.js rename to examples/acScripts/bot_randomExpression.js diff --git a/examples/proceduralAnimationAPI.js b/examples/acScripts/proceduralAnimationAPI.js similarity index 100% rename from examples/proceduralAnimationAPI.js rename to examples/acScripts/proceduralAnimationAPI.js diff --git a/examples/avatarCollision.js b/examples/avatarCollision.js deleted file mode 100644 index ce13daa50d..0000000000 --- a/examples/avatarCollision.js +++ /dev/null @@ -1,72 +0,0 @@ -// -// avatarCollision.js -// examples -// -// Created by Andrew Meadows on 2014-04-09 -// Copyright 2014 High Fidelity, Inc. -// -// Play a sound on collisions with your avatar -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("libraries/globals.js"); - -var SOUND_TRIGGER_CLEAR = 1000; // milliseconds -var SOUND_TRIGGER_DELAY = 200; // milliseconds -var soundExpiry = 0; -var DateObj = new Date(); - -var audioOptions = { - volume: 0.5, - position: { x: 0, y: 0, z: 0 } -} - -var hitSounds = new Array(); -hitSounds[0] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit1.raw"); -hitSounds[1] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit2.raw"); -hitSounds[2] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit3.raw"); -hitSounds[3] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit4.raw"); -hitSounds[4] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit5.raw"); -hitSounds[5] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit6.raw"); -hitSounds[6] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit7.raw"); -hitSounds[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit8.raw"); -hitSounds[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit9.raw"); -hitSounds[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit10.raw"); -hitSounds[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit11.raw"); -hitSounds[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit12.raw"); -hitSounds[12] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit13.raw"); -hitSounds[13] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit14.raw"); -hitSounds[14] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit15.raw"); -hitSounds[15] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit16.raw"); -hitSounds[16] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit17.raw"); -hitSounds[17] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit18.raw"); -hitSounds[18] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit19.raw"); -hitSounds[19] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit20.raw"); -hitSounds[20] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit21.raw"); -hitSounds[21] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-hitsandslaps/Hit22.raw"); - -function playHitSound(mySessionID, theirSessionID, collision) { - var now = new Date(); - var msec = now.getTime(); - if (msec > soundExpiry) { - // this is a new contact --> play a new sound - var soundIndex = Math.floor((Math.random() * hitSounds.length) % hitSounds.length); - audioOptions.position = collision.contactPoint; - Audio.playSound(hitSounds[soundIndex], audioOptions); - - // bump the expiry - soundExpiry = msec + SOUND_TRIGGER_CLEAR; - - // log the collision info - Uuid.print("my sessionID = ", mySessionID); - Uuid.print(" their sessionID = ", theirSessionID); - Vec3.print(" penetration = ", collision.penetration); - Vec3.print(" contactPoint = ", collision.contactPoint); - } else { - // this is a recurring contact --> continue to delay sound trigger - soundExpiry = msec + SOUND_TRIGGER_DELAY; - } -} -MyAvatar.collisionWithAvatar.connect(playHitSound); diff --git a/examples/laserPointer.js b/examples/controllers/hydra/laserPointer.js similarity index 100% rename from examples/laserPointer.js rename to examples/controllers/hydra/laserPointer.js diff --git a/examples/toyball.js b/examples/controllers/hydra/toyball.js similarity index 99% rename from examples/toyball.js rename to examples/controllers/hydra/toyball.js index 2cda1fa82a..4dc65703b7 100644 --- a/examples/toyball.js +++ b/examples/controllers/hydra/toyball.js @@ -15,7 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); // maybe we should make these constants... var LEFT_PALM = 0; diff --git a/examples/controllers/leap/laserPointer.js b/examples/controllers/leap/laserPointer.js new file mode 100644 index 0000000000..156e9ba298 --- /dev/null +++ b/examples/controllers/leap/laserPointer.js @@ -0,0 +1,93 @@ +// +// laserPointer.js +// examples +// +// Created by Clément Brisset on 7/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// If using Hydra controllers, pulling the triggers makes laser pointers emanate from the respective hands. +// If using a Leap Motion or similar to control your avatar's hands and fingers, pointing with your index fingers makes +// laser pointers emanate from the respective index fingers. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var laserPointer = (function () { + + var NUM_FINGERs = 4, // Excluding thumb + fingers = [ + [ "LeftHandIndex", "LeftHandMiddle", "LeftHandRing", "LeftHandPinky" ], + [ "RightHandIndex", "RightHandMiddle", "RightHandRing", "RightHandPinky" ] + ]; + + function isHandPointing(hand) { + var MINIMUM_TRIGGER_PULL = 0.9; + return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL; + } + + function isFingerPointing(hand) { + // Index finger is pointing if final two bones of middle, ring, and pinky fingers are > 90 degrees w.r.t. index finger + + var pointing, + indexDirection, + otherDirection, + f; + + pointing = true; + + indexDirection = Vec3.subtract( + MyAvatar.getJointPosition(fingers[hand][0] + "4"), + MyAvatar.getJointPosition(fingers[hand][0] + "2") + ); + + for (f = 1; f < NUM_FINGERs; f += 1) { + otherDirection = Vec3.subtract( + MyAvatar.getJointPosition(fingers[hand][f] + "4"), + MyAvatar.getJointPosition(fingers[hand][f] + "2") + ); + pointing = pointing && Vec3.dot(indexDirection, otherDirection) < 0; + } + + return pointing; + } + + function update() { + var LEFT_HAND = 0, + RIGHT_HAND = 1, + LEFT_HAND_POINTING_FLAG = 1, + RIGHT_HAND_POINTING_FLAG = 2, + FINGER_POINTING_FLAG = 4, + handState; + + handState = 0; + + if (isHandPointing(LEFT_HAND)) { + handState += LEFT_HAND_POINTING_FLAG; + } + if (isHandPointing(RIGHT_HAND)) { + handState += RIGHT_HAND_POINTING_FLAG; + } + + if (handState === 0) { + if (isFingerPointing(LEFT_HAND)) { + handState += LEFT_HAND_POINTING_FLAG; + } + if (isFingerPointing(RIGHT_HAND)) { + handState += RIGHT_HAND_POINTING_FLAG; + } + if (handState !== 0) { + handState += FINGER_POINTING_FLAG; + } + } + + MyAvatar.setHandState(handState); + } + + return { + update: update + }; + +}()); + +Script.update.connect(laserPointer.update); diff --git a/examples/example/audioBall.js b/examples/example/audio/audioBall.js similarity index 98% rename from examples/example/audioBall.js rename to examples/example/audio/audioBall.js index c4b245fbf1..91ef7c0759 100644 --- a/examples/example/audioBall.js +++ b/examples/example/audio/audioBall.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../libraries/globals.js"); +Script.include("../../libraries/globals.js"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/mexicanWhipoorwill.raw"); var CHANCE_OF_PLAYING_SOUND = 0.01; diff --git a/examples/example/audioDeviceExample.js b/examples/example/audio/audioDeviceExample.js similarity index 100% rename from examples/example/audioDeviceExample.js rename to examples/example/audio/audioDeviceExample.js diff --git a/examples/example/audioMuteExample.js b/examples/example/audio/audioMuteExample.js similarity index 100% rename from examples/example/audioMuteExample.js rename to examples/example/audio/audioMuteExample.js diff --git a/examples/example/audioReverbOn.js b/examples/example/audio/audioReverbOn.js similarity index 100% rename from examples/example/audioReverbOn.js rename to examples/example/audio/audioReverbOn.js diff --git a/examples/example/birdSongs.js b/examples/example/audio/birdSongs.js similarity index 100% rename from examples/example/birdSongs.js rename to examples/example/audio/birdSongs.js diff --git a/examples/example/radio.js b/examples/example/audio/radio.js similarity index 100% rename from examples/example/radio.js rename to examples/example/audio/radio.js diff --git a/examples/speechControl.js b/examples/example/audio/speechControl.js similarity index 100% rename from examples/speechControl.js rename to examples/example/audio/speechControl.js diff --git a/examples/example/cameraExample.js b/examples/example/avatarcontrol/cameraExample.js similarity index 100% rename from examples/example/cameraExample.js rename to examples/example/avatarcontrol/cameraExample.js diff --git a/examples/example/controllerExample.js b/examples/example/avatarcontrol/controllerExample.js similarity index 100% rename from examples/example/controllerExample.js rename to examples/example/avatarcontrol/controllerExample.js diff --git a/examples/example/guidedTour.js b/examples/example/avatarcontrol/guidedTour.js similarity index 100% rename from examples/example/guidedTour.js rename to examples/example/avatarcontrol/guidedTour.js diff --git a/examples/example/hideAvatarExample.js b/examples/example/avatarcontrol/hideAvatarExample.js similarity index 96% rename from examples/example/hideAvatarExample.js rename to examples/example/avatarcontrol/hideAvatarExample.js index 66d85becf1..856a8b3c69 100644 --- a/examples/example/hideAvatarExample.js +++ b/examples/example/avatarcontrol/hideAvatarExample.js @@ -12,7 +12,7 @@ // function keyReleaseEvent(event) { - if (event.text == "F2") { + if (event.text == "r") { MyAvatar.shouldRenderLocally = !MyAvatar.shouldRenderLocally; } } diff --git a/examples/example/lookAtExample.js b/examples/example/avatarcontrol/lookAtExample.js similarity index 89% rename from examples/example/lookAtExample.js rename to examples/example/avatarcontrol/lookAtExample.js index 7e3010eb8a..3beb22e7ec 100644 --- a/examples/example/lookAtExample.js +++ b/examples/example/avatarcontrol/lookAtExample.js @@ -8,8 +8,8 @@ // This is an example script that demonstrates use of the Camera class's lookAt(), keepLookingAt(), and stopLookingAt() // features. // -// To use the script, click on a voxel, and the camera will switch into independent mode and fix it's lookAt on the point -// on the face of the voxel that you clicked. Click again and it will stop looking at that point. While in this fixed mode +// To use the script, click on a entity, and the camera will switch into independent mode and fix it's lookAt on the point +// on the face of the entity that you clicked. Click again and it will stop looking at that point. While in this fixed mode // you can use the arrow keys to change the position of the camera. // // Distributed under the Apache License, Version 2.0. @@ -22,7 +22,6 @@ var oldMode = Camera.mode; function cancelLookAt() { if (lookingAtSomething) { lookingAtSomething = false; - Camera.stopLooking(); Camera.mode = oldMode; releaseMovementKeys(); } @@ -73,9 +72,6 @@ function mousePressEvent(event) { // switch to independent mode Camera.mode = "independent"; - // tell the camera to fix it's look at on the point we clicked - Camera.keepLookingAt(intersection.intersection); - // keep track of the fact that we're in this looking at mode lookingAtSomething = true; diff --git a/examples/example/multipleCursorsExample.js b/examples/example/avatarcontrol/multipleCursorsExample.js similarity index 100% rename from examples/example/multipleCursorsExample.js rename to examples/example/avatarcontrol/multipleCursorsExample.js diff --git a/examples/example/multitouchExample.js b/examples/example/avatarcontrol/multitouchExample.js similarity index 100% rename from examples/example/multitouchExample.js rename to examples/example/avatarcontrol/multitouchExample.js diff --git a/examples/example/bot.js b/examples/example/bot.js deleted file mode 100644 index fae6647ff3..0000000000 --- a/examples/example/bot.js +++ /dev/null @@ -1,233 +0,0 @@ -// -// bot.js -// examples -// -// Created by Stephen Birarda on 2/20/14. -// Modified by Philip on 3/3/14 -// Copyright 2014 High Fidelity, Inc. -// -// This is an example script that demonstrates an NPC avatar. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("../libraries/globals.js"); - -function getRandomFloat(min, max) { - return Math.random() * (max - min) + min; -} - -function getRandomInt (min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; -} - -function printVector(string, vector) { - print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); -} - -var CHANCE_OF_MOVING = 0.005; -var CHANCE_OF_SOUND = 0.005; -var CHANCE_OF_HEAD_TURNING = 0.05; -var CHANCE_OF_BIG_MOVE = 0.1; -var CHANCE_OF_WAVING = 0.009; - -var shouldReceiveVoxels = true; -var VOXEL_FPS = 60.0; -var lastVoxelQueryTime = 0.0; - -var isMoving = false; -var isTurningHead = false; -var isPlayingAudio = false; -var isWaving = false; -var waveFrequency = 0.0; -var waveAmplitude = 0.0; - -var X_MIN = 5.0; -var X_MAX = 15.0; -var Z_MIN = 5.0; -var Z_MAX = 15.0; -var Y_PELVIS = 1.0; -var SPINE_JOINT_NUMBER = 13; -var SHOULDER_JOINT_NUMBER = 17; -var ELBOW_JOINT_NUMBER = 18; -var JOINT_R_HIP = 1; -var JOINT_R_KNEE = 2; - -var MOVE_RANGE_SMALL = 0.5; -var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; -var TURN_RANGE = 70.0; -var STOP_TOLERANCE = 0.05; -var MOVE_RATE = 0.05; -var TURN_RATE = 0.15; -var PITCH_RATE = 0.20; -var PITCH_RANGE = 30.0; - -var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) }; -var targetPosition = { x: 0, y: 0, z: 0 }; -var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; -var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; -var targetHeadPitch = 0.0; - -var walkFrequency = 5.0; -var walkAmplitude = 45.0; - -var cumulativeTime = 0.0; - -var sounds = []; -loadSounds(); - -function clamp(val, min, max){ - return Math.max(min, Math.min(max, val)) -} - -// Play a random sound from a list of conversational audio clips -var AVERAGE_AUDIO_LENGTH = 8000; -function playRandomSound() { - if (!Agent.isPlayingAvatarSound) { - var whichSound = Math.floor((Math.random() * sounds.length) % sounds.length); - Agent.playAvatarSound(sounds[whichSound]); - } -} - -// pick an integer between 1 and 20 for the face model for this bot -botNumber = getRandomInt(1, 100); - -if (botNumber <= 20) { - newFaceFilePrefix = "bot" + botNumber; - newBodyFilePrefix = "defaultAvatar_body" -} else { - if (botNumber <= 40) { - newFaceFilePrefix = "superhero"; - } else if (botNumber <= 60) { - newFaceFilePrefix = "amber"; - } else if (botNumber <= 80) { - newFaceFilePrefix = "ron"; - } else { - newFaceFilePrefix = "angie"; - } - - newBodyFilePrefix = "bot" + botNumber; -} - -// set the face model fst using the bot number -// there is no need to change the body model - we're using the default -Avatar.faceModelURL = HIFI_PUBLIC_BUCKET + "meshes/" + newFaceFilePrefix + ".fst"; -Avatar.skeletonModelURL = HIFI_PUBLIC_BUCKET + "meshes/" + newBodyFilePrefix + ".fst"; -Avatar.billboardURL = HIFI_PUBLIC_BUCKET + "meshes/billboards/bot" + botNumber + ".png"; - -Agent.isAvatar = true; -Agent.isListeningToAudioStream = true; - -// change the avatar's position to the random one -Avatar.position = firstPosition; -printVector("New bot, position = ", Avatar.position); - -function stopWaving() { - isWaving = false; - Avatar.clearJointData(SHOULDER_JOINT_NUMBER); - Avatar.clearJointData(ELBOW_JOINT_NUMBER); - Avatar.clearJointData(SPINE_JOINT_NUMBER); -} - -function keepWalking() { - Avatar.setJointData(JOINT_R_HIP, Quat.fromPitchYawRollDegrees(walkAmplitude * Math.sin(cumulativeTime * walkFrequency), 0.0, 0.0)); - Avatar.setJointData(JOINT_R_KNEE, Quat.fromPitchYawRollDegrees(walkAmplitude * Math.sin(cumulativeTime * walkFrequency), 0.0, 0.0)); -} - -function stopWalking() { - Avatar.clearJointData(JOINT_R_HIP); - Avatar.clearJointData(JOINT_R_KNEE); -} - -function updateBehavior(deltaTime) { - - cumulativeTime += deltaTime; - - // Hack - right now you need to set the avatar position a bit after the avatar is made to make sure it's there. - - if (CHANCE_OF_MOVING == 0.000) { - Avatar.position = firstPosition; - } - - if (shouldReceiveVoxels && ((cumulativeTime - lastVoxelQueryTime) > (1.0 / VOXEL_FPS))) { - VoxelViewer.setPosition(Avatar.position); - VoxelViewer.setOrientation(Avatar.orientation); - VoxelViewer.queryOctree(); - lastVoxelQueryTime = cumulativeTime; - /* - if (Math.random() < (1.0 / VOXEL_FPS)) { - print("Voxels in view = " + VoxelViewer.getOctreeElementsCount()); - }*/ - } - - if (!isWaving && (Math.random() < CHANCE_OF_WAVING)) { - isWaving = true; - waveFrequency = 3.0 + Math.random() * 5.0; - waveAmplitude = 5.0 + Math.random() * 60.0; - Script.setTimeout(stopWaving, 1000 + Math.random() * 2000); - Avatar.setJointData(ELBOW_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 45, 0.0)); // Initially turn the palm outward - } else if (isWaving) { - Avatar.setJointData(SHOULDER_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 60 + waveAmplitude * Math.sin((cumulativeTime - 0.25) * waveFrequency))); - Avatar.setJointData(ELBOW_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 25 + waveAmplitude/2.0 * Math.sin(cumulativeTime * 1.2 * waveFrequency))); - Avatar.setJointData(SPINE_JOINT_NUMBER, Quat.fromPitchYawRollDegrees(0.0, 0.0, 60 + waveAmplitude/4.0 * Math.sin(cumulativeTime * waveFrequency))); - - } - - - if (Math.random() < CHANCE_OF_SOUND) { - playRandomSound(); - } - - if (!isTurningHead && (Math.random() < CHANCE_OF_HEAD_TURNING)) { - targetHeadPitch = getRandomFloat(-PITCH_RANGE, PITCH_RANGE); - isTurningHead = true; - } else { - Avatar.headPitch = Avatar.headPitch + (targetHeadPitch - Avatar.headPitch) * PITCH_RATE; - if (Math.abs(Avatar.headPitch - targetHeadPitch) < STOP_TOLERANCE) { - isTurningHead = false; - } - } - if (!isMoving && (Math.random() < CHANCE_OF_MOVING)) { - // Set new target location - targetDirection = Quat.multiply(Avatar.orientation, Quat.angleAxis(getRandomFloat(-TURN_RANGE, TURN_RANGE), { x:0, y:1, z:0 })); - var front = Quat.getFront(targetDirection); - if (Math.random() < CHANCE_OF_BIG_MOVE) { - targetPosition = Vec3.sum(Avatar.position, Vec3.multiply(front, getRandomFloat(0.0, MOVE_RANGE_BIG))); - } else { - targetPosition = Vec3.sum(Avatar.position, Vec3.multiply(front, getRandomFloat(0.0, MOVE_RANGE_SMALL))); - } - targetPosition.x = clamp(targetPosition.x, X_MIN, X_MAX); - targetPosition.z = clamp(targetPosition.z, Z_MIN, Z_MAX); - targetPosition.y = Y_PELVIS; - - isMoving = true; - } else if (isMoving) { - keepWalking(); - Avatar.position = Vec3.sum(Avatar.position, Vec3.multiply(Vec3.subtract(targetPosition, Avatar.position), MOVE_RATE)); - Avatar.orientation = Quat.mix(Avatar.orientation, targetDirection, TURN_RATE); - if (Vec3.length(Vec3.subtract(Avatar.position, targetPosition)) < STOP_TOLERANCE) { - isMoving = false; - stopWalking(); - } - } -} - -Script.update.connect(updateBehavior); - -function loadSounds() { - var sound_filenames = ["AB1.raw", "Anchorman2.raw", "B1.raw", "B1.raw", "Bale1.raw", "Bandcamp.raw", - "Big1.raw", "Big2.raw", "Brian1.raw", "Buster1.raw", "CES1.raw", "CES2.raw", "CES3.raw", "CES4.raw", - "Carrie1.raw", "Carrie3.raw", "Charlotte1.raw", "EN1.raw", "EN2.raw", "EN3.raw", "Eugene1.raw", "Francesco1.raw", - "Italian1.raw", "Japanese1.raw", "Leigh1.raw", "Lucille1.raw", "Lucille2.raw", "MeanGirls.raw", "Murray2.raw", - "Nigel1.raw", "PennyLane.raw", "Pitt1.raw", "Ricardo.raw", "SN.raw", "Sake1.raw", "Samantha1.raw", "Samantha2.raw", - "Spicoli1.raw", "Supernatural.raw", "Swearengen1.raw", "TheDude.raw", "Tony.raw", "Triumph1.raw", "Uma1.raw", - "Walken1.raw", "Walken2.raw", "Z1.raw", "Z2.raw" - ]; - - var SOUND_BASE_URL = HIFI_PUBLIC_BUCKET + "sounds/Cocktail+Party+Snippets/Raws/"; - - for (var i = 0; i < sound_filenames.length; i++) { - sounds.push(SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i])); - } -} diff --git a/examples/example/animationStateExample.js b/examples/example/entities/ZZZ-MOVE-TO_DOCS-animationStateExample.js similarity index 100% rename from examples/example/animationStateExample.js rename to examples/example/entities/ZZZ-MOVE-TO_DOCS-animationStateExample.js diff --git a/examples/example/animatedModelExample.js b/examples/example/entities/animatedModelExample.js similarity index 91% rename from examples/example/animatedModelExample.js rename to examples/example/entities/animatedModelExample.js index 3fffdc88d2..00790fecc8 100644 --- a/examples/example/animatedModelExample.js +++ b/examples/example/entities/animatedModelExample.js @@ -12,7 +12,7 @@ // var count = 0; -var moveUntil = 6000; +var moveUntil = 1000; var stopAfter = moveUntil + 100; var pitch = 0.0; @@ -25,16 +25,19 @@ var originalProperties = { position: { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z }, - - radius : 1, + dimensions: { + x: 1.62, + y: 0.41, + z: 1.13 + }, color: { red: 0, green: 255, blue: 0 }, - modelURL: "http://www.fungibleinsight.com/faces/beta.fst", + modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx", rotation: rotation, - animationURL: "http://www.fungibleinsight.com/faces/gangnam_style_2.fbx", + animationURL: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx", animationIsPlaying: true, }; diff --git a/examples/example/butterflies.js b/examples/example/entities/butterflies.js similarity index 100% rename from examples/example/butterflies.js rename to examples/example/entities/butterflies.js diff --git a/examples/example/collidingEntities.js b/examples/example/entities/collidingEntities.js similarity index 96% rename from examples/example/collidingEntities.js rename to examples/example/entities/collidingEntities.js index 233626df23..37c35e971d 100644 --- a/examples/example/collidingEntities.js +++ b/examples/example/entities/collidingEntities.js @@ -64,7 +64,7 @@ function draw(deltaTime) { y: 1, z: 0 }; - var entitySize = 0.1; + var entitySize = 1.1; print("number of entitys=" + numberEntitiesAdded +"\n"); @@ -99,7 +99,7 @@ function draw(deltaTime) { Script.stop(); } - print("Particles Stats: " + Entities.getLifetimeInSeconds() + " seconds," + + print("Entity Stats: " + Entities.getLifetimeInSeconds() + " seconds," + " Queued packets:" + Entities.getLifetimePacketsQueued() + "," + " PPS:" + Entities.getLifetimePPSQueued() + "," + " BPS:" + Entities.getLifetimeBPSQueued() + "," + diff --git a/examples/example/editEntityExample.js b/examples/example/entities/editEntityExample.js similarity index 91% rename from examples/example/editEntityExample.js rename to examples/example/entities/editEntityExample.js index 422e50b1eb..d6d0a83521 100644 --- a/examples/example/editEntityExample.js +++ b/examples/example/entities/editEntityExample.js @@ -5,7 +5,7 @@ // Created by Brad Hefta-Gaub on 12/31/13. // Copyright 2014 High Fidelity, Inc. // -// This is an example script that demonstrates creating and editing a particle +// This is an example script that demonstrates creating and editing a particle. Go to the origin of the domain to see the results (0,0,0). // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -29,6 +29,11 @@ var originalProperties = { gravity: { x: 0, y: 0, z: 0 }, + dimensions: { + x: 1, + y: 1, + z: 1 + }, color: { red: 0, @@ -74,7 +79,7 @@ function moveEntity(deltaTime) { y: originalProperties.position.y + (count * positionDelta.y), z: originalProperties.position.z + (count * positionDelta.z) }, - radius : 0.25, + //radius : 0.05, }; diff --git a/examples/example/editModelExample.js b/examples/example/entities/editModelExample.js similarity index 78% rename from examples/example/editModelExample.js rename to examples/example/entities/editModelExample.js index f56edfdf3b..474d9afe26 100644 --- a/examples/example/editModelExample.js +++ b/examples/example/entities/editModelExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../libraries/globals.js"); +Script.include("../../libraries/globals.js"); var count = 0; var moveUntil = 2000; @@ -23,22 +23,22 @@ var roll = 180.0; var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var originalProperties = { +type: "Model", position: { x: 2.0, y: 2.0, z: 0.5 }, - radius : 0.25, - - color: { red: 0, + dimensions: { + x: 2.16, + y: 3.34, + z: 0.54 + }, + color: { red: 0, green: 255, blue: 0 }, modelURL: HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/birarda/birarda_head.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/pug.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/minotaur/mino_full.fbx", - //modelURL: HIFI_PUBLIC_BUCKET + "meshes/Combat_tank_V01.FBX", + rotation: rotation }; @@ -67,10 +67,10 @@ function moveEntity(deltaTime) { return; // break early } - //print("count =" + count); + print("count =" + count); count++; - //print("entityID.creatorTokenID = " + entityID.creatorTokenID); + print("entityID.creatorTokenID = " + entityID.creatorTokenID); var newProperties = { position: { diff --git a/examples/example/entityModelExample.js b/examples/example/entities/entityModelExample.js similarity index 75% rename from examples/example/entityModelExample.js rename to examples/example/entities/entityModelExample.js index 067032fc6b..d09a349cb0 100644 --- a/examples/example/entityModelExample.js +++ b/examples/example/entities/entityModelExample.js @@ -11,30 +11,25 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../libraries/globals.js"); var count = 0; -var stopAfter = 100; +var stopAfter = 1000; var modelPropertiesA = { type: "Model", position: { x: 1, y: 1, z: 1 }, velocity: { x: 0.5, y: 0, z: 0.5 }, damping: 0, - dimensions: { x: 0.5, y: 0.5, z: 0.5 }, + dimensions: { + x: 2.16, + y: 3.34, + z: 0.54 + }, modelURL: HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX", lifetime: 20 }; -var modelPropertiesB = { - type: "Model", - position: { x: 1, y: 1.5, z: 1 }, - velocity: { x: 0.5, y: 0, z: 0.5 }, - damping: 0, - dimensions: { x: 0.5, y: 0.5, z: 0.5 }, - modelURL: HIFI_PUBLIC_BUCKET + "meshes/orc.fbx", - lifetime: 20 -}; var ballProperties = { type: "Sphere", @@ -47,7 +42,6 @@ var ballProperties = { }; var modelAEntityID = Entities.addEntity(modelPropertiesA); -var modelBEntityID = Entities.addEntity(modelPropertiesB); var ballEntityID = Entities.addEntity(ballProperties); function endAfterAWhile(deltaTime) { diff --git a/examples/example/findEntitiesExample.js b/examples/example/entities/findEntitiesExample.js similarity index 100% rename from examples/example/findEntitiesExample.js rename to examples/example/entities/findEntitiesExample.js diff --git a/examples/example/flockingBirds.js b/examples/example/entities/flockingBirds.js similarity index 99% rename from examples/example/flockingBirds.js rename to examples/example/entities/flockingBirds.js index fd59b20c48..b07e7cf4bd 100644 --- a/examples/example/flockingBirds.js +++ b/examples/example/entities/flockingBirds.js @@ -5,7 +5,7 @@ // Created by Brad Hefta-Gaub on 3/4/14. // Copyright 2014 High Fidelity, Inc. // -// This is an example script that generates particles that act like flocking birds +// This is an example script that generates entities that act like flocking birds // // All birds, even flying solo... // birds don't like to fall too fast diff --git a/examples/example/lightExample.js b/examples/example/entities/lightExample.js similarity index 98% rename from examples/example/lightExample.js rename to examples/example/entities/lightExample.js index 7a90eb8714..58495a02f4 100644 --- a/examples/example/lightExample.js +++ b/examples/example/entities/lightExample.js @@ -27,7 +27,7 @@ var lightID = Entities.addEntity({ angularVelocity: { x: 0, y: 0, z: 0 }, angularDamping: 0, - isSpotlight: false, + isSpotlight: true, diffuseColor: { red: 255, green: 255, blue: 0 }, ambientColor: { red: 0, green: 0, blue: 0 }, specularColor: { red: 255, green: 255, blue: 255 }, diff --git a/examples/example/rideAlongWithAnEntityExample.js b/examples/example/entities/rideAlongWithAnEntityExample.js similarity index 100% rename from examples/example/rideAlongWithAnEntityExample.js rename to examples/example/entities/rideAlongWithAnEntityExample.js diff --git a/examples/example/spotlightExample.js b/examples/example/entities/spotlightExample.js similarity index 100% rename from examples/example/spotlightExample.js rename to examples/example/entities/spotlightExample.js diff --git a/examples/example/cleanupChessboards.js b/examples/example/games/cleanupChessboards.js similarity index 100% rename from examples/example/cleanupChessboards.js rename to examples/example/games/cleanupChessboards.js diff --git a/examples/example/clonedOverlaysExample.js b/examples/example/games/clonedOverlaysExample.js similarity index 97% rename from examples/example/clonedOverlaysExample.js rename to examples/example/games/clonedOverlaysExample.js index 7aea048175..aa475ee518 100644 --- a/examples/example/clonedOverlaysExample.js +++ b/examples/example/games/clonedOverlaysExample.js @@ -15,10 +15,10 @@ const NUM_OF_TREES = 40; const NUM_OF_SANTAS = 20; // Image source: https://openclipart.org/detail/447/christmas-tree-by-theresaknott (heavily edited by Maximillian Merlin) -const CHRISTMAS_TREE_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/christmas-tree.svg"; +const CHRISTMAS_TREE_SPRITES_URL = "https://s3.amazonaws.com/hifi-public/models/props/xmas/christmas-tree.svg"; // Image source: http://opengameart.org/content/santa-claus (CC-BY 3.0) -const SANTA_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/Santa.png"; +const SANTA_SPRITES_URL = "https://s3.amazonaws.com/hifi-public/models/props/xmas/Santa.png"; Array.prototype.contains = function(obj) { var i = this.length; diff --git a/examples/example/playChess.js b/examples/example/games/playChess.js similarity index 100% rename from examples/example/playChess.js rename to examples/example/games/playChess.js diff --git a/examples/example/spaceInvadersExample.js b/examples/example/games/spaceInvadersExample.js similarity index 97% rename from examples/example/spaceInvadersExample.js rename to examples/example/games/spaceInvadersExample.js index 6216c709c2..5ad8bbe4f6 100644 --- a/examples/example/spaceInvadersExample.js +++ b/examples/example/games/spaceInvadersExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../libraries/globals.js"); +Script.include("../../libraries/globals.js"); var iteration = 0; @@ -106,22 +106,22 @@ invaderModels[0] = { modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[1] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-cyan.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[2] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-medium-cyan.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[3] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-medium-green.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; invaderModels[4] = { - modelURL: HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-small-green.svo", + modelURL: HIFI_PUBLIC_BUCKET + "meshes/space_invader.fbx", modelScale: 450, modelTranslation: { x: -1.3, y: -1.3, z: -1.3 }, }; diff --git a/examples/example/globalCollisionsExample.js b/examples/example/globalCollisionsExample.js index 426aebd5d9..5813cb2472 100644 --- a/examples/example/globalCollisionsExample.js +++ b/examples/example/globalCollisionsExample.js @@ -14,13 +14,6 @@ print("hello..."); -function entityCollisionWithVoxel(entity, voxel, collision) { - print("entityCollisionWithVoxel().."); - print(" entity.getID()=" + entity.id); - print(" voxel color...=" + voxel.red + ", " + voxel.green + ", " + voxel.blue); - Vec3.print('penetration=', collision.penetration); - Vec3.print('contactPoint=', collision.contactPoint); -} function entityCollisionWithEntity(entityA, entityB, collision) { print("entityCollisionWithParticle().."); @@ -30,7 +23,6 @@ function entityCollisionWithEntity(entityA, entityB, collision) { Vec3.print('contactPoint=', collision.contactPoint); } -Entities.entityCollisionWithVoxel.connect(entityCollisionWithVoxel); Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); print("here... hello..."); diff --git a/examples/example/localVoxelsExample.js b/examples/example/localVoxelsExample.js deleted file mode 100644 index d64138b214..0000000000 --- a/examples/example/localVoxelsExample.js +++ /dev/null @@ -1,63 +0,0 @@ -// -// localVoxelsExample.js -// examples -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -var TREE_SCALE = 16384; -var tree = LocalVoxels("tree"); -tree.setVoxel(0, 0, 0, - 0.5 * TREE_SCALE, - 255, 0, 0); -tree.setVoxel(0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0.5 * TREE_SCALE, - 0, 255, 0); - -var copy = LocalVoxels("copy"); -tree.pasteFrom(0, 0, 0, TREE_SCALE, "copy"); -tree.pasteFrom(0, 0, 0, TREE_SCALE, "clipboard"); - -var overlay1 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 1, z: 1}, - size: 1, - name: "tree" - }); -var overlay2 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 2, z: 1}, - size: 1, - name: "tree" - }); -var overlay3 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 3, z: 1}, - size: 1, - name: "tree" - }); -var overlay4 = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 4, z: 1}, - size: 1, - name: "copy" - }); - -var clipboard = Overlays.addOverlay("localvoxels", { - position: {x: 1, y: 5, z: 1}, - size: 1, - name: "clipboard" - }); - - - -// When our script shuts down, we should clean up all of our overlays -function scriptEnding() { - Overlays.deleteOverlay(overlay1); - Overlays.deleteOverlay(overlay2); - Overlays.deleteOverlay(overlay3); - Overlays.deleteOverlay(overlay4); - Overlays.deleteOverlay(clipboard); -} -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/examples/example/metavoxels.js b/examples/example/metavoxels/metavoxels.js similarity index 100% rename from examples/example/metavoxels.js rename to examples/example/metavoxels/metavoxels.js diff --git a/examples/example/globalServicesExample.js b/examples/example/misc/globalServicesExample.js similarity index 100% rename from examples/example/globalServicesExample.js rename to examples/example/misc/globalServicesExample.js diff --git a/examples/example/includeExample.js b/examples/example/scripts/includeExample.js similarity index 84% rename from examples/example/includeExample.js rename to examples/example/scripts/includeExample.js index 50a1234772..c9c882156e 100644 --- a/examples/example/includeExample.js +++ b/examples/example/scripts/includeExample.js @@ -15,5 +15,5 @@ Script.include("http://public.highfidelity.io/scripts/lookWithTouch.js"); // You can also include scripts that are relative to the current script -Script.include("editVoxels.js"); -Script.include("../examples/selectAudioDevice.js"); +//Script.include("../../editEntities.js"); +//Script.include("../../examples/selectAudioDevice.js"); diff --git a/examples/loadScriptFromMessage.js b/examples/example/scripts/loadScriptFromMessage.js similarity index 100% rename from examples/loadScriptFromMessage.js rename to examples/example/scripts/loadScriptFromMessage.js diff --git a/examples/example/locationExample.js b/examples/example/scripts/locationExample.js similarity index 100% rename from examples/example/locationExample.js rename to examples/example/scripts/locationExample.js diff --git a/examples/example/rayPickExample.js b/examples/example/scripts/rayPickExample.js similarity index 100% rename from examples/example/rayPickExample.js rename to examples/example/scripts/rayPickExample.js diff --git a/examples/example/settingsExample.js b/examples/example/scripts/settingsExample.js similarity index 96% rename from examples/example/settingsExample.js rename to examples/example/scripts/settingsExample.js index bef347ff07..f8364ff91b 100644 --- a/examples/example/settingsExample.js +++ b/examples/example/scripts/settingsExample.js @@ -15,4 +15,4 @@ print("mySetting: " + Settings.getValue("mySetting")); Settings.setValue("mySetting", "spam"); print("mySetting: " + Settings.getValue("mySetting")); -Script.stop(); \ No newline at end of file +//Script.stop(); \ No newline at end of file diff --git a/examples/example/streetAreaExample.js b/examples/example/scripts/streetAreaExample.js similarity index 100% rename from examples/example/streetAreaExample.js rename to examples/example/scripts/streetAreaExample.js diff --git a/examples/timer.js b/examples/example/scripts/timer.js similarity index 100% rename from examples/timer.js rename to examples/example/scripts/timer.js diff --git a/examples/example/dialogExample.js b/examples/example/ui/dialogExample.js similarity index 100% rename from examples/example/dialogExample.js rename to examples/example/ui/dialogExample.js diff --git a/examples/example/fileBrowserExample.js b/examples/example/ui/fileBrowserExample.js similarity index 100% rename from examples/example/fileBrowserExample.js rename to examples/example/ui/fileBrowserExample.js diff --git a/examples/example/menuExample.js b/examples/example/ui/menuExample.js similarity index 100% rename from examples/example/menuExample.js rename to examples/example/ui/menuExample.js diff --git a/examples/example/overlaysExample.js b/examples/example/ui/overlaysExample.js similarity index 99% rename from examples/example/overlaysExample.js rename to examples/example/ui/overlaysExample.js index c72619a042..4e85512545 100644 --- a/examples/example/overlaysExample.js +++ b/examples/example/ui/overlaysExample.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../libraries/globals.js"); +Script.include("../../libraries/globals.js"); // The "Swatches" example of this script will create 9 different image overlays, that use the color feature to // display different colors as color swatches. The overlays can be clicked on, to change the "selectedSwatch" variable diff --git a/examples/example/textInputOverlayExample.js b/examples/example/ui/textInputOverlayExample.js similarity index 100% rename from examples/example/textInputOverlayExample.js rename to examples/example/ui/textInputOverlayExample.js diff --git a/examples/example/windowExample.js b/examples/example/ui/windowExample.js similarity index 100% rename from examples/example/windowExample.js rename to examples/example/ui/windowExample.js diff --git a/examples/locationsMenu.js b/examples/locationsMenu.js deleted file mode 100644 index 30fa377a6f..0000000000 --- a/examples/locationsMenu.js +++ /dev/null @@ -1,304 +0,0 @@ -// -// locationsMenu.js -// examples -// -// Created by Ryan Huffman on 5/28/14 -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("libraries/globals.js"); - -var scriptUrl = "https://script.google.com/macros/s/AKfycbwIo4lmF-qUwX1Z-9eA_P-g2gse9oFhNcjVyyksGukyDDEFXgU/exec?action=listOwners&domain=alpha.highfidelity.io"; - -var LocationMenu = function(opts) { - var self = this; - - var pageSize = opts.pageSize || 10; - var menuWidth = opts.menuWidth || 150; - var menuHeight = opts.menuItemHeight || 24; - - var inactiveColor = { red: 51, green: 102, blue: 102 }; - var activeColor = { red: 18, green: 66, blue: 66 }; - var prevNextColor = { red: 192, green: 192, blue: 192 }; - var disabledColor = { red: 64, green: 64, blue: 64}; - var position = { x: 0, y: 0 }; - - var locationIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/location.svg"; - var toolHeight = 50; - var toolWidth = 50; - var visible = false; - var menuItemOffset = { - x: 55, - y: 0, - }; - var menuItemPadding = 5; - var margin = 7; - var fullMenuHeight = (2 * menuItemOffset.y) + (menuHeight * (pageSize + 1)); - var menuOffset = -fullMenuHeight + toolHeight; - - var windowDimensions = Controller.getViewportDimensions(); - - this.locations = []; - this.numPages = 1; - this.page = 0; - - this.menuToggleButton = Overlays.addOverlay("image", { - x: position.x, - y: position.y, - width: toolWidth, height: toolHeight, - subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight }, - imageURL: locationIconUrl, - alpha: 0.9 - }); - - this.background = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth + 10, - height: (menuHeight * (pageSize + 1)) + 10, - backgroundColor: { red: 0, green: 0, blue: 0}, - topMargin: 4, - leftMargin: 4, - text: "", - visible: visible, - }); - - this.menuItems = []; - for (var i = 0; i < pageSize; i++) { - var menuItem = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth, - height: menuHeight, - backgroundColor: inactiveColor, - topMargin: margin, - leftMargin: margin, - text: (i == 0) ? "Loading..." : "", - visible: visible, - }); - this.menuItems.push({ overlay: menuItem, location: null }); - } - - this.previousButton = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth / 2, - height: menuHeight, - backgroundColor: disabledColor, - topMargin: margin, - leftMargin: margin, - text: "Previous", - visible: visible, - }); - - this.nextButton = Overlays.addOverlay("text", { - x: 0, - y: 0, - width: menuWidth / 2, - height: menuHeight, - backgroundColor: disabledColor, - topMargin: margin, - leftMargin: margin, - text: "Next", - visible: visible, - }); - - this.reposition = function(force) { - var newWindowDimensions = Controller.getViewportDimensions(); - if (force || newWindowDimensions.y != windowDimensions.y) { - windowDimensions = newWindowDimensions; - - position.x = 8; - position.y = Math.floor(windowDimensions.y / 2) + 25 + 50 + 8; - - Overlays.editOverlay(self.menuToggleButton, { - x: position.x, - y: position.y, - }); - Overlays.editOverlay(self.background, { - x: position.x + menuItemOffset.x, - y: position.y + menuItemOffset.y - 2 * menuItemPadding + menuOffset, - }); - for (var i = 0; i < pageSize; i++) { - Overlays.editOverlay(self.menuItems[i].overlay, { - x: position.x + menuItemOffset.x + menuItemPadding, - y: position.y + menuItemOffset.y - menuItemPadding + (i * menuHeight) + menuOffset, - }); - } - Overlays.editOverlay(self.previousButton, { - x: position.x + menuItemOffset.x + menuItemPadding, - y: position.y + menuItemOffset.y - menuItemPadding + (pageSize * menuHeight) + menuOffset, - }); - Overlays.editOverlay(self.nextButton, { - x: position.x + menuItemOffset.x + menuItemPadding + (menuWidth / 2), - y: position.y + menuItemOffset.y - menuItemPadding + (pageSize * menuHeight) + menuOffset, - }); - } - } - - this.updateLocations = function(locations) { - this.locations = locations; - this.numPages = Math.ceil(locations.length / pageSize); - this.goToPage(0); - } - - this.setError = function() { - Overlays.editOverlay(this.menuItems[0].overlay, { text: "Error loading data" }); - } - - this.toggleMenu = function() { - visible = !visible; - for (var i = 0; i < this.menuItems.length; i++) { - Overlays.editOverlay(this.menuItems[i].overlay, { visible: visible}); - } - Overlays.editOverlay(this.previousButton, { visible: visible}); - Overlays.editOverlay(this.nextButton, { visible: visible}); - Overlays.editOverlay(this.background, { visible: visible}); - if (visible) { - Overlays.editOverlay(this.menuToggleButton, { subImage: { x: 0, y: 0, width: toolWidth, height: toolHeight } }), - } else { - Overlays.editOverlay(this.menuToggleButton, { subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight } }), - } - } - - this.goToPage = function(pageNumber) { - if (pageNumber < 0 || pageNumber >= this.numPages) { - return; - } - - this.page = pageNumber; - var start = pageNumber * pageSize; - for (var i = 0; i < pageSize; i++) { - var update = {}; - var location = null; - if (start + i < this.locations.length) { - location = this.locations[start + i]; - update.text = (start + i + 1) + ". " + location.username; - update.backgroundColor = inactiveColor; - } else { - update.text = ""; - update.backgroundColor = disabledColor; - } - Overlays.editOverlay(this.menuItems[i].overlay, update); - this.menuItems[i].location = location; - } - - this.previousEnabled = pageNumber > 0; - this.nextEnabled = pageNumber < (this.numPages - 1); - - Overlays.editOverlay(this.previousButton, { backgroundColor: this.previousEnabled ? prevNextColor : disabledColor}); - Overlays.editOverlay(this.nextButton, { backgroundColor: this.nextEnabled ? prevNextColor : disabledColor }); - } - - this.mousePressEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == self.menuToggleButton) { - self.toggleMenu(); - } else if (clickedOverlay == self.previousButton) { - if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - } else if (clickedOverlay == self.nextButton) { - if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - } else { - for (var i = 0; i < self.menuItems.length; i++) { - if (clickedOverlay == self.menuItems[i].overlay) { - if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); - } - break; - } - } - } - } - - this.mouseReleaseEvent = function(event) { - var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); - - if (clickedOverlay == self.previousButton) { - if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - self.goToPage(self.page - 1); - } - } else if (clickedOverlay == self.nextButton) { - if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - self.goToPage(self.page + 1); - } - } else { - for (var i = 0; i < self.menuItems.length; i++) { - if (clickedOverlay == self.menuItems[i].overlay) { - if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); - var location = self.menuItems[i].location; - Window.location = "hifi://" + location.domain + "/" - + location.x + "," + location.y + "," + location.z; - } - break; - } - } - } - } - - this.cleanup = function() { - for (var i = 0; i < self.menuItems.length; i++) { - Overlays.deleteOverlay(self.menuItems[i].overlay); - } - Overlays.deleteOverlay(self.menuToggleButton); - Overlays.deleteOverlay(self.previousButton); - Overlays.deleteOverlay(self.nextButton); - Overlays.deleteOverlay(self.background); - } - - Controller.mousePressEvent.connect(this.mousePressEvent); - Controller.mouseReleaseEvent.connect(this.mouseReleaseEvent); - Script.update.connect(this.reposition); - Script.scriptEnding.connect(this.cleanup); - - this.reposition(true); -}; - -var locationMenu = new LocationMenu({ pageSize: 8 }); - -print("Loading strip data from " + scriptUrl); - -var req = new XMLHttpRequest(); -req.responseType = 'json'; - -req.onreadystatechange = function() { - if (req.readyState == req.DONE) { - if (req.status == 200 && req.response != null) { - for (var domain in req.response) { - var locations = req.response[domain]; - var users = []; - for (var i = 0; i < locations.length; i++) { - var loc = locations[i]; - var x1 = loc[1], - x2 = loc[2], - y1 = loc[3], - y2 = loc[4]; - users.push({ - domain: domain, - username: loc[0], - x: x1, - y: 300, - z: y1, - }); - } - locationMenu.updateLocations(users); - } - } else { - print("Error loading data: " + req.status + " " + req.statusText + ", " + req.errorCode + ": " + req.responseText); - locationMenu.setError(); - } - } -} - -req.open("GET", scriptUrl); -req.send(); diff --git a/examples/sit.js b/examples/sit.js index c3abe9a908..71d909d1e7 100644 --- a/examples/sit.js +++ b/examples/sit.js @@ -10,7 +10,7 @@ // -var buttonImageUrl = "https://worklist-prod.s3.amazonaws.com/attachment/0aca88e1-9bd8-5c1d.svg"; +var buttonImageUrl = "https://public.highfidelity.io/images/tools/sit.svg"; var windowDimensions = Controller.getViewportDimensions(); diff --git a/examples/testModelOverlaySubMeshes.js b/examples/testModelOverlaySubMeshes.js deleted file mode 100644 index 20ec10ef7c..0000000000 --- a/examples/testModelOverlaySubMeshes.js +++ /dev/null @@ -1,88 +0,0 @@ -var position = Vec3.sum(MyAvatar.position, { x: 0, y: -1, z: 0}); - -var scalingFactor = 0.01; - -var sphereNaturalExtentsMin = { x: -1230, y: -1223, z: -1210 }; -var sphereNaturalExtentsMax = { x: 1230, y: 1229, z: 1223 }; -var panelsNaturalExtentsMin = { x: -1181, y: -326, z: 56 }; -var panelsNaturalExtentsMax = { x: 1181, y: 576, z: 1183 }; - -var sphereNaturalDimensions = Vec3.subtract(sphereNaturalExtentsMax, sphereNaturalExtentsMin); -var panelsNaturalDimensions = Vec3.subtract(panelsNaturalExtentsMax, panelsNaturalExtentsMin); -Vec3.print("sphereNaturalDimensions:", sphereNaturalDimensions); -Vec3.print("panelsNaturalDimensions:", panelsNaturalDimensions); - -var sphereNaturalCenter = Vec3.sum(sphereNaturalExtentsMin, Vec3.multiply(sphereNaturalDimensions, 0.5)); -var panelsNaturalCenter = Vec3.sum(panelsNaturalExtentsMin, Vec3.multiply(panelsNaturalDimensions, 0.5)); -Vec3.print("sphereNaturalCenter:", sphereNaturalCenter); -Vec3.print("panelsNaturalCenter:", panelsNaturalCenter); - -var sphereDimensions = Vec3.multiply(sphereNaturalDimensions, scalingFactor); -var panelsDimensions = Vec3.multiply(panelsNaturalDimensions, scalingFactor); -Vec3.print("sphereDimensions:", sphereDimensions); -Vec3.print("panelsDimensions:", panelsDimensions); - -var sphereCenter = Vec3.multiply(sphereNaturalCenter, scalingFactor); -var panelsCenter = Vec3.multiply(panelsNaturalCenter, scalingFactor); -Vec3.print("sphereCenter:", sphereCenter); -Vec3.print("panelsCenter:", panelsCenter); - -var centerShift = Vec3.subtract(panelsCenter, sphereCenter); -Vec3.print("centerShift:", centerShift); - -var spherePosition = position; -Vec3.print("spherePosition:", spherePosition); -var panelsPosition = Vec3.sum(spherePosition, centerShift); -Vec3.print("panelsPosition:", panelsPosition); - - -var screensOverlay = Overlays.addOverlay("model", { - position: panelsPosition, - dimensions: panelsDimensions, - url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_IsolatedPanelsFreezeTransforms.fbx" - }); - - -var structureOverlay = Overlays.addOverlay("model", { - position: spherePosition, - dimensions: sphereDimensions, - url: "https://s3.amazonaws.com/hifi-public/models/sets/Lobby/LobbyConcepts/Lobby5_OrbShellOnly.fbx", - ignoreRayIntersection: true, // we don't want to ray pick against any of this - }); - -var statusText = Overlays.addOverlay("text", { - x: 200, - y: 100, - width: 200, - height: 20, - backgroundColor: { red: 0, green: 0, blue: 0}, - alpha: 1.0, - backgroundAlpha: 1.0, - color: { red: 255, green: 255, blue: 255}, - topMargin: 4, - leftMargin: 4, - text: "", - }); - - -Controller.mouseMoveEvent.connect(function(event){ - var pickRay = Camera.computePickRay(event.x, event.y); - var result = Overlays.findRayIntersection(pickRay); - - if (result.intersects) { - if (result.overlayID == screensOverlay) { - Overlays.editOverlay(statusText, { text: "You are pointing at: " + result.extraInfo }); - } else { - Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." }); - } - } else { - Overlays.editOverlay(statusText, { text: "You are not pointing at a panel..." }); - } -}); - - -Script.scriptEnding.connect(function(){ - Overlays.deleteOverlay(screensOverlay); - Overlays.deleteOverlay(structureOverlay); - Overlays.deleteOverlay(statusText); -}); diff --git a/examples/twoFallingEntities.js b/examples/twoFallingEntities.js deleted file mode 100644 index 2d71344e2c..0000000000 --- a/examples/twoFallingEntities.js +++ /dev/null @@ -1,25 +0,0 @@ -// -// twoFallingEntities.js -// -// Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds -// - -var diameter = 0.2; -var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)); -var properties = { - type: "Sphere", - position: position, - velocity: { x: 0, y: 0, z: 0}, - gravity: { x: 0, y: -0.05, z: 0}, - dimensions: { x: diameter, y: diameter, z: diameter }; - damping: 0.00001, - color: { red: 200, green: 0, blue: 0 }, - lifetime: 60 - }; - -var newEntity = Entities.addEntity(properties); -position.x -= 0.5 * diameter; -properties.position = position; -var newEntityTwo = Entities.addEntity(properties); - -Script.stop(); // no need to run anymore diff --git a/examples/orbitingSound.js b/examples/utilities/diagnostics/orbitingSound.js similarity index 100% rename from examples/orbitingSound.js rename to examples/utilities/diagnostics/orbitingSound.js diff --git a/examples/utilities/diagnostics/playSoundOrbit.js b/examples/utilities/diagnostics/playSoundOrbit.js deleted file mode 100644 index d9885b7f34..0000000000 --- a/examples/utilities/diagnostics/playSoundOrbit.js +++ /dev/null @@ -1,43 +0,0 @@ -// -// playSoundPath.js -// examples -// -// Created by Craig Hansen-Sturm on 05/27/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("../../libraries/globals.js"); - -var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); - -var currentTime = 1.570079; // pi/2 -var deltaTime = 0.05; -var distance = 1; -var debug = 0; - -function playSound() { - currentTime += deltaTime; - - var s = distance * Math.sin(currentTime); - var c = distance * Math.cos(currentTime); - - var soundOffset = { x:s, y:0, z:c }; - - if (debug) { - print("t=" + currentTime + "offset=" + soundOffset.x + "," + soundOffset.y + "," + soundOffset.z); - } - - var avatarPosition = MyAvatar.position; - var soundPosition = Vec3.sum(avatarPosition,soundOffset); - - Audio.playSound(soundClip, { - position: soundPosition - }); -} - -Script.setInterval(playSound, 850); - - diff --git a/examples/playSoundWave.js b/examples/utilities/diagnostics/playSoundWave.js similarity index 100% rename from examples/playSoundWave.js rename to examples/utilities/diagnostics/playSoundWave.js diff --git a/examples/typedArraysUnitTest.js b/examples/utilities/diagnostics/typedArraysUnitTest.js similarity index 99% rename from examples/typedArraysUnitTest.js rename to examples/utilities/diagnostics/typedArraysUnitTest.js index e86a07289d..0688667cc4 100644 --- a/examples/typedArraysUnitTest.js +++ b/examples/utilities/diagnostics/typedArraysUnitTest.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("Test.js"); +Script.include("../../libraries/unitTest.js"); // e.g. extractbits([0xff, 0x80, 0x00, 0x00], 23, 30); inclusive function extractbits(bytes, lo, hi) { diff --git a/examples/Recorder.js b/examples/utilities/record/recorder.js similarity index 100% rename from examples/Recorder.js rename to examples/utilities/record/recorder.js diff --git a/examples/crazylegs.js b/examples/utilities/tools/crazylegs.js similarity index 93% rename from examples/crazylegs.js rename to examples/utilities/tools/crazylegs.js index 7a6fb68520..38ecaba7c0 100644 --- a/examples/crazylegs.js +++ b/examples/utilities/tools/crazylegs.js @@ -4,6 +4,8 @@ // // Created by Andrzej Kapolka on 3/6/14. // Copyright 2014 High Fidelity, Inc. +// +// Outputs the joint index of an avatar, this is useful for avatar procedural animations // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/examples/currentAPI.js b/examples/utilities/tools/currentAPI.js similarity index 100% rename from examples/currentAPI.js rename to examples/utilities/tools/currentAPI.js diff --git a/examples/developerMenuItems.js b/examples/utilities/tools/developerMenuItems.js similarity index 100% rename from examples/developerMenuItems.js rename to examples/utilities/tools/developerMenuItems.js From 288e2ee45a8f4ed035799864fe965e681a54abc1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:36:14 -0800 Subject: [PATCH 27/52] Add output buffer starve detection to audio --- interface/src/Audio.cpp | 25 +++++++++++++++++++++++-- interface/src/Audio.h | 21 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index d486ff6f50..99dcaa7eff 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -124,6 +124,11 @@ Audio::Audio(QObject* parent) : _audioOutputMsecsUnplayedStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS), _lastSentAudioPacket(0), _outputBufferSizeFrames(DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES), + _outputStarveDetectionStartTimeMsec(0), + _outputStarveDetectionCount(0), + _outputStarveDetectionEnabled(true), + _outputStarveDetectionPeriodMsec(DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD), + _outputStarveDetectionThreshold(DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD), _packetSentTimeGaps(1, APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS), _audioOutputIODevice(_receivedAudioStream, this) { @@ -1830,8 +1835,24 @@ void Audio::outputNotify() { if (recentUnfulfilled > 0) { qDebug() << "WARNING --- WE HAD at least:" << recentUnfulfilled << "recently unfulfilled readData() calls"; - // TODO: Ryan Huffman -- add code here to increase the AUDIO_OUTPUT_BUFFER_SIZE_FRAMES... this code only - // runs in cases where the audio device requested data samples, and ran dry because we couldn't fulfill the request + if (_outputStarveDetectionEnabled) { + quint64 now = QDateTime::currentMSecsSinceEpoch(); + quint64 dt = now - _outputStarveDetectionStartTimeMsec; + if (dt > _outputStarveDetectionPeriodMsec) { + _outputStarveDetectionStartTimeMsec = now; + _outputStarveDetectionCount = 0; + } else { + _outputStarveDetectionCount += recentUnfulfilled; + if (_outputStarveDetectionCount > _outputStarveDetectionThreshold) { + int newOutputBufferSizeFrames = _outputBufferSizeFrames + 1; + qDebug() << "Starve detection threshold met, increasing buffer size to " << newOutputBufferSizeFrames; + setOutputBufferSize(newOutputBufferSizeFrames); + + _outputStarveDetectionStartTimeMsec = now; + _outputStarveDetectionCount = 0; + } + } + } } } diff --git a/interface/src/Audio.h b/interface/src/Audio.h index ff22d2d03f..8cb46c6328 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -63,7 +63,10 @@ static const int MAX_16_BIT_AUDIO_SAMPLE = 32767; static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3; static const int MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 1; -static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 50; +static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 20; +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = true; +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD = 3; +static const quint64 DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD = 10 * 1000; // 10 Seconds class QAudioInput; class QAudioOutput; @@ -134,6 +137,15 @@ public: int getOutputBufferSize() { return _outputBufferSizeFrames; } + bool getOutputStarveDetectionEnabled() { return _outputStarveDetectionEnabled; } + void setOutputStarveDetectionEnabled(bool enabled) { _outputStarveDetectionEnabled = enabled; } + + int getOutputStarveDetectionPeriod() { return _outputStarveDetectionPeriodMsec; } + void setOutputStarveDetectionPeriod(int msecs) { _outputStarveDetectionPeriodMsec = msecs; } + + int getOutputStarveDetectionThreshold() { return _outputStarveDetectionThreshold; } + void setOutputStarveDetectionThreshold(int threshold) { _outputStarveDetectionThreshold = threshold; } + public slots: void start(); void stop(); @@ -161,6 +173,7 @@ public slots: void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel); void addStereoSamplesToScope(const QByteArray& samples); void processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer); + void setOutputBufferSize(int numFrames); virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector); @@ -219,6 +232,12 @@ private: QString _outputAudioDeviceName; int _outputBufferSizeFrames; + bool _outputStarveDetectionEnabled; + quint64 _outputStarveDetectionStartTimeMsec; + int _outputStarveDetectionCount; + int _outputStarveDetectionPeriodMsec; + int _outputStarveDetectionThreshold; // Maximum number of starves per _outputStarveDetectionPeriod before increasing buffer size + StDev _stdev; QElapsedTimer _timeSinceLastReceived; From 77aecaabd0367125e7f5fa38b64ee61a8e36c885 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:36:26 -0800 Subject: [PATCH 28/52] Remove extra switch output call --- interface/src/Audio.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 99dcaa7eff..013f96bb2b 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -449,7 +449,6 @@ void Audio::start() { QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput); qDebug() << "The default audio output device is" << outputDeviceInfo.deviceName(); bool outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo); - outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo); if (!inputFormatSupported) { qDebug() << "Unable to set up audio input because of a problem with input format."; From a660e7efedf1342f9d5dda3215a6cf00e6a44bb9 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:37:03 -0800 Subject: [PATCH 29/52] Add output starve values to settings --- interface/src/Menu.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ca22231024..97ea28eaeb 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -657,6 +657,9 @@ void Menu::loadSettings(QSettings* settings) { _receivedAudioStreamSettings._repetitionWithFade = settings->value("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE).toBool(); Audio* audio = Application::getInstance()->getAudio(); + audio->setOutputStarveDetectionEnabled(settings->value("audioOutputStarveDetectionEnabled", DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED).toBool()); + audio->setOutputStarveDetectionThreshold(settings->value("audioOutputStarveDetectionThreshold", DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD).toInt()); + audio->setOutputStarveDetectionPeriod(settings->value("audioOutputStarveDetectionPeriod", DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD).toInt()); int bufferSize = settings->value("audioOutputBufferSize", DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES).toInt(); QMetaObject::invokeMethod(audio, "setOutputBufferSize", Q_ARG(int, bufferSize)); @@ -727,7 +730,11 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("windowSecondsForDesiredReduction", _receivedAudioStreamSettings._windowSecondsForDesiredReduction); settings->setValue("repetitionWithFade", _receivedAudioStreamSettings._repetitionWithFade); - settings->setValue("audioOutputBufferSize", Application::getInstance()->getAudio()->getOutputBufferSize()); + Audio* audio = Application::getInstance()->getAudio(); + settings->setValue("audioOutputStarveDetectionEnabled", audio->getOutputStarveDetectionEnabled()); + settings->setValue("audioOutputStarveDetectionThreshold", audio->getOutputStarveDetectionThreshold()); + settings->setValue("audioOutputStarveDetectionPeriod", audio->getOutputStarveDetectionPeriod()); + settings->setValue("audioOutputBufferSize", audio->getOutputBufferSize()); settings->setValue("fieldOfView", _fieldOfView); settings->setValue("faceshiftEyeDeflection", _faceshiftEyeDeflection); From 08776aec9d4c76ba605687658d11a48767fdcbbe Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:37:17 -0800 Subject: [PATCH 30/52] Add output starve settings to preferences --- interface/src/ui/PreferencesDialog.cpp | 13 +- interface/ui/preferencesDialog.ui | 216 ++++++++++++++++++++++++- 2 files changed, 225 insertions(+), 4 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index bb70537adf..1e85cfd410 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -140,7 +140,12 @@ void PreferencesDialog::loadPreferences() { ui.windowSecondsForDesiredReductionSpin->setValue(streamSettings._windowSecondsForDesiredReduction); ui.repetitionWithFadeCheckBox->setChecked(streamSettings._repetitionWithFade); - ui.outputBufferSizeSpinner->setValue(Application::getInstance()->getAudio()->getOutputBufferSize()); + Audio* audio = Application::getInstance()->getAudio(); + ui.outputBufferSizeSpinner->setValue(audio->getOutputBufferSize()); + + ui.outputStarveDetectionCheckBox->setChecked(audio->getOutputStarveDetectionEnabled()); + ui.outputStarveDetectionThresholdSpinner->setValue(audio->getOutputStarveDetectionThreshold()); + ui.outputStarveDetectionPeriodSpinner->setValue(audio->getOutputStarveDetectionPeriod()); ui.realWorldFieldOfViewSpin->setValue(menuInstance->getRealWorldFieldOfView()); @@ -253,10 +258,14 @@ void PreferencesDialog::savePreferences() { Menu::getInstance()->setReceivedAudioStreamSettings(streamSettings); audio->setReceivedAudioStreamSettings(streamSettings); - Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings); + Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings); QMetaObject::invokeMethod(audio, "setOutputBufferSize", Q_ARG(int, ui.outputBufferSizeSpinner->value())); + audio->setOutputStarveDetectionEnabled(ui.outputStarveDetectionCheckBox->isChecked()); + audio->setOutputStarveDetectionThreshold(ui.outputStarveDetectionThresholdSpinner->value()); + audio->setOutputStarveDetectionPeriod(ui.outputStarveDetectionPeriodSpinner->value()); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Application::getInstance()->bumpSettings(); diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 864f8aa282..db4a747322 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -59,9 +59,9 @@ 0 - -690 + -825 485 - 1499 + 1611 @@ -1917,6 +1917,218 @@ + + + + + 0 + 0 + + + + + 32 + 40 + + + + + 0 + 0 + + + + + Arial + + + + Output Starve Detection (Automatic Buffer Size Increase) + + + + 32 + 32 + + + + + + + + 0 + + + 7 + + + 0 + + + 7 + + + + + + Arial + + + + Output Starve Detection Threshold + + + 0 + + + windowSecondsForDesiredReductionSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 1 + + + 500 + + + 1 + + + + + + + + + 0 + + + 7 + + + 0 + + + 7 + + + + + + Arial + + + + Output Starve Detection Period (ms) + + + 0 + + + windowSecondsForDesiredReductionSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 1 + + + 999999999 + + + 1 + + + + + From cb80e18ad09246df4f90729fdd607e23d5af30a9 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:47:24 -0800 Subject: [PATCH 31/52] Update default detection period to be int --- interface/src/Audio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 465455f039..2799525349 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -66,7 +66,7 @@ static const int MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 1; static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 20; static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = true; static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD = 3; -static const quint64 DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD = 10 * 1000; // 10 Seconds +static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD = 10 * 1000; // 10 Seconds class QAudioInput; class QAudioOutput; From 35a69ce0491525135bda85b810e0030f37971ac5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 7 Jan 2015 09:48:12 -0800 Subject: [PATCH 32/52] remove the faceplus find module --- BUILD.md | 2 +- cmake/modules/FindFaceplus.cmake | 24 ------------------------ interface/src/devices/FaceTracker.h | 2 +- 3 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 cmake/modules/FindFaceplus.cmake diff --git a/BUILD.md b/BUILD.md index d068d6d458..c86e34823c 100644 --- a/BUILD.md +++ b/BUILD.md @@ -60,5 +60,5 @@ OS X users who tap our [homebrew formulas repository](https://github.com/highfid ####Devices -You can support external input/output devices such as Leap Motion, Faceplus, Faceshift, PrioVR, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. +You can support external input/output devices such as Leap Motion, Faceshift, PrioVR, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. diff --git a/cmake/modules/FindFaceplus.cmake b/cmake/modules/FindFaceplus.cmake deleted file mode 100644 index e97fce3edb..0000000000 --- a/cmake/modules/FindFaceplus.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Try to find the Faceplus library -# -# You must provide a FACEPLUS_ROOT_DIR which contains lib and include directories -# -# Once done this will define -# -# FACEPLUS_FOUND - system found Faceplus -# FACEPLUS_INCLUDE_DIRS - the Faceplus include directory -# FACEPLUS_LIBRARIES - Link this to use Faceplus -# -# Created on 4/8/2014 by Andrzej Kapolka -# Copyright (c) 2014 High Fidelity -# - -find_path(FACEPLUS_INCLUDE_DIRS faceplus.h ${FACEPLUS_ROOT_DIR}/include) - -if (WIN32) - find_library(FACEPLUS_LIBRARIES faceplus.lib ${FACEPLUS_ROOT_DIR}/win32/) -endif (WIN32) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Faceplus DEFAULT_MSG FACEPLUS_INCLUDE_DIRS FACEPLUS_LIBRARIES) - -mark_as_advanced(FACEPLUS_INCLUDE_DIRS FACEPLUS_LIBRARIES) \ No newline at end of file diff --git a/interface/src/devices/FaceTracker.h b/interface/src/devices/FaceTracker.h index 75954871e5..7c367b7899 100644 --- a/interface/src/devices/FaceTracker.h +++ b/interface/src/devices/FaceTracker.h @@ -18,7 +18,7 @@ #include #include -/// Base class for face trackers (Faceshift, Visage, Faceplus). +/// Base class for face trackers (Faceshift, Visage). class FaceTracker : public QObject { Q_OBJECT From d113b3f85c67a0ec8dd583b18005b6913e79dd8c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 7 Jan 2015 09:48:41 -0800 Subject: [PATCH 33/52] Update getAudio() calls to use DependencyManager instead --- interface/src/Menu.cpp | 4 ++-- interface/src/ui/PreferencesDialog.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 684041c3d9..240b752f71 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -657,7 +657,7 @@ void Menu::loadSettings(QSettings* settings) { _receivedAudioStreamSettings._windowSecondsForDesiredReduction = settings->value("windowSecondsForDesiredReduction", DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION).toInt(); _receivedAudioStreamSettings._repetitionWithFade = settings->value("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE).toBool(); - Audio* audio = Application::getInstance()->getAudio(); + Audio* audio = DependencyManager::get - + 0 @@ -2130,7 +2130,7 @@ - + 0 @@ -2155,7 +2155,7 @@ color:#29967e - Voxels + Octree Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft @@ -2184,7 +2184,7 @@ - Max voxels sent each second + Max packets sent each second 0