summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
authorMelinda Green <melinda@lindenlab.com>2008-12-15 21:21:19 +0000
committerMelinda Green <melinda@lindenlab.com>2008-12-15 21:21:19 +0000
commite1d8dac25a93db837c780428a23f81cbf9109270 (patch)
treea0bcaec0cec1ba6b3ce813764650eada61fcde4f /indra/llmath
parent9c0dbb123376608e464fcd8d1a2e288e01d78a3f (diff)
svn merge -r105329:105903 svn+ssh://svn/svn/linden/branches/featurettes/featurettes-batch4-merge
Resolving QAR-1051 Merge featurettes batch #4
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/llcamera.cpp57
-rw-r--r--indra/llmath/llcamera.h22
-rw-r--r--indra/llmath/lloctree.h4
3 files changed, 44 insertions, 39 deletions
diff --git a/indra/llmath/llcamera.cpp b/indra/llmath/llcamera.cpp
index 3b9ba9d0f7..6c28013af8 100644
--- a/indra/llmath/llcamera.cpp
+++ b/indra/llmath/llcamera.cpp
@@ -50,33 +50,38 @@ LLCamera::LLCamera() :
}
-LLCamera::LLCamera(F32 z_field_of_view, F32 aspect_ratio, S32 view_height_in_pixels, F32 near_plane, F32 far_plane) :
+LLCamera::LLCamera(F32 vertical_fov_rads, F32 aspect_ratio, S32 view_height_in_pixels, F32 near_plane, F32 far_plane) :
LLCoordFrame(),
- mView(z_field_of_view),
- mAspect(aspect_ratio),
mViewHeightInPixels(view_height_in_pixels),
- mNearPlane(near_plane),
- mFarPlane(far_plane),
mFixedDistance(-1.f),
mPlaneCount(6)
{
- if (mView < MIN_FIELD_OF_VIEW) { mView = MIN_FIELD_OF_VIEW; }
- else if (mView > MAX_FIELD_OF_VIEW) { mView = MAX_FIELD_OF_VIEW; }
+ mAspect = llclamp(aspect_ratio, MIN_ASPECT_RATIO, MAX_ASPECT_RATIO);
+ mNearPlane = llclamp(near_plane, MIN_NEAR_PLANE, MAX_NEAR_PLANE);
+ if(far_plane < 0) far_plane = DEFAULT_FAR_PLANE;
+ mFarPlane = llclamp(far_plane, MIN_FAR_PLANE, MAX_FAR_PLANE);
- if (mAspect < MIN_ASPECT_RATIO) { mAspect = MIN_ASPECT_RATIO; }
- else if (mAspect > MAX_ASPECT_RATIO) { mAspect = MAX_ASPECT_RATIO; }
-
- if (mNearPlane < MIN_NEAR_PLANE) { mNearPlane = MIN_NEAR_PLANE; }
- else if (mNearPlane > MAX_NEAR_PLANE) { mNearPlane = MAX_NEAR_PLANE; }
+ setView(vertical_fov_rads);
+}
- if (mFarPlane < 0) { mFarPlane = DEFAULT_FAR_PLANE; }
- else if (mFarPlane < MIN_FAR_PLANE) { mFarPlane = MIN_FAR_PLANE; }
- else if (mFarPlane > MAX_FAR_PLANE) { mFarPlane = MAX_FAR_PLANE; }
- calculateFrustumPlanes();
-}
+// ---------------- LLCamera::getFoo() member functions ----------------
+F32 LLCamera::getMinView() const
+{
+ // minimum vertical fov needs to be constrained in narrow windows.
+ return mAspect > 1
+ ? MIN_FIELD_OF_VIEW // wide views
+ : MIN_FIELD_OF_VIEW * 1/mAspect; // clamps minimum width in narrow views
+}
+F32 LLCamera::getMaxView() const
+{
+ // maximum vertical fov needs to be constrained in wide windows.
+ return mAspect > 1
+ ? MAX_FIELD_OF_VIEW / mAspect // clamps maximum width in wide views
+ : MAX_FIELD_OF_VIEW; // narrow views
+}
// ---------------- LLCamera::setFoo() member functions ----------------
@@ -92,11 +97,9 @@ void LLCamera::disableUserClipPlane()
mPlaneCount = 6;
}
-void LLCamera::setView(F32 field_of_view)
+void LLCamera::setView(F32 vertical_fov_rads)
{
- mView = field_of_view;
- if (mView < MIN_FIELD_OF_VIEW) { mView = MIN_FIELD_OF_VIEW; }
- else if (mView > MAX_FIELD_OF_VIEW) { mView = MAX_FIELD_OF_VIEW; }
+ mView = llclamp(vertical_fov_rads, MIN_FIELD_OF_VIEW, MAX_FIELD_OF_VIEW);
calculateFrustumPlanes();
}
@@ -110,27 +113,21 @@ void LLCamera::setViewHeightInPixels(S32 height)
void LLCamera::setAspect(F32 aspect_ratio)
{
- mAspect = aspect_ratio;
- if (mAspect < MIN_ASPECT_RATIO) { mAspect = MIN_ASPECT_RATIO; }
- else if (mAspect > MAX_ASPECT_RATIO) { mAspect = MAX_ASPECT_RATIO; }
+ mAspect = llclamp(aspect_ratio, MIN_ASPECT_RATIO, MAX_ASPECT_RATIO);
calculateFrustumPlanes();
}
void LLCamera::setNear(F32 near_plane)
{
- mNearPlane = near_plane;
- if (mNearPlane < MIN_NEAR_PLANE) { mNearPlane = MIN_NEAR_PLANE; }
- else if (mNearPlane > MAX_NEAR_PLANE) { mNearPlane = MAX_NEAR_PLANE; }
+ mNearPlane = llclamp(near_plane, MIN_NEAR_PLANE, MAX_NEAR_PLANE);
calculateFrustumPlanes();
}
void LLCamera::setFar(F32 far_plane)
{
- mFarPlane = far_plane;
- if (mFarPlane < MIN_FAR_PLANE) { mFarPlane = MIN_FAR_PLANE; }
- else if (mFarPlane > MAX_FAR_PLANE) { mFarPlane = MAX_FAR_PLANE; }
+ mFarPlane = llclamp(far_plane, MIN_FAR_PLANE, MAX_FAR_PLANE);
calculateFrustumPlanes();
}
diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h
index 82c712e5e7..094e59fd0a 100644
--- a/indra/llmath/llcamera.h
+++ b/indra/llmath/llcamera.h
@@ -42,17 +42,19 @@ const F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f;
const F32 DEFAULT_NEAR_PLANE = 0.25f;
const F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions
-const F32 MAX_FIELD_OF_VIEW = F_PI;
const F32 MAX_ASPECT_RATIO = 50.0f;
const F32 MAX_NEAR_PLANE = 10.f;
const F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though.
const F32 MAX_FAR_CLIP = 512.0f;
-const F32 MIN_FIELD_OF_VIEW = 0.1f;
const F32 MIN_ASPECT_RATIO = 0.02f;
const F32 MIN_NEAR_PLANE = 0.1f;
const F32 MIN_FAR_PLANE = 0.2f;
+// Min/Max FOV values for square views. Call getMin/MaxView to get extremes based on current aspect ratio.
+static const F32 MIN_FIELD_OF_VIEW = 5.0f * DEG_TO_RAD;
+static const F32 MAX_FIELD_OF_VIEW = 175.f * DEG_TO_RAD;
+
static const LLVector3 X_AXIS(1.f,0.f,0.f);
static const LLVector3 Y_AXIS(0.f,1.f,0.f);
static const LLVector3 Z_AXIS(0.f,0.f,1.f);
@@ -101,7 +103,7 @@ public:
HORIZ_PLANE_ALL_MASK = 0x3
};
-protected:
+private:
F32 mView; // angle between top and bottom frustum planes in radians.
F32 mAspect; // width/height
S32 mViewHeightInPixels; // for ViewHeightInPixels() only
@@ -117,12 +119,12 @@ protected:
struct frustum_plane
{
- frustum_plane() : mask(0) {}
+ frustum_plane() : mask(0) {}
LLPlane p;
U8 mask;
};
frustum_plane mAgentPlanes[7]; //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP
-
+
U32 mPlaneCount; //defaults to 6, if setUserClipPlane is called, uses user supplied clip plane in
LLVector3 mWorldPlanePos; // Position of World Planes (may be offset from camera)
@@ -132,12 +134,13 @@ public:
public:
LLCamera();
- LLCamera(F32 z_field_of_view, F32 aspect_ratio, S32 view_height_in_pixels, F32 near_plane, F32 far_plane);
+ LLCamera(F32 vertical_fov_rads, F32 aspect_ratio, S32 view_height_in_pixels, F32 near_plane, F32 far_plane);
+ virtual ~LLCamera(){} // no-op virtual destructor
void setUserClipPlane(LLPlane plane);
void disableUserClipPlane();
U8 calcPlaneMask(const LLPlane& plane);
- void setView(F32 new_view);
+ virtual void setView(F32 vertical_fov_rads);
void setViewHeightInPixels(S32 height);
void setAspect(F32 new_aspect);
void setNear(F32 new_near);
@@ -148,6 +151,11 @@ public:
F32 getAspect() const { return mAspect; } // width / height
F32 getNear() const { return mNearPlane; } // meters
F32 getFar() const { return mFarPlane; } // meters
+
+ // The values returned by the min/max view getters depend upon the aspect ratio
+ // at the time they are called and therefore should not be cached.
+ F32 getMinView() const;
+ F32 getMaxView() const;
F32 getYaw() const
{
diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h
index 25b7100eb7..5a1efdbe28 100644
--- a/indra/llmath/lloctree.h
+++ b/indra/llmath/lloctree.h
@@ -38,9 +38,9 @@
#include <set>
#if LL_RELEASE_WITH_DEBUG_INFO || LL_DEBUG
-#define OCT_ERRS LL_WARNS("OctreeErrors")
-#else
#define OCT_ERRS LL_ERRS("OctreeErrors")
+#else
+#define OCT_ERRS LL_WARNS("OctreeErrors")
#endif
#define LL_OCTREE_PARANOIA_CHECK 0