Circle drawn with camera orientation as its normal for lookatIndicator.

This commit is contained in:
Mark Peng 2013-07-17 17:27:15 -07:00
parent 0bbea078b5
commit 125bcc46f4
4 changed files with 24 additions and 15 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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);

View file

@ -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,