summaryrefslogtreecommitdiff
path: root/indra/newview/llviewercamera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewercamera.cpp')
-rw-r--r--indra/newview/llviewercamera.cpp122
1 files changed, 75 insertions, 47 deletions
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index 72d1494d96..3f3c10a7c7 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -31,18 +31,12 @@
*/
#include "llviewerprecompiledheaders.h"
-#include "llviewercamera.h"
-
-#include <iomanip> // for setprecision
-#include "llquaternion.h"
+#include "llviewercamera.h"
+// Viewer includes
#include "llagent.h"
#include "llviewercontrol.h"
-#include "lldrawable.h"
-#include "llface.h"
-#include "llgl.h"
-#include "llglheaders.h"
#include "llviewerobjectlist.h"
#include "llviewerregion.h"
#include "llviewerwindow.h"
@@ -51,6 +45,17 @@
#include "lltoolmgr.h"
#include "llviewerjoystick.h"
+// Linden library includes
+#include "lldrawable.h"
+#include "llface.h"
+#include "llgl.h"
+#include "llglheaders.h"
+#include "llquaternion.h"
+#include "llwindow.h" // getPixelAspectRatio()
+
+// System includes
+#include <iomanip> // for setprecision
+
//glu pick matrix implementation borrowed from Mesa3D
glh::matrix4f gl_pick_matrix(GLfloat x, GLfloat y, GLfloat width, GLfloat height, GLint* viewport)
{
@@ -106,6 +111,7 @@ LLViewerCamera::LLViewerCamera() : LLCamera()
mScreenPixelArea = 0;
mZoomFactor = 1.f;
mZoomSubregion = 1;
+ gSavedSettings.getControl("CameraAngle")->getCommitSignal()->connect(boost::bind(&LLViewerCamera::updateCameraAngle, this, _2));
}
void LLViewerCamera::updateCameraLocation(const LLVector3 &center,
@@ -452,8 +458,15 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
}
}
+ LLRect world_view_rect = gViewerWindow->getWorldViewRect();
+ S32 viewport[4];
+ viewport[0] = world_view_rect.mLeft;
+ viewport[1] = world_view_rect.mBottom;
+ viewport[2] = world_view_rect.getWidth();
+ viewport[3] = world_view_rect.getHeight();
+
if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ],
- gGLModelView, gGLProjection, (GLint*)gGLViewport,
+ gGLModelView, gGLProjection, (GLint*)viewport,
&x, &y, &z))
{
// convert screen coordinates to virtual UI coordinates
@@ -461,9 +474,9 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
y /= gViewerWindow->getDisplayScale().mV[VY];
// should now have the x,y coords of grab_point in screen space
- const LLRect& window_rect = gViewerWindow->getWindowRect();
+ LLRect world_view_rect = gViewerWindow->getVirtualWorldViewRect();
- // ...sanity check
+ // convert to pixel coordinates
S32 int_x = lltrunc(x);
S32 int_y = lltrunc(y);
@@ -471,14 +484,14 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
if (clamp)
{
- if (int_x < window_rect.mLeft)
+ if (int_x < world_view_rect.mLeft)
{
- out_point.mX = window_rect.mLeft;
+ out_point.mX = world_view_rect.mLeft;
valid = FALSE;
}
- else if (int_x > window_rect.mRight)
+ else if (int_x > world_view_rect.mRight)
{
- out_point.mX = window_rect.mRight;
+ out_point.mX = world_view_rect.mRight;
valid = FALSE;
}
else
@@ -486,14 +499,14 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
out_point.mX = int_x;
}
- if (int_y < window_rect.mBottom)
+ if (int_y < world_view_rect.mBottom)
{
- out_point.mY = window_rect.mBottom;
+ out_point.mY = world_view_rect.mBottom;
valid = FALSE;
}
- else if (int_y > window_rect.mTop)
+ else if (int_y > world_view_rect.mTop)
{
- out_point.mY = window_rect.mTop;
+ out_point.mY = world_view_rect.mTop;
valid = FALSE;
}
else
@@ -507,19 +520,19 @@ BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
out_point.mX = int_x;
out_point.mY = int_y;
- if (int_x < window_rect.mLeft)
+ if (int_x < world_view_rect.mLeft)
{
valid = FALSE;
}
- else if (int_x > window_rect.mRight)
+ else if (int_x > world_view_rect.mRight)
{
valid = FALSE;
}
- if (int_y < window_rect.mBottom)
+ if (int_y < world_view_rect.mBottom)
{
valid = FALSE;
}
- else if (int_y > window_rect.mTop)
+ else if (int_y > world_view_rect.mTop)
{
valid = FALSE;
}
@@ -548,24 +561,30 @@ BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
in_front = FALSE;
}
+ LLRect world_view_rect = gViewerWindow->getWorldViewRect();
+ S32 viewport[4];
+ viewport[0] = world_view_rect.mLeft;
+ viewport[1] = world_view_rect.mBottom;
+ viewport[2] = world_view_rect.getWidth();
+ viewport[3] = world_view_rect.getHeight();
GLdouble x, y, z; // object's window coords, GL-style
if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY],
pos_agent.mV[VZ], gGLModelView,
- gGLProjection, (GLint*)gGLViewport,
+ gGLProjection, (GLint*)viewport,
&x, &y, &z))
{
x /= gViewerWindow->getDisplayScale().mV[VX];
y /= gViewerWindow->getDisplayScale().mV[VY];
// should now have the x,y coords of grab_point in screen space
- const LLRect& window_rect = gViewerWindow->getVirtualWindowRect();
+ const LLRect& world_rect = gViewerWindow->getVirtualWorldViewRect();
// ...sanity check
S32 int_x = lltrunc(x);
S32 int_y = lltrunc(y);
// find the center
- GLdouble center_x = (GLdouble)(0.5f * (window_rect.mLeft + window_rect.mRight));
- GLdouble center_y = (GLdouble)(0.5f * (window_rect.mBottom + window_rect.mTop));
+ GLdouble center_x = (GLdouble)world_rect.getCenterX();
+ GLdouble center_y = (GLdouble)world_rect.getCenterY();
if (x == center_x && y == center_y)
{
@@ -586,41 +605,41 @@ BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
// the slope of the line is undefined
if (line_y > 0.f)
{
- int_y = window_rect.mTop;
+ int_y = world_rect.mTop;
}
else
{
- int_y = window_rect.mBottom;
+ int_y = world_rect.mBottom;
}
}
- else if (0 == window_rect.getWidth())
+ else if (0 == world_rect.getWidth())
{
// the diagonal slope of the view is undefined
- if (y < window_rect.mBottom)
+ if (y < world_rect.mBottom)
{
- int_y = window_rect.mBottom;
+ int_y = world_rect.mBottom;
}
- else if ( y > window_rect.mTop)
+ else if ( y > world_rect.mTop)
{
- int_y = window_rect.mTop;
+ int_y = world_rect.mTop;
}
}
else
{
F32 line_slope = (F32)(line_y / line_x);
- F32 rect_slope = ((F32)window_rect.getHeight()) / ((F32)window_rect.getWidth());
+ F32 rect_slope = ((F32)world_rect.getHeight()) / ((F32)world_rect.getWidth());
if (fabs(line_slope) > rect_slope)
{
if (line_y < 0.f)
{
// bottom
- int_y = window_rect.mBottom;
+ int_y = world_rect.mBottom;
}
else
{
// top
- int_y = window_rect.mTop;
+ int_y = world_rect.mTop;
}
int_x = lltrunc(((GLdouble)int_y - center_y) / line_slope + center_x);
}
@@ -629,12 +648,12 @@ BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
if (line_x < 0.f)
{
// left
- int_x = window_rect.mLeft;
+ int_x = world_rect.mLeft;
}
else
{
// right
- int_x = window_rect.mRight;
+ int_x = world_rect.mRight;
}
int_y = lltrunc(((GLdouble)int_x - center_x) * line_slope + center_y);
}
@@ -643,29 +662,30 @@ BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
// exactly parallel ==> push to the corners
if (line_x > 0.f)
{
- int_x = window_rect.mRight;
+ int_x = world_rect.mRight;
}
else
{
- int_x = window_rect.mLeft;
+ int_x = world_rect.mLeft;
}
if (line_y > 0.0f)
{
- int_y = window_rect.mTop;
+ int_y = world_rect.mTop;
}
else
{
- int_y = window_rect.mBottom;
+ int_y = world_rect.mBottom;
}
}
}
if (!in_front)
{
- int_x = window_rect.mLeft + window_rect.mRight - int_x;
- int_y = window_rect.mBottom + window_rect.mTop - int_y;
+ int_x = world_rect.mLeft + world_rect.mRight - int_x;
+ int_y = world_rect.mBottom + world_rect.mTop - int_y;
}
- out_point.mX = int_x;
- out_point.mY = int_y;
+
+ out_point.mX = int_x + world_rect.mLeft;
+ out_point.mY = int_y + world_rect.mBottom;
return TRUE;
}
return FALSE;
@@ -803,3 +823,11 @@ void LLViewerCamera::setDefaultFOV(F32 vertical_fov_rads) {
mCameraFOVDefault = vertical_fov_rads;
}
+
+// static
+void LLViewerCamera::updateCameraAngle( void* user_data, const LLSD& value)
+{
+ LLViewerCamera* self=(LLViewerCamera*)user_data;
+ self->setDefaultFOV(value.asReal());
+}
+