From d2d8bad241875eb96b25648aea3fb92c5dfa98f6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 7 Aug 2013 14:47:36 -0700 Subject: [PATCH 1/5] simplified frustum camera mode, fixed resizeGL in case of frustum being on --- interface/src/Application.cpp | 46 +++++++++++++++++++---------------- interface/src/Application.h | 1 + interface/src/Camera.cpp | 1 - 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 61317cc4dd..20d2065a75 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -439,7 +439,7 @@ void Application::paintGL() { // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera Camera whichCamera = _myCamera; - if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) { + if (_frustumOn->isChecked()) { // set the camera to third-person view but offset so we can see the frustum _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); @@ -467,32 +467,42 @@ void Application::paintGL() { _frameCount++; } -void Application::resizeGL(int width, int height) { +void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) { float aspectRatio = ((float)width/(float)height); // based on screen resize // reset the camera FOV to our preference... - _myCamera.setFieldOfView(_horizontalFieldOfView); - - // get the lens details from the current camera - Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera; - float nearClip = camera.getNearClip(); - float farClip = camera.getFarClip(); - float fov; + camera.setFieldOfView(_horizontalFieldOfView); if (OculusManager::isConnected()) { // more magic numbers; see Oculus SDK docs, p. 32 camera.setAspectRatio(aspectRatio *= 0.5); - camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); - + camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); + } else { + camera.setAspectRatio(aspectRatio); + camera.setFieldOfView(_horizontalFieldOfView); + } +} + +void Application::resizeGL(int width, int height) { + + // tell both cameras about our new size + resetCamerasOnResizeGL(_myCamera, width, height); + resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); + + float aspectRatio = ((float)width/(float)height); // based on screen resize + + // get the lens details from the current camera + Camera& camera = _frustumOn->isChecked() ? _viewFrustumOffsetCamera : _myCamera; + float nearClip = camera.getNearClip(); + float farClip = camera.getFarClip(); + + if (OculusManager::isConnected()) { // resize the render texture if (_oculusTextureID != 0) { glBindTexture(GL_TEXTURE_2D, _oculusTextureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); } - } else { - camera.setAspectRatio(aspectRatio); - camera.setFieldOfView(fov = _horizontalFieldOfView); } // Tell our viewFrustum about this change @@ -819,11 +829,7 @@ void Application::keyPressEvent(QKeyEvent* event) { _colorVoxelMode->trigger(); break; case Qt::Key_O: - if (isShifted) { - _viewFrustumFromOffset->trigger(); - } else { - _selectVoxelMode->trigger(); - } + _selectVoxelMode->trigger(); break; case Qt::Key_Slash: _renderStatsOn->trigger(); @@ -2060,8 +2066,6 @@ void Application::initMenu() { QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); - (_viewFrustumFromOffset = frustumMenu->addAction( - "Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true); _frustumRenderModeAction = frustumMenu->addAction( "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); updateFrustumRenderModeAction(); diff --git a/interface/src/Application.h b/interface/src/Application.h index d9c945f34e..8de73edeb5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -211,6 +211,7 @@ private slots: void toggleFollowMode(); private: + void resetCamerasOnResizeGL(Camera& camera, int width, int height); static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, const char* nodeTypes, int numNodeTypes); diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index a91dfdce6c..29449e63b5 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -38,7 +38,6 @@ Camera::Camera() { _mode = CAMERA_MODE_THIRD_PERSON; _tightness = 10.0f; // default _fieldOfView = HORIZONTAL_FIELD_OF_VIEW_DEGREES; - _aspectRatio = 16.f/9.f; _nearClip = 0.08f; // default _farClip = 50.0f * TREE_SCALE; // default _upShift = 0.0f; From f4820143d747e4530ac081b2bfdc689e3714b4e5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 7 Aug 2013 16:12:03 -0700 Subject: [PATCH 2/5] cleanup resizeGL, and Display Frustum menus --- interface/src/Application.cpp | 74 ++++++++++++++++------------------- interface/src/Application.h | 1 - 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8261ad9585..79776321bd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -439,7 +439,7 @@ void Application::paintGL() { // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera Camera whichCamera = _myCamera; - if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) { + if (_frustumOn->isChecked()) { // set the camera to third-person view but offset so we can see the frustum _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); @@ -467,56 +467,52 @@ void Application::paintGL() { _frameCount++; } -void Application::resizeGL(int width, int height) { +void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) { float aspectRatio = ((float)width/(float)height); // based on screen resize + + if (OculusManager::isConnected()) { + // more magic numbers; see Oculus SDK docs, p. 32 + camera.setAspectRatio(aspectRatio *= 0.5); + camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); + } else { + camera.setAspectRatio(aspectRatio); + camera.setFieldOfView(_fieldOfView); + } +} + +void Application::resizeGL(int width, int height) { + resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); + resetCamerasOnResizeGL(_myCamera, width, height); // reset the camera FOV to our preference... _myCamera.setFieldOfView(_fieldOfView); - // get the lens details from the current camera - Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera; - float nearClip = camera.getNearClip(); - float farClip = camera.getFarClip(); - float fov; - - if (OculusManager::isConnected()) { - // more magic numbers; see Oculus SDK docs, p. 32 - camera.setAspectRatio(aspectRatio *= 0.5); - camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); - - // resize the render texture - if (_oculusTextureID != 0) { - glBindTexture(GL_TEXTURE_2D, _oculusTextureID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - glBindTexture(GL_TEXTURE_2D, 0); - } - } else { - camera.setAspectRatio(aspectRatio); - camera.setFieldOfView(fov = _fieldOfView); + // resize the render texture + if (OculusManager::isConnected() && _oculusTextureID != 0) { + glBindTexture(GL_TEXTURE_2D, _oculusTextureID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, 0); } - // Tell our viewFrustum about this change - _viewFrustum.setAspectRatio(aspectRatio); + // Tell our viewFrustum about this change, using the application camera + loadViewFrustum(_myCamera, _viewFrustum); glViewport(0, 0, width, height); // shouldn't this account for the menu??? glMatrixMode(GL_PROJECTION); glLoadIdentity(); - // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that - // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes - // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also, - // to see more.) - if (_frustumOn->isChecked()) { - nearClip -= 0.01f; - farClip += 0.01f; - } - // On window reshape, we need to tell OpenGL about our new setting float left, right, bottom, top, nearVal, farVal; glm::vec4 nearClipPlane, farClipPlane; - 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 (_frustumOn->isChecked()) { + nearVal = _viewFrustumOffsetCamera.getNearClip(); + farVal = _viewFrustumOffsetCamera.getFarClip(); + } glFrustum(left, right, bottom, top, nearVal, farVal); glMatrixMode(GL_MODELVIEW); @@ -819,11 +815,7 @@ void Application::keyPressEvent(QKeyEvent* event) { _colorVoxelMode->trigger(); break; case Qt::Key_O: - if (isShifted) { - _viewFrustumFromOffset->trigger(); - } else { - _selectVoxelMode->trigger(); - } + _selectVoxelMode->trigger(); break; case Qt::Key_Slash: _renderStatsOn->trigger(); @@ -2060,8 +2052,6 @@ void Application::initMenu() { QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); - (_viewFrustumFromOffset = frustumMenu->addAction( - "Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true); _frustumRenderModeAction = frustumMenu->addAction( "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); updateFrustumRenderModeAction(); @@ -2776,6 +2766,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { float fov = camera.getFieldOfView(); float nearClip = camera.getNearClip(); float farClip = camera.getFarClip(); + float aspectRatio = camera.getAspectRatio(); glm::quat rotation = camera.getRotation(); @@ -2784,6 +2775,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { viewFrustum.setOrientation(rotation); // Also make sure it's got the correct lens details from the camera + viewFrustum.setAspectRatio(aspectRatio); viewFrustum.setFieldOfView(fov); viewFrustum.setNearClip(nearClip); viewFrustum.setFarClip(farClip); diff --git a/interface/src/Application.h b/interface/src/Application.h index c49050ba8c..2904437c16 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -308,7 +308,6 @@ private: QAction* _voxelPaintColor; // The color with which to paint voxels QAction* _destructiveAddVoxel; // when doing voxel editing do we want them to be destructive QAction* _frustumOn; // Whether or not to display the debug view frustum - QAction* _viewFrustumFromOffset; // Whether or not to offset the view of the frustum QAction* _fullScreenMode; // whether we are in full screen mode QAction* _frustumRenderModeAction; QAction* _settingsAutosave; // Whether settings are saved automatically From cb211fbb04b1487bcae4b574de95d0419fc5ad6c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 7 Aug 2013 16:27:43 -0700 Subject: [PATCH 3/5] CR feedback --- interface/src/Application.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 79776321bd..35fdec8e68 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -484,9 +484,6 @@ void Application::resizeGL(int width, int height) { resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); resetCamerasOnResizeGL(_myCamera, width, height); - // reset the camera FOV to our preference... - _myCamera.setFieldOfView(_fieldOfView); - // resize the render texture if (OculusManager::isConnected() && _oculusTextureID != 0) { glBindTexture(GL_TEXTURE_2D, _oculusTextureID); From 4449b46466ec7d9d1e08d9161672da38b0c3f847 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 7 Aug 2013 16:38:02 -0700 Subject: [PATCH 4/5] Fix other avatar not rendered in first person --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 13e4dc2416..d0ed66a4eb 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -1427,7 +1427,7 @@ float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const { void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { - if (Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON) { + if (isMyAvatar() && Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON) { // Dont display body } else if (_head.getFace().isFullFrame()) { // Render the full-frame video From 2a21ce7945618eb84855f32908396f4cb7299ba7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 7 Aug 2013 16:40:28 -0700 Subject: [PATCH 5/5] socket changes to send correct port to pairing server --- interface/src/PairingHandler.cpp | 6 ++++-- libraries/shared/src/NodeList.cpp | 4 ++-- libraries/shared/src/NodeList.h | 9 ++++----- libraries/shared/src/UDPSocket.cpp | 13 ++++++++----- libraries/shared/src/UDPSocket.h | 6 +++--- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/interface/src/PairingHandler.cpp b/interface/src/PairingHandler.cpp index bd363a6b66..920f2c519c 100644 --- a/interface/src/PairingHandler.cpp +++ b/interface/src/PairingHandler.cpp @@ -27,12 +27,14 @@ void PairingHandler::sendPairRequest() { int localAddress = getLocalAddress(); char pairPacket[24] = {}; - sprintf(pairPacket, "Find %d.%d.%d.%d:%d", + sprintf(pairPacket, "Find %d.%d.%d.%d:%hu", localAddress & 0xFF, (localAddress >> 8) & 0xFF, (localAddress >> 16) & 0xFF, (localAddress >> 24) & 0xFF, - NODE_SOCKET_LISTEN_PORT); + NodeList::getInstance()->getSocketListenPort()); + + qDebug("Sending pair packet: %s\n", pairPacket); sockaddr_in pairingServerSocket; diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 610a9264cf..6c2647efd5 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -38,7 +38,7 @@ bool pingUnknownNodeThreadStopFlag = false; NodeList* NodeList::_sharedInstance = NULL; -NodeList* NodeList::createInstance(char ownerType, unsigned int socketListenPort) { +NodeList* NodeList::createInstance(char ownerType, unsigned short int socketListenPort) { if (!_sharedInstance) { _sharedInstance = new NodeList(ownerType, socketListenPort); } else { @@ -56,7 +56,7 @@ NodeList* NodeList::getInstance() { return _sharedInstance; } -NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) : +NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) : _nodeBuckets(), _numNodes(0), _nodeSocket(newSocketListenPort), diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index c2b966b879..84bc4f6151 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -28,7 +28,7 @@ const int MAX_NUM_NODES = 10000; const int NODES_PER_BUCKET = 100; const int MAX_PACKET_SIZE = 1500; -const unsigned int NODE_SOCKET_LISTEN_PORT = 40103; +const unsigned short int NODE_SOCKET_LISTEN_PORT = 40103; const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; @@ -55,7 +55,7 @@ public: class NodeList { public: - static NodeList* createInstance(char ownerType, unsigned int socketListenPort = NODE_SOCKET_LISTEN_PORT); + static NodeList* createInstance(char ownerType, unsigned short int socketListenPort = NODE_SOCKET_LISTEN_PORT); static NodeList* getInstance(); typedef NodeListIterator iterator; @@ -81,7 +81,7 @@ public: UDPSocket* getNodeSocket() { return &_nodeSocket; } - unsigned int getSocketListenPort() const { return _nodeSocket.getListeningPort(); }; + unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); }; void(*linkedDataCreateCallback)(Node *); @@ -128,7 +128,7 @@ public: private: static NodeList* _sharedInstance; - NodeList(char ownerType, unsigned int socketListenPort); + NodeList(char ownerType, unsigned short int socketListenPort); ~NodeList(); NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton @@ -142,7 +142,6 @@ private: UDPSocket _nodeSocket; char _ownerType; char* _nodeTypesOfInterest; - unsigned int _socketListenPort; uint16_t _ownerID; uint16_t _lastNodeID; pthread_t removeSilentNodesThread; diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index c156ddd1be..39c4dc2e62 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -129,7 +129,10 @@ sockaddr_in socketForHostname(const char* hostname) { return newSocket; } -UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking(true) { +UDPSocket::UDPSocket(unsigned short int listeningPort) : + _listeningPort(listeningPort), + blocking(true) +{ init(); // create the socket handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -145,10 +148,10 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking sockaddr_in bind_address; bind_address.sin_family = AF_INET; bind_address.sin_addr.s_addr = INADDR_ANY; - bind_address.sin_port = htons((uint16_t) listeningPort); + bind_address.sin_port = htons((uint16_t) _listeningPort); if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) { - qDebug("Failed to bind socket to port %d.\n", listeningPort); + qDebug("Failed to bind socket to port %hu.\n", _listeningPort); return; } @@ -156,7 +159,7 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking if (listeningPort == 0) { socklen_t addressLength = sizeof(sockaddr_in); getsockname(handle, (sockaddr*) &bind_address, &addressLength); - listeningPort = ntohs(bind_address.sin_port); + _listeningPort = ntohs(bind_address.sin_port); } // set timeout on socket recieve to 0.5 seconds @@ -165,7 +168,7 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking tv.tv_usec = 500000; setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv); - qDebug("Created UDP socket listening on port %d.\n", listeningPort); + qDebug("Created UDP socket listening on port %hu.\n", _listeningPort); } UDPSocket::~UDPSocket() { diff --git a/libraries/shared/src/UDPSocket.h b/libraries/shared/src/UDPSocket.h index 58bee3d2de..34f8ee0b06 100644 --- a/libraries/shared/src/UDPSocket.h +++ b/libraries/shared/src/UDPSocket.h @@ -20,10 +20,10 @@ class UDPSocket { public: - UDPSocket(int listening_port); + UDPSocket(unsigned short int listeningPort); ~UDPSocket(); bool init(); - int getListeningPort() const { return listeningPort; } + unsigned short int getListeningPort() const { return _listeningPort; } void setBlocking(bool blocking); bool isBlocking() const { return blocking; } int send(sockaddr* destAddress, const void* data, size_t byteLength) const; @@ -32,7 +32,7 @@ public: bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const; private: int handle; - int listeningPort; + unsigned short int _listeningPort; bool blocking; };