diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-08-22 16:12:40 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-08-22 16:12:40 -0400 |
commit | a3b1a60ed76ac9661bd245e7d5bb801be852944c (patch) | |
tree | 7958d835b5f3a5f210f6361d40f1d5eeee68ef58 /indra/llmath | |
parent | 0094c4299f6fb627c0a759374ede39450efdc8d0 (diff) | |
parent | 171089207b528ab80a954292c127ba77254ee927 (diff) |
merge
Diffstat (limited to 'indra/llmath')
-rwxr-xr-x | indra/llmath/llcamera.cpp | 86 | ||||
-rwxr-xr-x | indra/llmath/llcamera.h | 37 |
2 files changed, 69 insertions, 54 deletions
diff --git a/indra/llmath/llcamera.cpp b/indra/llmath/llcamera.cpp index 22ba26f99b..33cf185196 100755 --- a/indra/llmath/llcamera.cpp +++ b/indra/llmath/llcamera.cpp @@ -42,6 +42,11 @@ LLCamera::LLCamera() : mPlaneCount(6), mFrustumCornerDist(0.f) { + for (U32 i = 0; i < PLANE_MASK_NUM; i++) + { + mPlaneMask[i] = PLANE_MASK_NONE; + } + calculateFrustumPlanes(); } @@ -52,6 +57,11 @@ LLCamera::LLCamera(F32 vertical_fov_rads, F32 aspect_ratio, S32 view_height_in_p mPlaneCount(6), mFrustumCornerDist(0.f) { + for (U32 i = 0; i < PLANE_MASK_NUM; i++) + { + mPlaneMask[i] = PLANE_MASK_NONE; + } + 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; @@ -87,14 +97,14 @@ F32 LLCamera::getMaxView() const void LLCamera::setUserClipPlane(LLPlane& plane) { - mPlaneCount = 7; - mAgentPlanes[6] = plane; - mPlaneMask[6] = plane.calcPlaneMask(); + mPlaneCount = AGENT_PLANE_USER_CLIP_NUM; + mAgentPlanes[AGENT_PLANE_USER_CLIP] = plane; + mPlaneMask[AGENT_PLANE_USER_CLIP] = plane.calcPlaneMask(); } void LLCamera::disableUserClipPlane() { - mPlaneCount = 6; + mPlaneCount = AGENT_PLANE_NO_USER_CLIP_NUM; } void LLCamera::setView(F32 vertical_fov_rads) @@ -161,31 +171,33 @@ size_t LLCamera::readFrustumFromBuffer(const char *buffer) // ---------------- test methods ---------------- -S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) +static const LLVector4a sFrustumScaler[] = { - static const LLVector4a scaler[] = { - LLVector4a(-1,-1,-1), - LLVector4a( 1,-1,-1), - LLVector4a(-1, 1,-1), - LLVector4a( 1, 1,-1), - LLVector4a(-1,-1, 1), - LLVector4a( 1,-1, 1), - LLVector4a(-1, 1, 1), - LLVector4a( 1, 1, 1) - }; + LLVector4a(-1,-1,-1), + LLVector4a( 1,-1,-1), + LLVector4a(-1, 1,-1), + LLVector4a( 1, 1,-1), + LLVector4a(-1,-1, 1), + LLVector4a( 1,-1, 1), + LLVector4a(-1, 1, 1), + LLVector4a( 1, 1, 1) // 8 entries +}; +S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) +{ U8 mask = 0; bool result = false; LLVector4a rscale, maxp, minp; LLSimdScalar d; - for (U32 i = 0; i < mPlaneCount; i++) + U32 max_planes = llmin(mPlaneCount, (U32) AGENT_PLANE_USER_CLIP_NUM); // mAgentPlanes[] size is 7 + for (U32 i = 0; i < max_planes; i++) { mask = mPlaneMask[i]; - if (mask != 0xff) + if (mask < PLANE_MASK_NUM) { const LLPlane& p(mAgentPlanes[i]); p.getAt<3>(d); - rscale.setMul(radius, scaler[mask]); + rscale.setMul(radius, sFrustumScaler[mask]); minp.setSub(center, rscale); d = -d; if (p.dot3(minp).getF32() > d) @@ -207,29 +219,19 @@ S32 LLCamera::AABBInFrustum(const LLVector4a ¢er, const LLVector4a& radius) S32 LLCamera::AABBInFrustumNoFarClip(const LLVector4a& center, const LLVector4a& radius) { - static const LLVector4a scaler[] = { - LLVector4a(-1,-1,-1), - LLVector4a( 1,-1,-1), - LLVector4a(-1, 1,-1), - LLVector4a( 1, 1,-1), - LLVector4a(-1,-1, 1), - LLVector4a( 1,-1, 1), - LLVector4a(-1, 1, 1), - LLVector4a( 1, 1, 1) - }; - U8 mask = 0; bool result = false; LLVector4a rscale, maxp, minp; LLSimdScalar d; - for (U32 i = 0; i < mPlaneCount; i++) + U32 max_planes = llmin(mPlaneCount, (U32) AGENT_PLANE_USER_CLIP_NUM); // mAgentPlanes[] size is 7 + for (U32 i = 0; i < max_planes; i++) { mask = mPlaneMask[i]; - if ((i != 5) && (mask != 0xff)) + if ((i != 5) && (mask < PLANE_MASK_NUM)) { const LLPlane& p(mAgentPlanes[i]); p.getAt<3>(d); - rscale.setMul(radius, scaler[mask]); + rscale.setMul(radius, sFrustumScaler[mask]); minp.setSub(center, rscale); d = -d; if (p.dot3(minp).getF32() > d) @@ -369,7 +371,7 @@ int LLCamera::sphereInFrustum(const LLVector3 &sphere_center, const F32 radius) bool res = false; for (int i = 0; i < 6; i++) { - if (mPlaneMask[i] != 0xff) + if (mPlaneMask[i] != PLANE_MASK_NONE) { float d = mAgentPlanes[i].dist(sphere_center); @@ -541,14 +543,14 @@ void LLCamera::ignoreAgentFrustumPlane(S32 idx) return; } - mPlaneMask[idx] = 0xff; + mPlaneMask[idx] = PLANE_MASK_NONE; mAgentPlanes[idx].clear(); } void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) { - for (int i = 0; i < 8; i++) + for (int i = 0; i < AGENT_FRUSTRUM_NUM; i++) { mAgentFrustum[i] = frust[i]; } @@ -560,22 +562,22 @@ void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) //order of planes is important, keep most likely to fail in the front of the list //near - frust[0], frust[1], frust[2] - mAgentPlanes[2] = planeFromPoints(frust[0], frust[1], frust[2]); + mAgentPlanes[AGENT_PLANE_NEAR] = planeFromPoints(frust[0], frust[1], frust[2]); //far - mAgentPlanes[5] = planeFromPoints(frust[5], frust[4], frust[6]); + mAgentPlanes[AGENT_PLANE_FAR] = planeFromPoints(frust[5], frust[4], frust[6]); //left - mAgentPlanes[0] = planeFromPoints(frust[4], frust[0], frust[7]); + mAgentPlanes[AGENT_PLANE_LEFT] = planeFromPoints(frust[4], frust[0], frust[7]); //right - mAgentPlanes[1] = planeFromPoints(frust[1], frust[5], frust[6]); + mAgentPlanes[AGENT_PLANE_RIGHT] = planeFromPoints(frust[1], frust[5], frust[6]); //top - mAgentPlanes[4] = planeFromPoints(frust[3], frust[2], frust[6]); + mAgentPlanes[AGENT_PLANE_TOP] = planeFromPoints(frust[3], frust[2], frust[6]); //bottom - mAgentPlanes[3] = planeFromPoints(frust[1], frust[0], frust[4]); + mAgentPlanes[AGENT_PLANE_BOTTOM] = planeFromPoints(frust[1], frust[0], frust[4]); //cache plane octant facing mask for use in AABBInFrustum for (U32 i = 0; i < mPlaneCount; i++) @@ -635,7 +637,7 @@ void LLCamera::calculateWorldFrustumPlanes() LLVector3 center = mOrigin - mXAxis*mNearPlane; mWorldPlanePos = center; LLVector3 pnorm; - for (int p=0; p<4; p++) + for (int p = 0; p < PLANE_NUM; p++) { mLocalPlanes[p].getVector3(pnorm); LLVector3 norm = rotateToAbsolute(pnorm); diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h index 0b591be622..1283cfb16b 100755 --- a/indra/llmath/llcamera.h +++ b/indra/llmath/llcamera.h @@ -76,26 +76,39 @@ public: PLANE_RIGHT = 1, PLANE_BOTTOM = 2, PLANE_TOP = 3, - PLANE_NUM = 4 + PLANE_NUM = 4, + PLANE_MASK_NONE = 0xff // Disable this plane }; enum { PLANE_LEFT_MASK = (1<<PLANE_LEFT), PLANE_RIGHT_MASK = (1<<PLANE_RIGHT), PLANE_BOTTOM_MASK = (1<<PLANE_BOTTOM), PLANE_TOP_MASK = (1<<PLANE_TOP), - PLANE_ALL_MASK = 0xf + PLANE_ALL_MASK = 0xf, }; enum - { + { // Indexes to mAgentPlanes[] and mPlaneMask[] AGENT_PLANE_LEFT = 0, - AGENT_PLANE_RIGHT, - AGENT_PLANE_NEAR, - AGENT_PLANE_BOTTOM, - AGENT_PLANE_TOP, - AGENT_PLANE_FAR, + AGENT_PLANE_RIGHT = 1, + AGENT_PLANE_NEAR = 2, + AGENT_PLANE_BOTTOM = 3, + AGENT_PLANE_TOP = 4, + AGENT_PLANE_FAR = 5, + AGENT_PLANE_USER_CLIP = 6 + }; + enum + { // Sizes for mAgentPlanes[]. 7th entry is special case for user clip + AGENT_PLANE_NO_USER_CLIP_NUM = 6, + AGENT_PLANE_USER_CLIP_NUM = 7, + PLANE_MASK_NUM = 8 // 7 actually used, 8 is for alignment }; + enum + { + AGENT_FRUSTRUM_NUM = 8 + }; + enum { HORIZ_PLANE_LEFT = 0, HORIZ_PLANE_RIGHT = 1, @@ -108,15 +121,15 @@ public: }; private: - LL_ALIGN_16(LLPlane mAgentPlanes[7]); //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP - U8 mPlaneMask[8]; // 8 for alignment + LL_ALIGN_16(LLPlane mAgentPlanes[AGENT_PLANE_USER_CLIP_NUM]); //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP + U8 mPlaneMask[PLANE_MASK_NUM]; // 8 for alignment F32 mView; // angle between top and bottom frustum planes in radians. F32 mAspect; // width/height S32 mViewHeightInPixels; // for ViewHeightInPixels() only F32 mNearPlane; F32 mFarPlane; - LL_ALIGN_16(LLPlane mLocalPlanes[4]); + LL_ALIGN_16(LLPlane mLocalPlanes[PLANE_NUM]); F32 mFixedDistance; // Always return this distance, unless < 0 LLVector3 mFrustCenter; // center of frustum and radius squared for ultra-quick exclusion test F32 mFrustRadiusSquared; @@ -128,7 +141,7 @@ private: LLVector3 mWorldPlanePos; // Position of World Planes (may be offset from camera) public: - LLVector3 mAgentFrustum[8]; //8 corners of 6-plane frustum + LLVector3 mAgentFrustum[AGENT_FRUSTRUM_NUM]; //8 corners of 6-plane frustum F32 mFrustumCornerDist; //distance to corner of frustum against far clip plane LLPlane& getAgentPlane(U32 idx) { return mAgentPlanes[idx]; } |