summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorRick Pasetto <rick@lindenlab.com>2009-12-14 15:41:09 -0800
committerRick Pasetto <rick@lindenlab.com>2009-12-14 15:41:09 -0800
commitb877ed17e8d1072ca950cffab355ba4b2480cb09 (patch)
tree45aeb1fa3a37432f22d9de3e414c68cf018c2315 /indra/newview
parent38483348eed5563fde1963575758334567af15e6 (diff)
DEV-42327: Compute controls position & size for HUD objects
Review #62 Added facility to get the HUD projection and modelview matrices by refactoring the calls in llviewerdisplay a bit.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llpanelprimmediacontrols.cpp32
-rw-r--r--indra/newview/llviewerdisplay.cpp70
2 files changed, 69 insertions, 33 deletions
diff --git a/indra/newview/llpanelprimmediacontrols.cpp b/indra/newview/llpanelprimmediacontrols.cpp
index 3fe51106e4..7b2ac38568 100644
--- a/indra/newview/llpanelprimmediacontrols.cpp
+++ b/indra/newview/llpanelprimmediacontrols.cpp
@@ -57,6 +57,7 @@
#include "llsliderctrl.h"
#include "llstring.h"
#include "llviewercontrol.h"
+#include "llviewerdisplay.h"
#include "llviewerparcelmgr.h"
#include "llviewermedia.h"
#include "llviewermediafocus.h"
@@ -66,8 +67,11 @@
#include "llfloatertools.h" // to enable hide if build tools are up
+// Functions pulled from pipeline.cpp
glh::matrix4f glh_get_current_modelview();
glh::matrix4f glh_get_current_projection();
+// Functions pulled from llviewerdisplay.cpp
+bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model);
// Warning: make sure these two match!
const LLPanelPrimMediaControls::EZoomLevel LLPanelPrimMediaControls::kZoomLevels[] = { ZOOM_NONE, ZOOM_MEDIUM };
@@ -564,9 +568,6 @@ void LLPanelPrimMediaControls::updateShape()
//
// Calculate position and shape of the controls
//
- LLVector3 min, max;
-
- glh::matrix4f mat = glh_get_current_projection()*glh_get_current_modelview();
std::vector<LLVector3>::iterator vert_it;
std::vector<LLVector3>::iterator vert_end;
std::vector<LLVector3> vect_face;
@@ -603,8 +604,18 @@ void LLPanelPrimMediaControls::updateShape()
vert_it = vect_face.begin();
vert_end = vect_face.end();
- min = LLVector3(1,1,1);
- max = LLVector3(-1,-1,-1);
+ glh::matrix4f mat;
+ if (!is_hud)
+ {
+ mat = glh_get_current_projection() * glh_get_current_modelview();
+ }
+ else {
+ glh::matrix4f proj, modelview;
+ if (get_hud_matrices(proj, modelview))
+ mat = proj * modelview;
+ }
+ LLVector3 min = LLVector3(1,1,1);
+ LLVector3 max = LLVector3(-1,-1,-1);
for(; vert_it != vert_end; ++vert_it)
{
// project silhouette vertices into screen space
@@ -633,10 +644,15 @@ void LLPanelPrimMediaControls::updateShape()
media_controls_rect.mRight += getRect().getWidth() - mMediaRegion->getRect().mRight;
// keep all parts of HUD on-screen
- media_controls_rect.intersectWith(getParent()->getLocalRect());
+ LLRect window_rect = getParent()->getLocalRect();
+ media_controls_rect.intersectWith(window_rect);
- // clamp to minimum size, keeping centered
- media_controls_rect.setCenterAndSize(media_controls_rect.getCenterX(), media_controls_rect.getCenterY(),
+ // clamp to minimum size, keeping rect inside window
+ S32 centerX = media_controls_rect.getCenterX();
+ S32 centerY = media_controls_rect.getCenterY();
+ window_rect.stretch(-mMinWidth/2, -mMinHeight/2);
+ window_rect.clampPointToRect(centerX, centerY);
+ media_controls_rect.setCenterAndSize(centerX, centerY,
llmax(mMinWidth, media_controls_rect.getWidth()), llmax(mMinHeight, media_controls_rect.getHeight()));
setShape(media_controls_rect, true);
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index 5b733ed817..68a5147bc7 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -1009,10 +1009,10 @@ void render_hud_attachments()
glh_set_current_modelview(current_mod);
}
-BOOL setup_hud_matrices()
+LLRect get_whole_screen_region()
{
LLRect whole_screen = gViewerWindow->getWindowRectScaled();
-
+
// apply camera zoom transform (for high res screenshots)
F32 zoom_factor = LLViewerCamera::getInstance()->getZoomFactor();
S16 sub_region = LLViewerCamera::getInstance()->getZoomSubRegion();
@@ -1024,52 +1024,43 @@ BOOL setup_hud_matrices()
int tile_y = sub_region / num_horizontal_tiles;
int tile_x = sub_region - (tile_y * num_horizontal_tiles);
glh::matrix4f mat;
-
+
whole_screen.setLeftTopAndSize(tile_x * tile_width, gViewerWindow->getWindowHeightScaled() - (tile_y * tile_height), tile_width, tile_height);
}
-
- return setup_hud_matrices(whole_screen);
+ return whole_screen;
}
-BOOL setup_hud_matrices(const LLRect& screen_region)
+bool get_hud_matrices(const LLRect& screen_region, glh::matrix4f &proj, glh::matrix4f &model)
{
LLVOAvatar* my_avatarp = gAgent.getAvatarObject();
if (my_avatarp && my_avatarp->hasHUDAttachment())
{
F32 zoom_level = gAgent.mHUDCurZoom;
LLBBox hud_bbox = my_avatarp->getHUDBBox();
-
- // set up transform to keep HUD objects in front of camera
- glMatrixMode(GL_PROJECTION);
+
F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
- glh::matrix4f proj = gl_ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
+ proj = gl_ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
proj.element(2,2) = -0.01f;
-
+
F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect();
-
+
glh::matrix4f mat;
F32 scale_x = (F32)gViewerWindow->getWindowWidthScaled() / (F32)screen_region.getWidth();
F32 scale_y = (F32)gViewerWindow->getWindowHeightScaled() / (F32)screen_region.getHeight();
mat.set_scale(glh::vec3f(scale_x, scale_y, 1.f));
mat.set_translate(
glh::vec3f(clamp_rescale((F32)screen_region.getCenterX(), 0.f, (F32)gViewerWindow->getWindowWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio),
- clamp_rescale((F32)screen_region.getCenterY(), 0.f, (F32)gViewerWindow->getWindowHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
- 0.f));
+ clamp_rescale((F32)screen_region.getCenterY(), 0.f, (F32)gViewerWindow->getWindowHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
+ 0.f));
proj *= mat;
-
- glLoadMatrixf(proj.m);
- glh_set_current_projection(proj);
-
- glMatrixMode(GL_MODELVIEW);
- glh::matrix4f model((GLfloat*) OGL_TO_CFR_ROTATION);
+
+ glh::matrix4f tmp_model((GLfloat*) OGL_TO_CFR_ROTATION);
mat.set_scale(glh::vec3f(zoom_level, zoom_level, zoom_level));
mat.set_translate(glh::vec3f(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f));
-
- model *= mat;
- glLoadMatrixf(model.m);
- glh_set_current_modelview(model);
-
+
+ tmp_model *= mat;
+ model = tmp_model;
return TRUE;
}
else
@@ -1078,6 +1069,35 @@ BOOL setup_hud_matrices(const LLRect& screen_region)
}
}
+bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model)
+{
+ LLRect whole_screen = get_whole_screen_region();
+ return get_hud_matrices(whole_screen, proj, model);
+}
+
+BOOL setup_hud_matrices()
+{
+ LLRect whole_screen = get_whole_screen_region();
+ return setup_hud_matrices(whole_screen);
+}
+
+BOOL setup_hud_matrices(const LLRect& screen_region)
+{
+ glh::matrix4f proj, model;
+ bool result = get_hud_matrices(screen_region, proj, model);
+ if (!result) return result;
+
+ // set up transform to keep HUD objects in front of camera
+ glMatrixMode(GL_PROJECTION);
+ glLoadMatrixf(proj.m);
+ glh_set_current_projection(proj);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixf(model.m);
+ glh_set_current_modelview(model);
+ return TRUE;
+}
+
static LLFastTimer::DeclareTimer FTM_SWAP("Swap");
void render_ui(F32 zoom_factor, int subfield)