From 00171eccbbec29ef55f7c11a94818ea0af781dcd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 16 May 2013 16:23:11 -0700 Subject: [PATCH 01/19] Slight fix for shadows; we were drawing an unnecessary layer of text. --- interface/src/ui/TextRenderer.cpp | 2 +- interface/src/ui/TextRenderer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index df04988bc9..65056799e2 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -139,7 +139,7 @@ const Glyph& TextRenderer::getGlyph(char c) { painter.setFont(_font); if (_effectType == SHADOW_EFFECT) { for (int i = 0; i < _effectThickness; i++) { - painter.drawText(-bounds.x() - i, -bounds.y() + i, ch); + painter.drawText(-bounds.x() - 1 - i, -bounds.y() + 1 + i, ch); } } else if (_effectType == OUTLINE_EFFECT) { QPainterPath path; diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 6df7186d86..643c3ede8c 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -26,7 +26,7 @@ public: enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT }; TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 2); + EffectType effect = NO_EFFECT, int effectThickness = 1); ~TextRenderer(); const QFontMetrics& metrics() const { return _metrics; } From c43847946c12da9761b1df95a45f19c15af23877 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 16 May 2013 20:31:17 -0600 Subject: [PATCH 02/19] Tweaked mouse camera movement a bit --- interface/src/Avatar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 0e7cad3f05..8dc8ee7324 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -280,9 +280,9 @@ bool Avatar::getIsNearInteractingOther() { void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) { // Update yaw based on mouse behavior - const float MOUSE_MOVE_RADIUS = 0.25f; - const float MOUSE_ROTATE_SPEED = 5.0f; - const float MOUSE_PITCH_SPEED = 3.0f; + const float MOUSE_MOVE_RADIUS = 0.15f; + const float MOUSE_ROTATE_SPEED = 3.0f; + const float MOUSE_PITCH_SPEED = 1.5f; const float MAX_YAW_TO_ADD = 180.f; const int TITLE_BAR_HEIGHT = 46; float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f; From 3ed99f40a6f73853e272109fa9fc73d57d4b9542 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 17 May 2013 10:17:21 -0700 Subject: [PATCH 03/19] Working on support for off-axis projection. --- interface/src/Application.cpp | 45 +++++++++++++++++++++++++--- interface/src/Camera.cpp | 10 +++++++ interface/src/Camera.h | 7 +++++ libraries/shared/src/SharedUtil.cpp | 15 ++++++++++ libraries/shared/src/SharedUtil.h | 3 ++ libraries/voxels/src/ViewFrustum.cpp | 11 +++++++ libraries/voxels/src/ViewFrustum.h | 24 ++++++++++----- 7 files changed, 103 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c70b674f38..7d21cdcaa0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -447,7 +447,12 @@ void Application::resizeGL(int width, int height) { } // On window reshape, we need to tell OpenGL about our new setting - gluPerspective(fov,aspectRatio,nearClip,farClip); + float left, right, bottom, top, nearVal, farVal; + glm::vec3 eyeOffset = camera.getEyeOffsetPosition(); + computeOffsetFrustum(fov, aspectRatio, nearClip, farClip, eyeOffset.x, eyeOffset.y, eyeOffset.z, + left, right, bottom, top, nearVal, farVal); + glFrustum(left, right, bottom, top, nearVal, farVal); + glTranslatef(-eyeOffset.x, -eyeOffset.y, -eyeOffset.z); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -542,9 +547,9 @@ void Application::keyPressEvent(QKeyEvent* event) { _audio.startEchoTest(); break; - case Qt::Key_L: - _displayLevels = !_displayLevels; - break; + //case Qt::Key_L: + // _displayLevels = !_displayLevels; + // break; case Qt::Key_E: _myAvatar.setDriveKeys(UP, 1); @@ -598,6 +603,36 @@ void Application::keyPressEvent(QKeyEvent* event) { _myAvatar.setDriveKeys(shifted ? RIGHT : ROT_RIGHT, 1); break; + case Qt::Key_I: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0.001, 0)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + + case Qt::Key_K: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, -0.001, 0)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + + case Qt::Key_J: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + + case Qt::Key_L: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + + case Qt::Key_U: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, 0.001)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + + case Qt::Key_Y: + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, -0.001)); + resizeGL(_glWidget->width(), _glWidget->height()); + break; + default: event->ignore(); break; @@ -1412,6 +1447,8 @@ void Application::loadViewFrustum(ViewFrustum& viewFrustum) { viewFrustum.setFieldOfView(fov); viewFrustum.setNearClip(nearClip); viewFrustum.setFarClip(farClip); + viewFrustum.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition()); + viewFrustum.setEyeOffsetOrientation(_myCamera.getEyeOffsetOrientation()); // Ask the ViewFrustum class to calculate our corners viewFrustum.calculate(); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 4cd66521f0..14eeace22c 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -153,6 +153,16 @@ void Camera::setFarClip (float f) { _frustumNeedsReshape = true; } +void Camera::setEyeOffsetPosition (const glm::vec3& p) { + _eyeOffsetPosition = p; + _frustumNeedsReshape = true; +} + +void Camera::setEyeOffsetOrientation (const glm::quat& o) { + _eyeOffsetOrientation = o; + _frustumNeedsReshape = true; +} + void Camera::initialize() { _needsToInitialize = true; } diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 52c577e88a..2f3ce7f099 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -10,6 +10,7 @@ #include "Orientation.h" #include +#include enum CameraMode { @@ -53,6 +54,8 @@ public: void setAspectRatio ( float a ); void setNearClip ( float n ); void setFarClip ( float f ); + void setEyeOffsetPosition ( const glm::vec3& p); + void setEyeOffsetOrientation ( const glm::quat& o); float getYaw () { return _yaw; } float getPitch () { return _pitch; } @@ -64,6 +67,8 @@ public: float getAspectRatio() { return _aspectRatio; } float getNearClip () { return _nearClip; } float getFarClip () { return _farClip; } + glm::vec3 getEyeOffsetPosition () { return _eyeOffsetPosition; } + glm::quat getEyeOffsetOrientation () { return _eyeOffsetOrientation; } bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped void setFrustumWasReshaped(); // call this after reshaping the view frustum. @@ -79,6 +84,8 @@ private: float _aspectRatio; float _nearClip; float _farClip; + glm::vec3 _eyeOffsetPosition; + glm::quat _eyeOffsetOrientation; float _yaw; float _pitch; float _roll; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index d6820897b8..f30026bfa0 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -409,3 +409,18 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex, return -1; // error case } +// Takes a set of perspective parameters (as one would pass to gluPerspective) and an eye offset (in view space) and writes +// out the parameters to pass to glFrustum to effect the possibly skewed view frustum +void computeOffsetFrustum(float fovy, float aspect, float zNear, float zFar, float xOffset, float yOffset, float zOffset, + float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal) { + // adjust near and far distances by z offset + nearVal = zNear + zOffset; + farVal = zFar + zOffset; + + float hheight = zNear * tanf(fovy * 0.5f * PI_OVER_180); + top = hheight - yOffset; + bottom = -hheight - yOffset; + float hwidth = aspect * hheight; + left = -hwidth - xOffset; + right = hwidth - xOffset; +} diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 98baa5488a..721f6aff97 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -78,4 +78,7 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex, void** valueArray, float* keyArray, int* originalIndexArray, int currentCount, int maxCount); +void computeOffsetFrustum(float fovy, float aspect, float zNear, float zFar, float xOffset, float yOffset, float zOffset, + float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal); + #endif /* defined(__hifi__SharedUtil__) */ diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 25022ae521..355729e762 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -9,6 +9,7 @@ // #include "ViewFrustum.h" +#include "SharedUtil.h" #include "voxels_Log.h" using voxels_lib::printLog; @@ -52,6 +53,16 @@ void ViewFrustum::calculate() { glm::vec3 front = _direction; + float left, right, bottom, top, nearVal, farVal; + computeOffsetFrustum(_fieldOfView, _aspectRatio, _nearClip, _farClip, + _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z, + left, right, bottom, top, nearVal, farVal); + + _nearHeight = top - bottom; + _nearWidth = right - left; + _farHeight = _nearHeight * (farVal / nearVal); + _farWidth = _nearWidth * (farVal / nearVal); + // Calculating field of view. float fovInRadians = _fieldOfView * PI_OVER_180; diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index aadb1f86e8..dae62352b0 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -12,6 +12,7 @@ #define __hifi__ViewFrustum__ #include +#include #include "Plane.h" #include "AABox.h" @@ -29,6 +30,8 @@ private: float _aspectRatio; float _nearClip; float _farClip; + glm::vec3 _eyeOffsetPosition; + glm::quat _eyeOffsetOrientation; // Calculated values float _nearHeight; @@ -63,16 +66,21 @@ public: const glm::vec3& getRight() const { return _right; }; // setters for lens attributes - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } + void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; } + void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; } + // getters for lens attributes - float getFieldOfView() const { return _fieldOfView; }; - float getAspectRatio() const { return _aspectRatio; }; - float getNearClip() const { return _nearClip; }; - float getFarClip() const { return _farClip; }; + float getFieldOfView() const { return _fieldOfView; }; + float getAspectRatio() const { return _aspectRatio; }; + float getNearClip() const { return _nearClip; }; + float getFarClip() const { return _farClip; }; + const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }; + const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation;}; const glm::vec3& getFarCenter() const { return _farCenter; }; const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; From d9cc07cf172b4f2f36869af1dd0f188840fb47bd Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sat, 18 May 2013 12:33:21 -0700 Subject: [PATCH 04/19] Working on audio echo cancellation --- interface/src/Application.cpp | 2 +- interface/src/Audio.cpp | 40 ++++++++++++++++++++--------------- interface/src/Audio.h | 10 ++++++--- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c70b674f38..7a9faa54f6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1662,7 +1662,7 @@ void Application::displayOverlay() { #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); _audioScope.render(20, _glWidget->height() - 200); - //_audio.renderEchoCompare(); // PER: Will turn back on to further test echo + _audio.renderEchoCompare(); // PER: Will turn back on to further test echo #endif //noiseTest(_glWidget->width(), _glWidget->height()); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 5bca301552..c64701d67e 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -99,12 +99,21 @@ int audioCallback (const void* inputBuffer, parentAudio->_scope->addSamples(2, outputRight, PACKET_LENGTH_SAMPLES_PER_CHANNEL); // if needed, add input/output data to echo analysis buffers - if (parentAudio->_isGatheringEchoFrames) { - memcpy(parentAudio->_echoInputSamples, inputLeft, + if (parentAudio->_echoInputFrameCountdown > 0) { + if (--parentAudio->_echoInputFrameCountdown == 0) { + memcpy(parentAudio->_echoInputSamples, inputLeft, PACKET_LENGTH_SAMPLES_PER_CHANNEL * sizeof(int16_t)); + parentAudio->_echoInputFrameCountdown = 0; + printLog("got input\n"); + } + } + + if (parentAudio->_isGatheringEchoOutputFrames) { memcpy(parentAudio->_echoOutputSamples, outputLeft, PACKET_LENGTH_SAMPLES_PER_CHANNEL * sizeof(int16_t)); - parentAudio->addedPingFrame(); + parentAudio->_isGatheringEchoOutputFrames = false; + parentAudio->_echoInputFrameCountdown = 2; + printLog("got output\n"); } if (inputLeft != NULL) { @@ -273,7 +282,10 @@ int audioCallback (const void* inputBuffer, for (int s = 0; s < PACKET_LENGTH_SAMPLES_PER_CHANNEL; s++) { outputLeft[s] = outputRight[s] = (int16_t)(sinf((float) s / PING_PITCH) * PING_VOLUME); } - parentAudio->_isGatheringEchoFrames = true; + printLog("Send echo ping\n"); + parentAudio->_isSendingEchoPing = false; + parentAudio->_isGatheringEchoOutputFrames = true; + } gettimeofday(&parentAudio->_lastCallbackTime, NULL); return paContinue; @@ -293,6 +305,9 @@ Audio::Audio(Oscilloscope* scope) : _scope(scope), _averagedLatency(0.0), _measuredJitter(0), + _jitterBufferLengthMsecs(12.0), + _jitterBufferSamples(_jitterBufferLengthMsecs * + NUM_AUDIO_CHANNELS * (SAMPLE_RATE / 1000.0)), _wasStarved(0), _lastInputLoudness(0), _mixerLoopbackFlag(false), @@ -303,8 +318,8 @@ Audio::Audio(Oscilloscope* scope) : _packetsReceivedThisPlayback(0), _shouldStartEcho(false), _isSendingEchoPing(false), - _echoPingFrameCount(0), - _isGatheringEchoFrames(false) + _echoInputFrameCountdown(0), + _isGatheringEchoOutputFrames(false) { outputPortAudioError(Pa_Initialize()); outputPortAudioError(Pa_OpenDefaultStream(&_stream, @@ -376,20 +391,11 @@ void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) { void Audio::startEchoTest() { _shouldStartEcho = true; - _echoPingFrameCount = 0; _isSendingEchoPing = true; - _isGatheringEchoFrames = false; + _isGatheringEchoOutputFrames = false; + } -void Audio::addedPingFrame() { - const int ECHO_PING_FRAMES = 1; - _echoPingFrameCount++; - if (_echoPingFrameCount == ECHO_PING_FRAMES) { - _isGatheringEchoFrames = false; - _isSendingEchoPing = false; - //startEchoTest(); - } -} void Audio::analyzeEcho(int16_t* inputBuffer, int16_t* outputBuffer, int numSamples) { // Compare output and input streams, looking for evidence of correlation needing echo cancellation // diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 2eae70bb34..34a342a1d4 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -38,7 +38,6 @@ public: void addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes); void startEchoTest(); - void addedPingFrame(); void renderEchoCompare(); private: @@ -49,6 +48,8 @@ private: timeval _lastReceiveTime; float _averagedLatency; float _measuredJitter; + float _jitterBufferLengthMsecs; + short _jitterBufferSamples; int _wasStarved; float _lastInputLoudness; bool _mixerLoopbackFlag; @@ -57,12 +58,15 @@ private: int _totalPacketsReceived; timeval _firstPlaybackTime; int _packetsReceivedThisPlayback; + // Echo Analysis bool _shouldStartEcho; bool _isSendingEchoPing; - int _echoPingFrameCount; int16_t* _echoInputSamples; int16_t* _echoOutputSamples; - bool _isGatheringEchoFrames; + int _echoInputFrameCountdown; + bool _isGatheringEchoOutputFrames; + + // give access to AudioData class from audioCallback friend int audioCallback (const void*, void*, unsigned long, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*); From dd3e8d524a6c6fde1be4c723d4696a3732e85b4f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sun, 19 May 2013 18:37:21 -0700 Subject: [PATCH 05/19] Support for eye offset position/orientation in camera/frustum. --- interface/src/Application.cpp | 91 +++++--- interface/src/Application.h | 2 +- interface/src/Environment.cpp | 10 - libraries/shared/src/SharedUtil.cpp | 15 -- libraries/shared/src/SharedUtil.h | 3 - libraries/voxels/src/ViewFrustum.cpp | 296 ++++++++++++++++----------- libraries/voxels/src/ViewFrustum.h | 17 +- 7 files changed, 257 insertions(+), 177 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5f6de04180..9563b62e58 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -18,6 +18,8 @@ #include #endif +#include + #include #include #include @@ -356,6 +358,14 @@ void Application::paintGL() { whichCamera = _viewFrustumOffsetCamera; } + // transform by eye offset + + glm::vec3 eyeOffsetPos = whichCamera.getEyeOffsetPosition(); + glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); + glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); + glRotatef(-glm::angle(eyeOffsetOrient), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z); + glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z); + // transform view according to whichCamera // could be myCamera (if in normal mode) // or could be viewFrustumOffsetCamera if in offset mode @@ -451,11 +461,10 @@ void Application::resizeGL(int width, int height) { // On window reshape, we need to tell OpenGL about our new setting float left, right, bottom, top, nearVal, farVal; - glm::vec3 eyeOffset = camera.getEyeOffsetPosition(); - computeOffsetFrustum(fov, aspectRatio, nearClip, farClip, eyeOffset.x, eyeOffset.y, eyeOffset.z, - left, right, bottom, top, nearVal, farVal); + glm::vec4 nearClipPlane, farClipPlane; + loadViewFrustum(camera, _viewFrustum); + _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); glFrustum(left, right, bottom, top, nearVal, farVal); - glTranslatef(-eyeOffset.x, -eyeOffset.y, -eyeOffset.z); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -607,32 +616,62 @@ void Application::keyPressEvent(QKeyEvent* event) { break; case Qt::Key_I: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0.001, 0)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(0.002f, 0, 0)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0.001, 0)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; case Qt::Key_K: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, -0.001, 0)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(-0.002f, 0, 0)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, -0.001, 0)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; case Qt::Key_J: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(0, 0.002f, 0)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; case Qt::Key_L: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(0, -0.002f, 0)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; case Qt::Key_U: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, 0.001)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(0, 0, -0.002f)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, -0.001)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; case Qt::Key_Y: - _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, -0.001)); + if (shifted) { + _myCamera.setEyeOffsetOrientation(glm::normalize( + glm::quat(glm::vec3(0, 0, 0.002f)) * _myCamera.getEyeOffsetOrientation())); + } else { + _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0, 0, 0.001)); + } resizeGL(_glWidget->width(), _glWidget->height()); break; @@ -1048,12 +1087,12 @@ void Application::doFalseRandomizeEveryOtherVoxelColors() { } void Application::doFalseColorizeByDistance() { - loadViewFrustum(_viewFrustum); + loadViewFrustum(_myCamera, _viewFrustum); _voxels.falseColorizeDistanceFromView(&_viewFrustum); } void Application::doFalseColorizeInView() { - loadViewFrustum(_viewFrustum); + loadViewFrustum(_myCamera, _viewFrustum); // we probably want to make sure the viewFrustum is initialized first _voxels.falseColorizeInView(&_viewFrustum); } @@ -1354,7 +1393,7 @@ void Application::updateAvatar(float deltaTime) { // We could optimize this to not actually load the viewFrustum, since we don't // actually need to calculate the view frustum planes to send these details // to the server. - loadViewFrustum(_viewFrustum); + loadViewFrustum(_myCamera, _viewFrustum); _myAvatar.setCameraPosition(_viewFrustum.getPosition()); _myAvatar.setCameraDirection(_viewFrustum.getDirection()); _myAvatar.setCameraUp(_viewFrustum.getUp()); @@ -1406,7 +1445,7 @@ void Application::updateAvatar(float deltaTime) { // Description: this will load the view frustum bounds for EITHER the head // or the "myCamera". // -void Application::loadViewFrustum(ViewFrustum& viewFrustum) { +void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { // We will use these below, from either the camera or head vectors calculated above glm::vec3 position; glm::vec3 direction; @@ -1416,16 +1455,16 @@ void Application::loadViewFrustum(ViewFrustum& viewFrustum) { // Camera or Head? if (_cameraFrustum->isChecked()) { - position = _myCamera.getPosition(); + position = camera.getPosition(); } else { position = _myAvatar.getHeadPosition(); } - fov = _myCamera.getFieldOfView(); - nearClip = _myCamera.getNearClip(); - farClip = _myCamera.getFarClip(); + fov = camera.getFieldOfView(); + nearClip = camera.getNearClip(); + farClip = camera.getFarClip(); - Orientation o = _myCamera.getOrientation(); + Orientation o = camera.getOrientation(); direction = o.getFront(); up = o.getUp(); @@ -1450,8 +1489,8 @@ void Application::loadViewFrustum(ViewFrustum& viewFrustum) { viewFrustum.setFieldOfView(fov); viewFrustum.setNearClip(nearClip); viewFrustum.setFarClip(farClip); - viewFrustum.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition()); - viewFrustum.setEyeOffsetOrientation(_myCamera.getEyeOffsetOrientation()); + viewFrustum.setEyeOffsetPosition(camera.getEyeOffsetPosition()); + viewFrustum.setEyeOffsetOrientation(camera.getEyeOffsetOrientation()); // Ask the ViewFrustum class to calculate our corners viewFrustum.calculate(); @@ -1862,12 +1901,12 @@ void Application::displayStats() { // * Far Plane - draws only the far plane void Application::renderViewFrustum(ViewFrustum& viewFrustum) { // Load it with the latest details! - loadViewFrustum(viewFrustum); + loadViewFrustum(_myCamera, viewFrustum); - glm::vec3 position = viewFrustum.getPosition(); - glm::vec3 direction = viewFrustum.getDirection(); - glm::vec3 up = viewFrustum.getUp(); - glm::vec3 right = viewFrustum.getRight(); + 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); diff --git a/interface/src/Application.h b/interface/src/Application.h index 8a949fa183..da3898ab9f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -105,7 +105,7 @@ private: void init(); void updateAvatar(float deltaTime); - void loadViewFrustum(ViewFrustum& viewFrustum); + void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum); void displayOculus(Camera& whichCamera); void displaySide(Camera& whichCamera); diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index 8c16c17479..fb7c8c7271 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -25,18 +25,8 @@ void Environment::renderAtmosphere(Camera& camera) { glPushMatrix(); glTranslatef(getAtmosphereCenter().x, getAtmosphereCenter().y, getAtmosphereCenter().z); - // use the camera distance to reset the near and far distances to keep the atmosphere in the frustum - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - float projection[16]; - glGetFloatv(GL_PROJECTION_MATRIX, projection); glm::vec3 relativeCameraPos = camera.getPosition() - getAtmosphereCenter(); float height = glm::length(relativeCameraPos); - float near = camera.getNearClip(), far = height + getAtmosphereOuterRadius(); - projection[10] = (far + near) / (near - far); - projection[14] = (2.0f * far * near) / (near - far); - glLoadMatrixf(projection); // use the appropriate shader depending on whether we're inside or outside ProgramObject* program; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index f30026bfa0..d6820897b8 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -409,18 +409,3 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex, return -1; // error case } -// Takes a set of perspective parameters (as one would pass to gluPerspective) and an eye offset (in view space) and writes -// out the parameters to pass to glFrustum to effect the possibly skewed view frustum -void computeOffsetFrustum(float fovy, float aspect, float zNear, float zFar, float xOffset, float yOffset, float zOffset, - float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal) { - // adjust near and far distances by z offset - nearVal = zNear + zOffset; - farVal = zFar + zOffset; - - float hheight = zNear * tanf(fovy * 0.5f * PI_OVER_180); - top = hheight - yOffset; - bottom = -hheight - yOffset; - float hwidth = aspect * hheight; - left = -hwidth - xOffset; - right = hwidth - xOffset; -} diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 721f6aff97..98baa5488a 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -78,7 +78,4 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex, void** valueArray, float* keyArray, int* originalIndexArray, int currentCount, int maxCount); -void computeOffsetFrustum(float fovy, float aspect, float zNear, float zFar, float xOffset, float yOffset, float zOffset, - float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal); - #endif /* defined(__hifi__SharedUtil__) */ diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 355729e762..778928f01b 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -8,11 +8,16 @@ // // +#include + +#include + #include "ViewFrustum.h" #include "SharedUtil.h" #include "voxels_Log.h" using voxels_lib::printLog; +using namespace std; ViewFrustum::ViewFrustum() : _position(glm::vec3(0,0,0)), @@ -23,10 +28,6 @@ ViewFrustum::ViewFrustum() : _aspectRatio(1.0), _nearClip(0.1), _farClip(500.0), - _nearHeight(0.0), - _nearWidth(0.0), - _farHeight(0.0), - _farWidth(0.0), _farCenter(glm::vec3(0,0,0)), _farTopLeft(glm::vec3(0,0,0)), _farTopRight(glm::vec3(0,0,0)), @@ -42,77 +43,76 @@ ViewFrustum::ViewFrustum() : // ViewFrustum::calculateViewFrustum() // // Description: this will calculate the view frustum bounds for a given position -// and direction +// and direction // // Notes on how/why this works: // http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/ // void ViewFrustum::calculate() { + // compute the off-axis frustum parameters as we would for glFrustum + float left, right, bottom, top, nearVal, farVal; + glm::vec4 nearClipPlane, farClipPlane; + computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); + + // start with the corners of the near frustum window + glm::vec3 topLeft(left, top, -nearVal); + glm::vec3 topRight(right, top, -nearVal); + glm::vec3 bottomLeft(left, bottom, -nearVal); + glm::vec3 bottomRight(right, bottom, -nearVal); + + // find the intersections of the rays through the corners with the clip planes in view space + _farTopLeft = topLeft * (-farClipPlane.w / glm::dot(topLeft, glm::vec3(farClipPlane))); + _farTopRight = topRight * (-farClipPlane.w / glm::dot(topRight, glm::vec3(farClipPlane))); + _farBottomLeft = bottomLeft * (-farClipPlane.w / glm::dot(bottomLeft, glm::vec3(farClipPlane))); + _farBottomRight = bottomRight * (-farClipPlane.w / glm::dot(bottomRight, glm::vec3(farClipPlane))); + _nearTopLeft = topLeft * (-nearClipPlane.w / glm::dot(topLeft, glm::vec3(nearClipPlane))); + _nearTopRight = topRight * (-nearClipPlane.w / glm::dot(topRight, glm::vec3(nearClipPlane))); + _nearBottomLeft = bottomLeft * (-nearClipPlane.w / glm::dot(bottomLeft, glm::vec3(nearClipPlane))); + _nearBottomRight = bottomRight * (-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))); + + // compute the offset position and axes in world space + _offsetPosition = _position + _eyeOffsetPosition.x * _right + _eyeOffsetPosition.y * _up - + _eyeOffsetPosition.z * _direction; + _offsetDirection = _eyeOffsetOrientation * _direction; + _offsetUp = _eyeOffsetOrientation * _up; + _offsetRight = _eyeOffsetOrientation * _right; + + // now transform the intersections to world space + _farTopLeft = _offsetPosition + _farTopLeft.x * _offsetRight + _farTopLeft.y * _offsetUp - + _farTopLeft.z * _offsetDirection; + _farTopRight = _offsetPosition + _farTopRight.x * _offsetRight + _farTopRight.y * _offsetUp - + _farTopRight.z * _offsetDirection; + _farBottomLeft = _offsetPosition + _farBottomLeft.x * _offsetRight + _farBottomLeft.y * _offsetUp - + _farBottomLeft.z * _offsetDirection; + _farBottomRight = _offsetPosition + _farBottomRight.x * _offsetRight + _farBottomRight.y * _offsetUp - + _farBottomRight.z * _offsetDirection; + _nearTopLeft = _offsetPosition + _nearTopLeft.x * _offsetRight + _nearTopLeft.y * _offsetUp - + _nearTopLeft.z * _offsetDirection; + _nearTopRight = _offsetPosition + _nearTopRight.x * _offsetRight + _nearTopRight.y * _offsetUp - + _nearTopRight.z * _offsetDirection; + _nearBottomLeft = _offsetPosition + _nearBottomLeft.x * _offsetRight + _nearBottomLeft.y * _offsetUp - + _nearBottomLeft.z * _offsetDirection; + _nearBottomRight = _offsetPosition + _nearBottomRight.x * _offsetRight + _nearBottomRight.y * _offsetUp - + _nearBottomRight.z * _offsetDirection; + + // compute the six planes + // The planes are defined such that the normal points towards the inside of the view frustum. + // Testing if an object is inside the view frustum is performed by computing on which side of + // the plane the object resides. This can be done computing the signed distance from the point + // to the plane. If it is on the side that the normal is pointing, i.e. the signed distance + // is positive, then it is on the right side of the respective plane. If an object is on the + // right side of all six planes then the object is inside the frustum. - static const double PI_OVER_180 = 3.14159265359 / 180.0; // would be better if this was in a shared location - - glm::vec3 front = _direction; - - float left, right, bottom, top, nearVal, farVal; - computeOffsetFrustum(_fieldOfView, _aspectRatio, _nearClip, _farClip, - _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z, - left, right, bottom, top, nearVal, farVal); - - _nearHeight = top - bottom; - _nearWidth = right - left; - _farHeight = _nearHeight * (farVal / nearVal); - _farWidth = _nearWidth * (farVal / nearVal); - - // Calculating field of view. - float fovInRadians = _fieldOfView * PI_OVER_180; - - float twoTimesTanHalfFOV = 2.0f * tan(fovInRadians/2.0f); - - // Do we need this? - //tang = (float)tan(ANG2RAD * angle * 0.5) ; - - float nearClip = _nearClip; - float farClip = _farClip; - - _nearHeight = (twoTimesTanHalfFOV * nearClip); - _nearWidth = _nearHeight * _aspectRatio; - _farHeight = (twoTimesTanHalfFOV * farClip); - _farWidth = _farHeight * _aspectRatio; - - float farHalfHeight = (_farHeight * 0.5f); - float farHalfWidth = (_farWidth * 0.5f); - _farCenter = _position+front * farClip; - _farTopLeft = _farCenter + (_up * farHalfHeight) - (_right * farHalfWidth); - _farTopRight = _farCenter + (_up * farHalfHeight) + (_right * farHalfWidth); - _farBottomLeft = _farCenter - (_up * farHalfHeight) - (_right * farHalfWidth); - _farBottomRight = _farCenter - (_up * farHalfHeight) + (_right * farHalfWidth); - - float nearHalfHeight = (_nearHeight * 0.5f); - float nearHalfWidth = (_nearWidth * 0.5f); - _nearCenter = _position+front * nearClip; - _nearTopLeft = _nearCenter + (_up * nearHalfHeight) - (_right * nearHalfWidth); - _nearTopRight = _nearCenter + (_up * nearHalfHeight) + (_right * nearHalfWidth); - _nearBottomLeft = _nearCenter - (_up * nearHalfHeight) - (_right * nearHalfWidth); - _nearBottomRight = _nearCenter - (_up * nearHalfHeight) + (_right * nearHalfWidth); - - // compute the six planes - // The planes are defined such that the normal points towards the inside of the view frustum. - // Testing if an object is inside the view frustum is performed by computing on which side of - // the plane the object resides. This can be done computing the signed distance from the point - // to the plane. If it is on the side that the normal is pointing, i.e. the signed distance - // is positive, then it is on the right side of the respective plane. If an object is on the - // right side of all six planes then the object is inside the frustum. - - // the function set3Points assumes that the points are given in counter clockwise order, assume you - // are inside the frustum, facing the plane. Start with any point, and go counter clockwise for - // three consecutive points - - _planes[TOP_PLANE ].set3Points(_nearTopRight,_nearTopLeft,_farTopLeft); - _planes[BOTTOM_PLANE].set3Points(_nearBottomLeft,_nearBottomRight,_farBottomRight); - _planes[LEFT_PLANE ].set3Points(_nearBottomLeft,_farBottomLeft,_farTopLeft); - _planes[RIGHT_PLANE ].set3Points(_farBottomRight,_nearBottomRight,_nearTopRight); - _planes[NEAR_PLANE ].set3Points(_nearBottomRight,_nearBottomLeft,_nearTopLeft); - _planes[FAR_PLANE ].set3Points(_farBottomLeft,_farBottomRight,_farTopRight); + // the function set3Points assumes that the points are given in counter clockwise order, assume you + // are inside the frustum, facing the plane. Start with any point, and go counter clockwise for + // three consecutive points + + _planes[TOP_PLANE ].set3Points(_nearTopRight,_nearTopLeft,_farTopLeft); + _planes[BOTTOM_PLANE].set3Points(_nearBottomLeft,_nearBottomRight,_farBottomRight); + _planes[LEFT_PLANE ].set3Points(_nearBottomLeft,_farBottomLeft,_farTopLeft); + _planes[RIGHT_PLANE ].set3Points(_farBottomRight,_nearBottomRight,_nearTopRight); + _planes[NEAR_PLANE ].set3Points(_nearBottomRight,_nearBottomLeft,_nearTopLeft); + _planes[FAR_PLANE ].set3Points(_farBottomLeft,_farBottomRight,_farTopRight); } @@ -124,34 +124,35 @@ void ViewFrustum::dump() const { printLog("right.x=%f, right.y=%f, right.z=%f\n", _right.x, _right.y, _right.z); printLog("farDist=%f\n", _farClip); - printLog("farHeight=%f\n", _farHeight); - printLog("farWidth=%f\n", _farWidth); printLog("nearDist=%f\n", _nearClip); - printLog("nearHeight=%f\n", _nearHeight); - printLog("nearWidth=%f\n", _nearWidth); + + printLog("eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z); + + printLog("eyeOffsetOrientation=%f,%f,%f,%f\n", _eyeOffsetOrientation.x, _eyeOffsetOrientation.y, + _eyeOffsetOrientation.z, _eyeOffsetOrientation.w); printLog("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n", - _farCenter.x, _farCenter.y, _farCenter.z); + _farCenter.x, _farCenter.y, _farCenter.z); printLog("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n", - _farTopLeft.x, _farTopLeft.y, _farTopLeft.z); + _farTopLeft.x, _farTopLeft.y, _farTopLeft.z); printLog("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n", - _farTopRight.x, _farTopRight.y, _farTopRight.z); + _farTopRight.x, _farTopRight.y, _farTopRight.z); printLog("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n", - _farBottomLeft.x, _farBottomLeft.y, _farBottomLeft.z); + _farBottomLeft.x, _farBottomLeft.y, _farBottomLeft.z); printLog("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n", - _farBottomRight.x, _farBottomRight.y, _farBottomRight.z); + _farBottomRight.x, _farBottomRight.y, _farBottomRight.z); printLog("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n", - _nearCenter.x, _nearCenter.y, _nearCenter.z); + _nearCenter.x, _nearCenter.y, _nearCenter.z); printLog("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n", - _nearTopLeft.x, _nearTopLeft.y, _nearTopLeft.z); + _nearTopLeft.x, _nearTopLeft.y, _nearTopLeft.z); printLog("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n", - _nearTopRight.x, _nearTopRight.y, _nearTopRight.z); + _nearTopRight.x, _nearTopRight.y, _nearTopRight.z); printLog("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n", - _nearBottomLeft.x, _nearBottomLeft.y, _nearBottomLeft.z); + _nearBottomLeft.x, _nearBottomLeft.y, _nearBottomLeft.z); printLog("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n", - _nearBottomRight.x, _nearBottomRight.y, _nearBottomRight.z); + _nearBottomRight.x, _nearBottomRight.y, _nearBottomRight.z); } @@ -174,30 +175,30 @@ ViewFrustum::location ViewFrustum::pointInFrustum(const glm::vec3& point) const //printf("ViewFrustum::pointInFrustum() point=%f,%f,%f\n",point.x,point.y,point.z); //dump(); - ViewFrustum::location result = INSIDE; - for(int i=0; i < 6; i++) { - float distance = _planes[i].distance(point); + ViewFrustum::location result = INSIDE; + for(int i=0; i < 6; i++) { + float distance = _planes[i].distance(point); //printf("plane[%d] %s -- distance=%f \n",i,debugPlaneName(i),distance); - - if (distance < 0) { - return OUTSIDE; - } - } - return(result); + + if (distance < 0) { + return OUTSIDE; + } + } + return(result); } ViewFrustum::location ViewFrustum::sphereInFrustum(const glm::vec3& center, float radius) const { - ViewFrustum::location result = INSIDE; - float distance; - for(int i=0; i < 6; i++) { - distance = _planes[i].distance(center); - if (distance < -radius) - return OUTSIDE; - else if (distance < radius) - result = INTERSECT; - } - return(result); + ViewFrustum::location result = INSIDE; + float distance; + for(int i=0; i < 6; i++) { + distance = _planes[i].distance(center); + if (distance < -radius) + return OUTSIDE; + else if (distance < radius) + result = INTERSECT; + } + return(result); } @@ -205,8 +206,8 @@ ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const { //printf("ViewFrustum::boxInFrustum() box.corner=%f,%f,%f x=%f\n", // box.getCorner().x,box.getCorner().y,box.getCorner().z,box.getSize().x); - ViewFrustum::location result = INSIDE; - for(int i=0; i < 6; i++) { + ViewFrustum::location result = INSIDE; + for(int i=0; i < 6; i++) { //printf("plane[%d] -- point(%f,%f,%f) normal(%f,%f,%f) d=%f \n",i, // _planes[i].getPoint().x, _planes[i].getPoint().y, _planes[i].getPoint().z, @@ -214,26 +215,26 @@ ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const { // _planes[i].getDCoefficient() //); - glm::vec3 normal = _planes[i].getNormal(); - glm::vec3 boxVertexP = box.getVertexP(normal); - float planeToBoxVertexPDistance = _planes[i].distance(boxVertexP); + glm::vec3 normal = _planes[i].getNormal(); + glm::vec3 boxVertexP = box.getVertexP(normal); + float planeToBoxVertexPDistance = _planes[i].distance(boxVertexP); - glm::vec3 boxVertexN = box.getVertexN(normal); - float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN); - + glm::vec3 boxVertexN = box.getVertexN(normal); + float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN); + //printf("plane[%d] normal=(%f,%f,%f) bVertexP=(%f,%f,%f) planeToBoxVertexPDistance=%f boxVertexN=(%f,%f,%f) planeToBoxVertexNDistance=%f\n",i, // normal.x,normal.y,normal.z, // boxVertexP.x,boxVertexP.y,boxVertexP.z,planeToBoxVertexPDistance, // boxVertexN.x,boxVertexN.y,boxVertexN.z,planeToBoxVertexNDistance // ); - if (planeToBoxVertexPDistance < 0) { - return OUTSIDE; - } else if (planeToBoxVertexNDistance < 0) { - result = INTERSECT; - } - } - return(result); + if (planeToBoxVertexPDistance < 0) { + return OUTSIDE; + } else if (planeToBoxVertexNDistance < 0) { + result = INTERSECT; + } + } + return(result); } bool ViewFrustum::matches(const ViewFrustum& compareTo) const { @@ -245,7 +246,9 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo) const { compareTo._fieldOfView == _fieldOfView && compareTo._aspectRatio == _aspectRatio && compareTo._nearClip == _nearClip && - compareTo._farClip == _farClip; + compareTo._farClip == _farClip && + compareTo._eyeOffsetPosition == _eyeOffsetPosition && + compareTo._eyeOffsetOrientation == _eyeOffsetOrientation; if (!result && debug) { printLog("ViewFrustum::matches()... result=%s\n", (result ? "yes" : "no")); @@ -277,6 +280,15 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo) const { printLog("%s -- compareTo._farClip=%f _farClip=%f\n", (compareTo._farClip == _farClip ? "MATCHES " : "NO MATCH"), compareTo._farClip, _farClip); + printLog("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n", + (compareTo._eyeOffsetPosition == _eyeOffsetPosition ? "MATCHES " : "NO MATCH"), + compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z, + _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z); + printLog("%s -- compareTo._eyeOffsetOrientation=%f,%f,%f,%f _eyeOffsetOrientation=%f,%f,%f,%f\n", + (compareTo._eyeOffsetOrientation == _eyeOffsetOrientation ? "MATCHES " : "NO MATCH"), + compareTo._eyeOffsetOrientation.x, compareTo._eyeOffsetOrientation.y, + compareTo._eyeOffsetOrientation.z, compareTo._eyeOffsetOrientation.w, + _eyeOffsetOrientation.x, _eyeOffsetOrientation.y, _eyeOffsetOrientation.z, _eyeOffsetOrientation.w); } return result; } @@ -288,6 +300,51 @@ void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction = glm::normalize(origin - _position); } +void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, float& far, + glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { + // compute our dimensions the usual way + float hheight = _nearClip * tanf(_fieldOfView * 0.5f * PI_OVER_180); + float hwidth = _aspectRatio * hheight; + + // get our frustum corners in view space + glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition); + glm::vec4 corners[8]; + float farScale = _farClip / _nearClip; + corners[0] = eyeMatrix * glm::vec4(-hwidth, -hheight, -_nearClip, 1.0f); + corners[1] = eyeMatrix * glm::vec4(hwidth, -hheight, -_nearClip, 1.0f); + corners[2] = eyeMatrix * glm::vec4(hwidth, hheight, -_nearClip, 1.0f); + corners[3] = eyeMatrix * glm::vec4(-hwidth, hheight, -_nearClip, 1.0f); + corners[4] = eyeMatrix * glm::vec4(-hwidth * farScale, -hheight * farScale, -_farClip, 1.0f); + corners[5] = eyeMatrix * glm::vec4(hwidth * farScale, -hheight * farScale, -_farClip, 1.0f); + corners[6] = eyeMatrix * glm::vec4(hwidth * farScale, hheight * farScale, -_farClip, 1.0f); + corners[7] = eyeMatrix * glm::vec4(-hwidth * farScale, hheight * farScale, -_farClip, 1.0f); + + // find the minimum and maximum z values, which will be our near and far clip distances + near = FLT_MAX; + far = -FLT_MAX; + for (int i = 0; i < 8; i++) { + near = min(near, -corners[i].z); + far = max(far, -corners[i].z); + } + + // get the near/far normal and use it to find the clip planes + glm::vec4 normal = eyeMatrix * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f); + nearClipPlane = glm::vec4(-normal.x, -normal.y, -normal.z, glm::dot(normal, corners[0])); + farClipPlane = glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, corners[4])); + + // get the extents at Z = -near + left = FLT_MAX; + right = -FLT_MAX; + bottom = FLT_MAX; + top = -FLT_MAX; + for (int i = 0; i < 4; i++) { + glm::vec4 intersection = corners[i] * (-near / corners[i].z); + left = min(left, intersection.x); + right = max(right, intersection.x); + bottom = min(bottom, intersection.y); + top = max(top, intersection.y); + } +} void ViewFrustum::printDebugDetails() const { printLog("ViewFrustum::printDebugDetails()... \n"); @@ -299,5 +356,8 @@ void ViewFrustum::printDebugDetails() const { printLog("_aspectRatio=%f\n", _aspectRatio); printLog("_nearClip=%f\n", _nearClip); printLog("_farClip=%f\n", _farClip); + printLog("_eyeOffsetPosition=%f,%f,%f\n", _eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z ); + printLog("_eyeOffsetOrientation=%f,%f,%f,%f\n", _eyeOffsetOrientation.x, _eyeOffsetOrientation.y, _eyeOffsetOrientation.z, + _eyeOffsetOrientation.w ); } diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index dae62352b0..772371c7df 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -34,10 +34,10 @@ private: glm::quat _eyeOffsetOrientation; // Calculated values - float _nearHeight; - float _nearWidth; - float _farHeight; - float _farWidth; + glm::vec3 _offsetPosition; + glm::vec3 _offsetDirection; + glm::vec3 _offsetUp; + glm::vec3 _offsetRight; glm::vec3 _farCenter; glm::vec3 _farTopLeft; glm::vec3 _farTopRight; @@ -82,6 +82,11 @@ public: const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }; const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation;}; + const glm::vec3& getOffsetPosition() const { return _offsetPosition; }; + const glm::vec3& getOffsetDirection() const { return _offsetDirection;}; + const glm::vec3& getOffsetUp() const { return _offsetUp; }; + const glm::vec3& getOffsetRight() const { return _offsetRight; }; + const glm::vec3& getFarCenter() const { return _farCenter; }; const glm::vec3& getFarTopLeft() const { return _farTopLeft; }; const glm::vec3& getFarTopRight() const { return _farTopRight; }; @@ -109,8 +114,12 @@ public: // some frustum comparisons bool matches(const ViewFrustum& compareTo) const; bool matches(const ViewFrustum* compareTo) const { return matches(*compareTo); }; + void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const; + void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, float& far, + glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; + void printDebugDetails() const; }; From 06242a82c4f0b0320f03014fefaa9c4ae18db2a8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 19 May 2013 20:53:46 -0700 Subject: [PATCH 06/19] fixed Philip's no animation problem --- libraries/avatars/src/AvatarData.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index f131f82c85..a11c2da260 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -50,7 +50,9 @@ public: _cameraFarClip(0.0f), _keyState(NO_KEY_DOWN), _wantResIn(false), - _wantColor(true) { }; + _wantColor(true), + _wantDelta(false) + { }; ~AvatarData(); From 0c03f6694848bd161fa09698fea5f2ed8e89f963 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sun, 19 May 2013 22:32:55 -0700 Subject: [PATCH 07/19] Fixed the frustum computation, fixed a bug in Plane. --- libraries/voxels/src/Plane.cpp | 2 +- libraries/voxels/src/ViewFrustum.cpp | 56 ++++++++++++---------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/libraries/voxels/src/Plane.cpp b/libraries/voxels/src/Plane.cpp index a5dc9a93bf..d999306794 100755 --- a/libraries/voxels/src/Plane.cpp +++ b/libraries/voxels/src/Plane.cpp @@ -28,7 +28,7 @@ void Plane::set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 // this will be perpendicular to both lines _normal = glm::cross(linev1v2,linev1v3); - glm::normalize(_normal); + _normal = glm::normalize(_normal); // this is a point on the plane _point = v2; diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 778928f01b..cce3eac76f 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -60,40 +60,32 @@ void ViewFrustum::calculate() { glm::vec3 bottomLeft(left, bottom, -nearVal); glm::vec3 bottomRight(right, bottom, -nearVal); - // find the intersections of the rays through the corners with the clip planes in view space - _farTopLeft = topLeft * (-farClipPlane.w / glm::dot(topLeft, glm::vec3(farClipPlane))); - _farTopRight = topRight * (-farClipPlane.w / glm::dot(topRight, glm::vec3(farClipPlane))); - _farBottomLeft = bottomLeft * (-farClipPlane.w / glm::dot(bottomLeft, glm::vec3(farClipPlane))); - _farBottomRight = bottomRight * (-farClipPlane.w / glm::dot(bottomRight, glm::vec3(farClipPlane))); - _nearTopLeft = topLeft * (-nearClipPlane.w / glm::dot(topLeft, glm::vec3(nearClipPlane))); - _nearTopRight = topRight * (-nearClipPlane.w / glm::dot(topRight, glm::vec3(nearClipPlane))); - _nearBottomLeft = bottomLeft * (-nearClipPlane.w / glm::dot(bottomLeft, glm::vec3(nearClipPlane))); - _nearBottomRight = bottomRight * (-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))); + // find the intersections of the rays through the corners with the clip planes in view space, + // then transform them to world space + glm::mat4 worldMatrix = glm::translate(_position) * glm::mat4(glm::mat3(_right, _up, -_direction)) * + glm::translate(_eyeOffsetPosition) * glm::mat4_cast(_eyeOffsetOrientation); + _farTopLeft = glm::vec3(worldMatrix * glm::vec4(topLeft * + (-farClipPlane.w / glm::dot(topLeft, glm::vec3(farClipPlane))), 1.0f)); + _farTopRight = glm::vec3(worldMatrix * glm::vec4(topRight * + (-farClipPlane.w / glm::dot(topRight, glm::vec3(farClipPlane))), 1.0f)); + _farBottomLeft = glm::vec3(worldMatrix * glm::vec4(bottomLeft * + (-farClipPlane.w / glm::dot(bottomLeft, glm::vec3(farClipPlane))), 1.0f)); + _farBottomRight = glm::vec3(worldMatrix * glm::vec4(bottomRight * + (-farClipPlane.w / glm::dot(bottomRight, glm::vec3(farClipPlane))), 1.0f)); + _nearTopLeft = glm::vec3(worldMatrix * glm::vec4(topLeft * + (-nearClipPlane.w / glm::dot(topLeft, glm::vec3(nearClipPlane))), 1.0f)); + _nearTopRight = glm::vec3(worldMatrix * glm::vec4(topRight * + (-nearClipPlane.w / glm::dot(topRight, glm::vec3(nearClipPlane))), 1.0f)); + _nearBottomLeft = glm::vec3(worldMatrix * glm::vec4(bottomLeft * + (-nearClipPlane.w / glm::dot(bottomLeft, glm::vec3(nearClipPlane))), 1.0f)); + _nearBottomRight = glm::vec3(worldMatrix * glm::vec4(bottomRight * + (-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))), 1.0f)); // compute the offset position and axes in world space - _offsetPosition = _position + _eyeOffsetPosition.x * _right + _eyeOffsetPosition.y * _up - - _eyeOffsetPosition.z * _direction; - _offsetDirection = _eyeOffsetOrientation * _direction; - _offsetUp = _eyeOffsetOrientation * _up; - _offsetRight = _eyeOffsetOrientation * _right; - - // now transform the intersections to world space - _farTopLeft = _offsetPosition + _farTopLeft.x * _offsetRight + _farTopLeft.y * _offsetUp - - _farTopLeft.z * _offsetDirection; - _farTopRight = _offsetPosition + _farTopRight.x * _offsetRight + _farTopRight.y * _offsetUp - - _farTopRight.z * _offsetDirection; - _farBottomLeft = _offsetPosition + _farBottomLeft.x * _offsetRight + _farBottomLeft.y * _offsetUp - - _farBottomLeft.z * _offsetDirection; - _farBottomRight = _offsetPosition + _farBottomRight.x * _offsetRight + _farBottomRight.y * _offsetUp - - _farBottomRight.z * _offsetDirection; - _nearTopLeft = _offsetPosition + _nearTopLeft.x * _offsetRight + _nearTopLeft.y * _offsetUp - - _nearTopLeft.z * _offsetDirection; - _nearTopRight = _offsetPosition + _nearTopRight.x * _offsetRight + _nearTopRight.y * _offsetUp - - _nearTopRight.z * _offsetDirection; - _nearBottomLeft = _offsetPosition + _nearBottomLeft.x * _offsetRight + _nearBottomLeft.y * _offsetUp - - _nearBottomLeft.z * _offsetDirection; - _nearBottomRight = _offsetPosition + _nearBottomRight.x * _offsetRight + _nearBottomRight.y * _offsetUp - - _nearBottomRight.z * _offsetDirection; + _offsetPosition = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); + _offsetDirection = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f)); + _offsetUp = glm::vec3(worldMatrix * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f)); + _offsetRight = glm::vec3(worldMatrix * glm::vec4(1.0f, 0.0f, 0.0f, 0.0f)); // compute the six planes // The planes are defined such that the normal points towards the inside of the view frustum. From ae02004ef65ad808545b52aca87821229ba8bd03 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sun, 19 May 2013 22:40:53 -0700 Subject: [PATCH 08/19] Use M rather than L, since L is taken by the level display. --- interface/src/Application.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dada57c1ec..7974b2bdf8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -552,9 +552,9 @@ void Application::keyPressEvent(QKeyEvent* event) { _audio.startEchoTest(); break; - //case Qt::Key_L: - // _displayLevels = !_displayLevels; - // break; + case Qt::Key_L: + _displayLevels = !_displayLevels; + break; case Qt::Key_E: _myAvatar.setDriveKeys(UP, 1); @@ -638,7 +638,7 @@ void Application::keyPressEvent(QKeyEvent* event) { resizeGL(_glWidget->width(), _glWidget->height()); break; - case Qt::Key_L: + case Qt::Key_M: if (shifted) { _myCamera.setEyeOffsetOrientation(glm::normalize( glm::quat(glm::vec3(0, -0.002f, 0)) * _myCamera.getEyeOffsetOrientation())); From 85bca558f5a62830dab133f8d39d76ce8286bac9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 20 May 2013 09:38:01 -0700 Subject: [PATCH 09/19] Tabs -> spaces, spacing fix. --- interface/src/Camera.h | 40 +++++++++++++++--------------- libraries/voxels/src/ViewFrustum.h | 10 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/interface/src/Camera.h b/interface/src/Camera.h index dd966b8448..8b70a06504 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -35,8 +35,8 @@ public: void initialize(); // instantly put the camera at the ideal position and rotation. - void update( float deltaTime ); - + void update( float deltaTime ); + void setYaw ( float y ) { _yaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } @@ -75,27 +75,27 @@ public: private: bool _needsToInitialize; - CameraMode _mode; + CameraMode _mode; bool _frustumNeedsReshape; - glm::vec3 _position; - glm::vec3 _idealPosition; - glm::vec3 _targetPosition; - float _fieldOfView; - float _aspectRatio; - float _nearClip; - float _farClip; + glm::vec3 _position; + glm::vec3 _idealPosition; + glm::vec3 _targetPosition; + float _fieldOfView; + float _aspectRatio; + float _nearClip; + float _farClip; glm::vec3 _eyeOffsetPosition; glm::quat _eyeOffsetOrientation; - float _yaw; - float _pitch; - float _roll; - float _upShift; - float _idealYaw; - float _idealPitch; - float _idealRoll; - float _distance; - float _tightness; - Orientation _orientation; + float _yaw; + float _pitch; + float _roll; + float _upShift; + float _idealYaw; + float _idealPitch; + float _idealRoll; + float _distance; + float _tightness; + Orientation _orientation; float _modeShift; CameraFollowingAttributes _attributes[NUM_CAMERA_MODES]; diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 772371c7df..7fd2026133 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -66,11 +66,11 @@ public: const glm::vec3& getRight() const { return _right; }; // setters for lens attributes - void setFieldOfView ( float f ) { _fieldOfView = f; } - void setAspectRatio ( float a ) { _aspectRatio = a; } - void setNearClip ( float n ) { _nearClip = n; } - void setFarClip ( float f ) { _farClip = f; } - void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; } + void setFieldOfView ( float f ) { _fieldOfView = f; } + void setAspectRatio ( float a ) { _aspectRatio = a; } + void setNearClip ( float n ) { _nearClip = n; } + void setFarClip ( float f ) { _farClip = f; } + void setEyeOffsetPosition (const glm::vec3& p) { _eyeOffsetPosition = p; } void setEyeOffsetOrientation (const glm::quat& o) { _eyeOffsetOrientation = o; } From 0f2f4ee8f911197c3a36737f908c06c494fea0e5 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 20 May 2013 11:32:32 -0700 Subject: [PATCH 10/19] Add the discussed four lines to disable blending and enable backface culling. --- interface/src/VoxelSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index a3796f68c1..d578bb3504 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -638,11 +638,18 @@ void VoxelSystem::render() { _perlinModulateProgram->bind(); glBindTexture(GL_TEXTURE_2D, _permutationNormalTextureID); + // for performance, disable blending and enable backface culling + glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + // draw the number of voxels we have glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID); glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); glDrawElements(GL_TRIANGLES, 36 * _voxelsInReadArrays, GL_UNSIGNED_INT, 0); + glEnable(GL_BLEND); + glDisable(GL_CULL_FACE); + _perlinModulateProgram->release(); glBindTexture(GL_TEXTURE_2D, 0); From dae7bf8674af2c08494c76863431d2531274792a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 May 2013 11:48:50 -0700 Subject: [PATCH 11/19] use AgentList defaults when AIM has no socket or address set --- interface/src/Application.cpp | 6 ++++-- libraries/audio/src/AudioInjectionManager.cpp | 19 +++++++++++++++++++ libraries/audio/src/AudioInjectionManager.h | 3 ++- libraries/shared/src/AgentList.cpp | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1f34ed3c09..ed9d4a3235 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -150,8 +150,8 @@ Application::Application(int& argc, char** argv) : _packetCount(0), _packetsPerSecond(0), _bytesPerSecond(0), - _bytesCount(0) { - + _bytesCount(0) +{ gettimeofday(&_applicationStartupTime, NULL); printLog("Interface Startup:\n"); @@ -167,7 +167,9 @@ Application::Application(int& argc, char** argv) : if (portStr) { listenPort = atoi(portStr); } + AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); + _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking"); if (!_enableNetworkThread) { AgentList::getInstance()->getAgentSocket()->setBlocking(false); diff --git a/libraries/audio/src/AudioInjectionManager.cpp b/libraries/audio/src/AudioInjectionManager.cpp index ce252afd23..275161730e 100644 --- a/libraries/audio/src/AudioInjectionManager.cpp +++ b/libraries/audio/src/AudioInjectionManager.cpp @@ -9,12 +9,16 @@ #include #include "SharedUtil.h" +#include "AgentList.h" +#include "AgentTypes.h" +#include "Agent.h" #include "PacketHeaders.h" #include "AudioInjectionManager.h" UDPSocket* AudioInjectionManager::_injectorSocket = NULL; sockaddr AudioInjectionManager::_destinationSocket; +bool AudioInjectionManager::_isDestinationSocketExplicit = false; AudioInjector* AudioInjectionManager::_injectors[50] = {}; AudioInjector* AudioInjectionManager::injectorWithSamplesFromFile(const char* filename) { @@ -39,9 +43,24 @@ AudioInjector* AudioInjectionManager::injectorWithCapacity(int capacity) { return NULL; } +void AudioInjectionManager::setDestinationSocket(sockaddr& destinationSocket) { + _destinationSocket = destinationSocket; + _isDestinationSocketExplicit = true; +} + void* AudioInjectionManager::injectAudioViaThread(void* args) { AudioInjector* injector = (AudioInjector*) args; + // if we don't have an injectorSocket then grab the one from the agent list + if (!_injectorSocket) { + _injectorSocket = AgentList::getInstance()->getAgentSocket(); + } + + // if we don't have an explicit destination socket then pull active socket for current audio mixer from agent list + if (!_isDestinationSocketExplicit) { + _destinationSocket = *AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER)->getActiveSocket(); + } + injector->injectAudio(_injectorSocket, &_destinationSocket); // if this an injector inside the injection manager's array we're responsible for deletion diff --git a/libraries/audio/src/AudioInjectionManager.h b/libraries/audio/src/AudioInjectionManager.h index 3297305475..8cb9614811 100644 --- a/libraries/audio/src/AudioInjectionManager.h +++ b/libraries/audio/src/AudioInjectionManager.h @@ -24,12 +24,13 @@ public: static void threadInjector(AudioInjector* injector); static void setInjectorSocket(UDPSocket* injectorSocket) { _injectorSocket = injectorSocket;} - static void setDestinationSocket(sockaddr& destinationSocket) { _destinationSocket = destinationSocket; } + static void setDestinationSocket(sockaddr& destinationSocket); private: static void* injectAudioViaThread(void* args); static UDPSocket* _injectorSocket; static sockaddr _destinationSocket; + static bool _isDestinationSocketExplicit; static AudioInjector* _injectors[MAX_CONCURRENT_INJECTORS]; }; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index c667f733a4..3da956a04a 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -10,6 +10,7 @@ #include #include #include + #include "AgentList.h" #include "AgentTypes.h" #include "PacketHeaders.h" From 50ee9b9ee492278d07df898c1d3965c2c351a0aa Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 20 May 2013 11:50:04 -0700 Subject: [PATCH 12/19] Added options menu choice for 'MouseLook', defaults off --- interface/src/Application.cpp | 14 +++++++++----- interface/src/Application.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7a10a6af90..427c91176f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -860,11 +860,13 @@ void Application::idle() { } // Update from Mouse - QPoint mouse = QCursor::pos(); - _myAvatar.updateFromMouse(_glWidget->mapFromGlobal(mouse).x(), - _glWidget->mapFromGlobal(mouse).y(), - _glWidget->width(), - _glWidget->height()); + if (_mouseLook->isChecked()) { + QPoint mouse = QCursor::pos(); + _myAvatar.updateFromMouse(_glWidget->mapFromGlobal(mouse).x(), + _glWidget->mapFromGlobal(mouse).y(), + _glWidget->width(), + _glWidget->height()); + } // Read serial port interface devices if (_serialPort.active) { @@ -1117,6 +1119,8 @@ void Application::initMenu() { optionsMenu->addAction("Noise", this, SLOT(setNoise(bool)), Qt::Key_N)->setCheckable(true); (_gyroLook = optionsMenu->addAction("Gyro Look"))->setCheckable(true); _gyroLook->setChecked(true); + (_mouseLook = optionsMenu->addAction("Mouse Look"))->setCheckable(true); + _mouseLook->setChecked(false); optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F)->setCheckable(true); QMenu* renderMenu = menuBar->addMenu("Render"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 8a949fa183..f1c8d3ff1c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -133,6 +133,7 @@ private: QAction* _lookingInMirror; // Are we currently rendering one's own head as if in mirror? QAction* _gyroLook; // Whether to allow the gyro data from head to move your view + QAction* _mouseLook; // Whether the have the mouse near edge of screen move your view QAction* _renderVoxels; // Whether to render voxels QAction* _renderStarsOn; // Whether to display the stars QAction* _renderAtmosphereOn; // Whether to display the atmosphere From 28581e33ccd9f40b8b50bbbcb3ceb6ee177aa3ba Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 20 May 2013 11:56:40 -0700 Subject: [PATCH 13/19] turn off audio echo rendering (it's for debug) --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 427c91176f..a1778bff54 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1662,7 +1662,7 @@ void Application::displayOverlay() { #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); _audioScope.render(20, _glWidget->height() - 200); - _audio.renderEchoCompare(); // PER: Will turn back on to further test echo + //_audio.renderEchoCompare(); // PER: Will turn back on to further test echo #endif //noiseTest(_glWidget->width(), _glWidget->height()); From fe1f02beffe2a5a49c40e1bc6fcfe1654ee3191d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 May 2013 12:16:55 -0700 Subject: [PATCH 14/19] moved constructor --- libraries/avatars/src/AvatarData.cpp | 27 +++++++++++++++++++++++++++ libraries/avatars/src/AvatarData.h | 28 +--------------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index ab60088cf8..2bd53532dd 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -34,6 +34,33 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo return sizeof(uint16_t); } +AvatarData::AvatarData() : + _handPosition(0,0,0), + _bodyYaw(-90.0), + _bodyPitch(0.0), + _bodyRoll(0.0), + _headYaw(0), + _headPitch(0), + _headRoll(0), + _headLeanSideways(0), + _headLeanForward(0), + _audioLoudness(0), + _handState(0), + _cameraPosition(0,0,0), + _cameraDirection(0,0,0), + _cameraUp(0,0,0), + _cameraRight(0,0,0), + _cameraFov(0.0f), + _cameraAspectRatio(0.0f), + _cameraNearClip(0.0f), + _cameraFarClip(0.0f), + _keyState(NO_KEY_DOWN), + _wantResIn(false), + _wantColor(true), + _wantDelta(false) +{ +}; + AvatarData::~AvatarData() { } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index a11c2da260..33d2b5205e 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -28,33 +28,7 @@ enum KeyState class AvatarData : public AgentData { public: - AvatarData() : - _handPosition(0,0,0), - _bodyYaw(-90.0), - _bodyPitch(0.0), - _bodyRoll(0.0), - _headYaw(0), - _headPitch(0), - _headRoll(0), - _headLeanSideways(0), - _headLeanForward(0), - _audioLoudness(0), - _handState(0), - _cameraPosition(0,0,0), - _cameraDirection(0,0,0), - _cameraUp(0,0,0), - _cameraRight(0,0,0), - _cameraFov(0.0f), - _cameraAspectRatio(0.0f), - _cameraNearClip(0.0f), - _cameraFarClip(0.0f), - _keyState(NO_KEY_DOWN), - _wantResIn(false), - _wantColor(true), - _wantDelta(false) - { }; - - + AvatarData(); ~AvatarData(); AvatarData* clone() const; From d6ceca4f4bffbaa88fa4d641be5adf292c31a831 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 May 2013 12:16:56 -0700 Subject: [PATCH 15/19] move constructor for AvatarData to implemenation file --- libraries/avatars/src/AvatarData.cpp | 29 ++++++++++++++++++++++++++++ libraries/avatars/src/AvatarData.h | 26 +------------------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 2e11e8aa84..d644be8c7c 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -19,6 +19,35 @@ using namespace std; using avatars_lib::printLog; +AvatarData::AvatarData() : + _handPosition(0,0,0), + _bodyYaw(-90.0), + _bodyPitch(0.0), + _bodyRoll(0.0), + _headYaw(0), + _headPitch(0), + _headRoll(0), + _headLeanSideways(0), + _headLeanForward(0), + _audioLoudness(0), + _handState(0), + _cameraPosition(0,0,0), + _cameraDirection(0,0,0), + _cameraUp(0,0,0), + _cameraRight(0,0,0), + _cameraFov(0.0f), + _cameraAspectRatio(0.0f), + _cameraNearClip(0.0f), + _cameraFarClip(0.0f), + _keyState(NO_KEY_DOWN), + _wantResIn(false), + _wantColor(true), + _wantDelta(false) +{ + +} + + int packFloatAngleToTwoByte(unsigned char* buffer, float angle) { const float ANGLE_CONVERSION_RATIO = (std::numeric_limits::max() / 360.0); diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 89fa8c70a3..eeb2e1eb7e 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -28,31 +28,7 @@ enum KeyState class AvatarData : public AgentData { public: - AvatarData() : - _handPosition(0,0,0), - _bodyYaw(-90.0), - _bodyPitch(0.0), - _bodyRoll(0.0), - _headYaw(0), - _headPitch(0), - _headRoll(0), - _headLeanSideways(0), - _headLeanForward(0), - _audioLoudness(0), - _handState(0), - _cameraPosition(0,0,0), - _cameraDirection(0,0,0), - _cameraUp(0,0,0), - _cameraRight(0,0,0), - _cameraFov(0.0f), - _cameraAspectRatio(0.0f), - _cameraNearClip(0.0f), - _cameraFarClip(0.0f), - _keyState(NO_KEY_DOWN), - _wantResIn(false), - _wantColor(true), - _wantDelta(false) - { }; + AvatarData(); const glm::vec3& getPosition() const { return _position; } void setPosition(const glm::vec3 position) { _position = position; } From 17c961f1b0d04e764308ac6e2267f87fffb78bd9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 May 2013 12:34:15 -0700 Subject: [PATCH 16/19] merge --- libraries/avatars/src/AvatarData.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 33d2b5205e..a2b210078b 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -29,24 +29,22 @@ enum KeyState class AvatarData : public AgentData { public: AvatarData(); - ~AvatarData(); - AvatarData* clone() const; - const glm::vec3& getPosition() const; - void setPosition(glm::vec3 position); - void setHandPosition(glm::vec3 handPosition); + const glm::vec3& getPosition() const { return _position; } + void setPosition(const glm::vec3 position) { _position = position; } + void setHandPosition(const glm::vec3 handPosition) { _handPosition = handPosition; } int getBroadcastData(unsigned char* destinationBuffer); int parseData(unsigned char* sourceBuffer, int numBytes); // Body Rotation - float getBodyYaw(); - float getBodyPitch(); - float getBodyRoll(); - void setBodyYaw(float bodyYaw); - void setBodyPitch(float bodyPitch); - void setBodyRoll(float bodyRoll); + float getBodyYaw() const { return _bodyYaw; } + void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } + float getBodyPitch() const { return _bodyPitch; } + void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } + float getBodyRoll() const {return _bodyRoll; } + void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } // Head Rotation void setHeadPitch(float p); @@ -110,6 +108,10 @@ public: void setWantDelta(bool wantDelta) { _wantDelta = wantDelta; } protected: + // privatize the copy constructor and assignment operator so they cannot be called + AvatarData(const AvatarData&); + AvatarData& operator= (const AvatarData&); + glm::vec3 _position; glm::vec3 _handPosition; From 24b34b19b15217bf2d3e1daff7b630dc5f8f9cb2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 May 2013 12:35:18 -0700 Subject: [PATCH 17/19] merge --- libraries/avatars/src/AvatarData.cpp | 50 +--------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 2bd53532dd..73157911b4 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -61,14 +61,6 @@ AvatarData::AvatarData() : { }; -AvatarData::~AvatarData() { - -} - -AvatarData* AvatarData::clone() const { - return new AvatarData(*this); -} - int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { unsigned char* bufferStart = destinationBuffer; @@ -227,49 +219,9 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { return sourceBuffer - startPosition; } -const glm::vec3& AvatarData::getPosition() const { - return _position; -} - -void AvatarData::setPosition(glm::vec3 position) { - _position = position; -} - -void AvatarData::setHandPosition(glm::vec3 handPosition) { - _handPosition = handPosition; -} - -float AvatarData::getBodyYaw() { - return _bodyYaw; -} - -void AvatarData::setBodyYaw(float bodyYaw) { - _bodyYaw = bodyYaw; -} - -float AvatarData::getBodyPitch() { - return _bodyPitch; -} - -void AvatarData::setBodyPitch(float bodyPitch) { - _bodyPitch = bodyPitch; -} - -float AvatarData::getBodyRoll() { - return _bodyRoll; -} - -void AvatarData::setBodyRoll(float bodyRoll) { - _bodyRoll = bodyRoll; -} - void AvatarData::setHeadPitch(float p) { // Set head pitch and apply limits const float MAX_PITCH = 60; const float MIN_PITCH = -60; _headPitch = glm::clamp(p, MIN_PITCH, MAX_PITCH); -} - - - - +} \ No newline at end of file From cf065a413c5a9ea9b3eb8c6c1ec613da669cd6d0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 May 2013 12:36:16 -0700 Subject: [PATCH 18/19] merge --- libraries/avatars/src/AvatarData.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index a2b210078b..5bb93b02b5 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -29,7 +29,6 @@ enum KeyState class AvatarData : public AgentData { public: AvatarData(); - AvatarData* clone() const; const glm::vec3& getPosition() const { return _position; } void setPosition(const glm::vec3 position) { _position = position; } From 6aafcc752dcf8dfd25a5e539ece794ddd09f6267 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 20 May 2013 12:51:21 -0700 Subject: [PATCH 19/19] re-arrange member variable constructors for compiler warning --- interface/src/Oscilloscope.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index 088ef6ac14..baa173e512 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -32,11 +32,15 @@ namespace { // everything in here only exists while compiling this .cpp file } -Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : - _valWidth(w), _valHeight(h), - _arrSamples(0l), _arrVertices(0l), - _valLowpass(0.4f), _valDownsample(3), - enabled(isEnabled), inputPaused(false) { +Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : + enabled(isEnabled), + inputPaused(false), + _valWidth(w), + _valHeight(h), + _arrSamples(0l), + _arrVertices(0l), + _valLowpass(0.4f), + _valDownsample(3) { // allocate enough space for the sample data and to turn it into // vertices and since they're all 'short', do so in one shot