diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmath/llcamera.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmath/llcamera.cpp | 127 |
1 files changed, 96 insertions, 31 deletions
diff --git a/linden/indra/llmath/llcamera.cpp b/linden/indra/llmath/llcamera.cpp index 82c401f..7a9d576 100644 --- a/linden/indra/llmath/llcamera.cpp +++ b/linden/indra/llmath/llcamera.cpp | |||
@@ -43,7 +43,8 @@ LLCamera::LLCamera() : | |||
43 | mViewHeightInPixels( -1 ), // invalid height | 43 | mViewHeightInPixels( -1 ), // invalid height |
44 | mNearPlane(DEFAULT_NEAR_PLANE), | 44 | mNearPlane(DEFAULT_NEAR_PLANE), |
45 | mFarPlane(DEFAULT_FAR_PLANE), | 45 | mFarPlane(DEFAULT_FAR_PLANE), |
46 | mFixedDistance(-1.f) | 46 | mFixedDistance(-1.f), |
47 | mPlaneCount(6) | ||
47 | { | 48 | { |
48 | calculateFrustumPlanes(); | 49 | calculateFrustumPlanes(); |
49 | } | 50 | } |
@@ -56,7 +57,8 @@ LLCamera::LLCamera(F32 z_field_of_view, F32 aspect_ratio, S32 view_height_in_pix | |||
56 | mViewHeightInPixels(view_height_in_pixels), | 57 | mViewHeightInPixels(view_height_in_pixels), |
57 | mNearPlane(near_plane), | 58 | mNearPlane(near_plane), |
58 | mFarPlane(far_plane), | 59 | mFarPlane(far_plane), |
59 | mFixedDistance(-1.f) | 60 | mFixedDistance(-1.f), |
61 | mPlaneCount(6) | ||
60 | { | 62 | { |
61 | if (mView < MIN_FIELD_OF_VIEW) { mView = MIN_FIELD_OF_VIEW; } | 63 | if (mView < MIN_FIELD_OF_VIEW) { mView = MIN_FIELD_OF_VIEW; } |
62 | else if (mView > MAX_FIELD_OF_VIEW) { mView = MAX_FIELD_OF_VIEW; } | 64 | else if (mView > MAX_FIELD_OF_VIEW) { mView = MAX_FIELD_OF_VIEW; } |
@@ -78,6 +80,18 @@ LLCamera::LLCamera(F32 z_field_of_view, F32 aspect_ratio, S32 view_height_in_pix | |||
78 | 80 | ||
79 | // ---------------- LLCamera::setFoo() member functions ---------------- | 81 | // ---------------- LLCamera::setFoo() member functions ---------------- |
80 | 82 | ||
83 | void LLCamera::setUserClipPlane(LLPlane plane) | ||
84 | { | ||
85 | mPlaneCount = 7; | ||
86 | mAgentPlanes[6].p = plane; | ||
87 | mAgentPlanes[6].mask = calcPlaneMask(plane); | ||
88 | } | ||
89 | |||
90 | void LLCamera::disableUserClipPlane() | ||
91 | { | ||
92 | mPlaneCount = 6; | ||
93 | } | ||
94 | |||
81 | void LLCamera::setView(F32 field_of_view) | 95 | void LLCamera::setView(F32 field_of_view) |
82 | { | 96 | { |
83 | mView = field_of_view; | 97 | mView = field_of_view; |
@@ -150,7 +164,7 @@ size_t LLCamera::readFrustumFromBuffer(const char *buffer) | |||
150 | 164 | ||
151 | // ---------------- test methods ---------------- | 165 | // ---------------- test methods ---------------- |
152 | 166 | ||
153 | int LLCamera::AABBInFrustum(const LLVector3 ¢er, const LLVector3& radius) | 167 | S32 LLCamera::AABBInFrustum(const LLVector3 ¢er, const LLVector3& radius) |
154 | { | 168 | { |
155 | static const LLVector3 scaler[] = { | 169 | static const LLVector3 scaler[] = { |
156 | LLVector3(-1,-1,-1), | 170 | LLVector3(-1,-1,-1), |
@@ -166,10 +180,56 @@ int LLCamera::AABBInFrustum(const LLVector3 ¢er, const LLVector3& radius) | |||
166 | U8 mask = 0; | 180 | U8 mask = 0; |
167 | S32 result = 2; | 181 | S32 result = 2; |
168 | 182 | ||
169 | for (int i = 0; i < 6; i++) | 183 | for (U32 i = 0; i < mPlaneCount; i++) |
184 | { | ||
185 | mask = mAgentPlanes[i].mask; | ||
186 | LLPlane p = mAgentPlanes[i].p; | ||
187 | LLVector3 n = LLVector3(p); | ||
188 | float d = p.mV[3]; | ||
189 | LLVector3 rscale = radius.scaledVec(scaler[mask]); | ||
190 | |||
191 | LLVector3 minp = center - rscale; | ||
192 | LLVector3 maxp = center + rscale; | ||
193 | |||
194 | if (n * minp > -d) | ||
195 | { | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | if (n * maxp > -d) | ||
200 | { | ||
201 | result = 1; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | return result; | ||
206 | } | ||
207 | |||
208 | S32 LLCamera::AABBInFrustumNoFarClip(const LLVector3 ¢er, const LLVector3& radius) | ||
209 | { | ||
210 | static const LLVector3 scaler[] = { | ||
211 | LLVector3(-1,-1,-1), | ||
212 | LLVector3( 1,-1,-1), | ||
213 | LLVector3(-1, 1,-1), | ||
214 | LLVector3( 1, 1,-1), | ||
215 | LLVector3(-1,-1, 1), | ||
216 | LLVector3( 1,-1, 1), | ||
217 | LLVector3(-1, 1, 1), | ||
218 | LLVector3( 1, 1, 1) | ||
219 | }; | ||
220 | |||
221 | U8 mask = 0; | ||
222 | S32 result = 2; | ||
223 | |||
224 | for (U32 i = 0; i < mPlaneCount; i++) | ||
170 | { | 225 | { |
171 | mask = mAgentPlaneMask[i]; | 226 | if (i == 5) |
172 | LLPlane p = mAgentPlanes[i]; | 227 | { |
228 | continue; | ||
229 | } | ||
230 | |||
231 | mask = mAgentPlanes[i].mask; | ||
232 | LLPlane p = mAgentPlanes[i].p; | ||
173 | LLVector3 n = LLVector3(p); | 233 | LLVector3 n = LLVector3(p); |
174 | float d = p.mV[3]; | 234 | float d = p.mV[3]; |
175 | LLVector3 rscale = radius.scaledVec(scaler[mask]); | 235 | LLVector3 rscale = radius.scaledVec(scaler[mask]); |
@@ -312,7 +372,7 @@ int LLCamera::sphereInFrustum(const LLVector3 &sphere_center, const F32 radius) | |||
312 | int res = 2; | 372 | int res = 2; |
313 | for (int i = 0; i < 6; i++) | 373 | for (int i = 0; i < 6; i++) |
314 | { | 374 | { |
315 | float d = mAgentPlanes[i].dist(sphere_center); | 375 | float d = mAgentPlanes[i].p.dist(sphere_center); |
316 | 376 | ||
317 | if (d > radius) | 377 | if (d > radius) |
318 | { | 378 | { |
@@ -477,6 +537,25 @@ LLPlane planeFromPoints(LLVector3 p1, LLVector3 p2, LLVector3 p3) | |||
477 | return LLPlane(p1, n); | 537 | return LLPlane(p1, n); |
478 | } | 538 | } |
479 | 539 | ||
540 | U8 LLCamera::calcPlaneMask(const LLPlane& plane) | ||
541 | { | ||
542 | U8 mask = 0; | ||
543 | |||
544 | if (plane.mV[0] >= 0) | ||
545 | { | ||
546 | mask |= 1; | ||
547 | } | ||
548 | if (plane.mV[1] >= 0) | ||
549 | { | ||
550 | mask |= 2; | ||
551 | } | ||
552 | if (plane.mV[2] >= 0) | ||
553 | { | ||
554 | mask |= 4; | ||
555 | } | ||
556 | |||
557 | return mask; | ||
558 | } | ||
480 | 559 | ||
481 | void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) | 560 | void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) |
482 | { | 561 | { |
@@ -486,48 +565,34 @@ void LLCamera::calcAgentFrustumPlanes(LLVector3* frust) | |||
486 | mAgentFrustum[i] = frust[i]; | 565 | mAgentFrustum[i] = frust[i]; |
487 | } | 566 | } |
488 | 567 | ||
568 | mFrustumCornerDist = (frust[5] - getOrigin()).magVec(); | ||
569 | |||
489 | //frust contains the 8 points of the frustum, calculate 6 planes | 570 | //frust contains the 8 points of the frustum, calculate 6 planes |
490 | 571 | ||
491 | //order of planes is important, keep most likely to fail in the front of the list | 572 | //order of planes is important, keep most likely to fail in the front of the list |
492 | 573 | ||
493 | //near - frust[0], frust[1], frust[2] | 574 | //near - frust[0], frust[1], frust[2] |
494 | mAgentPlanes[2] = planeFromPoints(frust[0], frust[1], frust[2]); | 575 | mAgentPlanes[2].p = planeFromPoints(frust[0], frust[1], frust[2]); |
495 | 576 | ||
496 | //far | 577 | //far |
497 | mAgentPlanes[5] = planeFromPoints(frust[5], frust[4], frust[6]); | 578 | mAgentPlanes[5].p = planeFromPoints(frust[5], frust[4], frust[6]); |
498 | 579 | ||
499 | //left | 580 | //left |
500 | mAgentPlanes[0] = planeFromPoints(frust[4], frust[0], frust[7]); | 581 | mAgentPlanes[0].p = planeFromPoints(frust[4], frust[0], frust[7]); |
501 | 582 | ||
502 | //right | 583 | //right |
503 | mAgentPlanes[1] = planeFromPoints(frust[1], frust[5], frust[6]); | 584 | mAgentPlanes[1].p = planeFromPoints(frust[1], frust[5], frust[6]); |
504 | 585 | ||
505 | //top | 586 | //top |
506 | mAgentPlanes[4] = planeFromPoints(frust[3], frust[2], frust[6]); | 587 | mAgentPlanes[4].p = planeFromPoints(frust[3], frust[2], frust[6]); |
507 | 588 | ||
508 | //bottom | 589 | //bottom |
509 | mAgentPlanes[3] = planeFromPoints(frust[1], frust[0], frust[4]); | 590 | mAgentPlanes[3].p = planeFromPoints(frust[1], frust[0], frust[4]); |
510 | 591 | ||
511 | //cache plane octant facing mask for use in AABBInFrustum | 592 | //cache plane octant facing mask for use in AABBInFrustum |
512 | for (int i = 0; i < 6; i++) | 593 | for (U32 i = 0; i < mPlaneCount; i++) |
513 | { | 594 | { |
514 | U8 mask = 0; | 595 | mAgentPlanes[i].mask = calcPlaneMask(mAgentPlanes[i].p); |
515 | LLPlane p = mAgentPlanes[i]; | ||
516 | LLVector3 n = LLVector3(p); | ||
517 | |||
518 | if (n.mV[0] >= 0) | ||
519 | { | ||
520 | mask |= 1; | ||
521 | } | ||
522 | if (n.mV[1] >= 0) | ||
523 | { | ||
524 | mask |= 2; | ||
525 | } | ||
526 | if (n.mV[2] >= 0) | ||
527 | { | ||
528 | mask |= 4; | ||
529 | } | ||
530 | mAgentPlaneMask[i] = mask; | ||
531 | } | 596 | } |
532 | } | 597 | } |
533 | 598 | ||