From 125bcc46f486ae06cc3be0099a19867bf55eb265 Mon Sep 17 00:00:00 2001 From: Mark Peng Date: Wed, 17 Jul 2013 17:27:15 -0700 Subject: [PATCH] Circle drawn with camera orientation as its normal for lookatIndicator. --- interface/src/Application.cpp | 29 ++++++++++++++-------------- interface/src/Application.h | 3 +++ libraries/voxels/src/ViewFrustum.cpp | 5 ++++- libraries/voxels/src/ViewFrustum.h | 2 ++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 10da14697b..2c2a197899 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1676,6 +1676,8 @@ void Application::initMenu() { _renderFrameTimerOn->setChecked(false); (_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true); _renderLookatOn->setChecked(false); + (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true); + _renderLookatIndicatorOn->setChecked(true); (_manualFirstPerson = renderMenu->addAction( "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); (_manualThirdPerson = renderMenu->addAction( @@ -1887,7 +1889,7 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m glm::vec3 headPosition = avatar->getHead().getPosition(); if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) { eyePosition = avatar->getHead().getEyeLevelPosition(); - renderLookatIndicator(headPosition); + _lookatOtherPosition = headPosition; return true; } } @@ -1895,24 +1897,19 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m return false; } -void Application::renderLookatIndicator(glm::vec3& pointOfInterest) { - // Render a circle between me and the avatar in question. +void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) { - // I need a vector that is perpendicular to the vector from my camera position to the head position. - // Start by locating point on vector that will be the center of the circle. - glm::vec3 direction = glm::normalize(pointOfInterest - _myCamera.getPosition()); + glm::vec3 direction = glm::normalize(pointOfInterest - whichCamera.getPosition()); const float DISTANCE_FROM_HEAD_SPHERE = 0.1f; glm::vec3 indicatorOrigin = pointOfInterest - DISTANCE_FROM_HEAD_SPHERE * direction; - // Then find a perpendicular vector/point - // const float ARB_X = 1.0f; - // const float ARB_Y = 1.0f; - // float z = - (direction.x * ARB_X + direction.y * ARB_Y) / direction.z; - // glm::vec3 perpendicular(ARB_X, ARB_Y, z); - // perpendicular = glm::normalize(perpendicular); - // glm::vec3 startingVertex = indicatorOrigin + perpendicular; - renderCircle(indicatorOrigin, 0.1, direction, 30); + // glm::vec3 haloOrigin(pointOfInterest.x, pointOfInterest.y + DISTANCE_FROM_HEAD_SPHERE, pointOfInterest.z); + glColor3f(1.0f, 0.0f, 0.0f); + // renderCircle(haloOrigin, 0.1f, glm::vec3(0.0f, 1.0f, 0.0f), 30); + // glm::vec3 normal; + // _viewFrustum.computeNormalToNearClipPlane(normal); + renderCircle(indicatorOrigin, 0.1f, _viewFrustum.getDirection(), 30); } void Application::update(float deltaTime) { @@ -2605,6 +2602,10 @@ void Application::displaySide(Camera& whichCamera) { } _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked()); _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked()); + + if (_renderLookatIndicatorOn->isChecked() && _isLookingAtOtherAvatar) { + renderLookatIndicator(_lookatOtherPosition, whichCamera); + } } if (TESTING_PARTICLE_SYSTEM) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 52e75ea446..b577fa3af2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -195,6 +195,7 @@ private: void update(float deltaTime); bool isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, glm::vec3& eyePosition); + void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera); void updateAvatar(float deltaTime); void loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum); @@ -250,6 +251,7 @@ private: QAction* _renderStatsOn; // Whether to show onscreen text overlay with stats QAction* _renderFrameTimerOn; // Whether to show onscreen text overlay with stats QAction* _renderLookatOn; // Whether to show lookat vectors from avatar eyes if looking at something + QAction* _renderLookatIndicatorOn; QAction* _manualFirstPerson; // Whether to force first-person mode QAction* _manualThirdPerson; // Whether to force third-person mode QAction* _logOn; // Whether to show on-screen log @@ -365,6 +367,7 @@ private: bool _justEditedVoxel; // set when we've just added/deleted/colored a voxel bool _isLookingAtOtherAvatar; + glm::vec3 _lookatOtherPosition; bool _paintOn; // Whether to paint voxels as you fly around unsigned char _dominantColor; // The dominant color of the voxel we're painting diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index c13da815f8..69fbeab54d 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -364,7 +364,10 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const { return result; } - +void ViewFrustum::computeNormalToNearClipPlane(glm::vec3& normal) const { + Plane nearClipPlane(_nearTopLeft, _nearTopRight, _nearBottomLeft); + normal = nearClipPlane.getNormal(); +} void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const { origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft); diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 188b85c0de..4f34143b27 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -83,6 +83,8 @@ public: bool matches(const ViewFrustum& compareTo, bool debug = false) const; bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }; + void computeNormalToNearClipPlane(glm::vec3& normal) const; + 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,