diff options
author | Jacek Antonelli | 2008-09-06 18:24:57 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-09-06 18:25:07 -0500 |
commit | 798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch) | |
tree | 1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llspatialpartition.cpp | |
parent | Second Life viewer sources 1.20.15 (diff) | |
download | meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2 meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz |
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/newview/llspatialpartition.cpp')
-rw-r--r-- | linden/indra/newview/llspatialpartition.cpp | 178 |
1 files changed, 135 insertions, 43 deletions
diff --git a/linden/indra/newview/llspatialpartition.cpp b/linden/indra/newview/llspatialpartition.cpp index 4ec5720..9f5d115 100644 --- a/linden/indra/newview/llspatialpartition.cpp +++ b/linden/indra/newview/llspatialpartition.cpp | |||
@@ -36,6 +36,7 @@ | |||
36 | #include "llviewerwindow.h" | 36 | #include "llviewerwindow.h" |
37 | #include "llviewerobjectlist.h" | 37 | #include "llviewerobjectlist.h" |
38 | #include "llvovolume.h" | 38 | #include "llvovolume.h" |
39 | #include "llvolume.h" | ||
39 | #include "llviewercamera.h" | 40 | #include "llviewercamera.h" |
40 | #include "llface.h" | 41 | #include "llface.h" |
41 | #include "llviewercontrol.h" | 42 | #include "llviewercontrol.h" |
@@ -243,28 +244,6 @@ void LLSpatialGroup::buildOcclusion() | |||
243 | 244 | ||
244 | BOOL earlyFail(LLCamera* camera, LLSpatialGroup* group); | 245 | BOOL earlyFail(LLCamera* camera, LLSpatialGroup* group); |
245 | 246 | ||
246 | BOOL LLLineSegmentAABB(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size) | ||
247 | { | ||
248 | float fAWdU[3]; | ||
249 | LLVector3 dir; | ||
250 | LLVector3 diff; | ||
251 | |||
252 | for (U32 i = 0; i < 3; i++) | ||
253 | { | ||
254 | dir.mV[i] = 0.5f * (end.mV[i] - start.mV[i]); | ||
255 | diff.mV[i] = (0.5f * (end.mV[i] + start.mV[i])) - center.mV[i]; | ||
256 | fAWdU[i] = fabsf(dir.mV[i]); | ||
257 | if(fabsf(diff.mV[i])>size.mV[i] + fAWdU[i]) return false; | ||
258 | } | ||
259 | |||
260 | float f; | ||
261 | f = dir.mV[1] * diff.mV[2] - dir.mV[2] * diff.mV[1]; if(fabsf(f)>size.mV[1]*fAWdU[2] + size.mV[2]*fAWdU[1]) return false; | ||
262 | f = dir.mV[2] * diff.mV[0] - dir.mV[0] * diff.mV[2]; if(fabsf(f)>size.mV[0]*fAWdU[2] + size.mV[2]*fAWdU[0]) return false; | ||
263 | f = dir.mV[0] * diff.mV[1] - dir.mV[1] * diff.mV[0]; if(fabsf(f)>size.mV[0]*fAWdU[1] + size.mV[1]*fAWdU[0]) return false; | ||
264 | |||
265 | return true; | ||
266 | } | ||
267 | |||
268 | //returns: | 247 | //returns: |
269 | // 0 if sphere and AABB are not intersecting | 248 | // 0 if sphere and AABB are not intersecting |
270 | // 1 if they are | 249 | // 1 if they are |
@@ -2170,7 +2149,8 @@ void renderBoundingBox(LLDrawable* drawable) | |||
2170 | if (vobj && vobj->onActiveList()) | 2149 | if (vobj && vobj->onActiveList()) |
2171 | { | 2150 | { |
2172 | gGL.flush(); | 2151 | gGL.flush(); |
2173 | glLineWidth(4.f*sinf(gFrameTimeSeconds*2.f)+1.f); | 2152 | glLineWidth(4.f*(sinf(gFrameTimeSeconds*2.f)*0.25f+0.75f)); |
2153 | stop_glerror(); | ||
2174 | drawBoxOutline(pos,size); | 2154 | drawBoxOutline(pos,size); |
2175 | gGL.flush(); | 2155 | gGL.flush(); |
2176 | glLineWidth(1.f); | 2156 | glLineWidth(1.f); |
@@ -2305,6 +2285,56 @@ void renderLights(LLDrawable* drawablep) | |||
2305 | } | 2285 | } |
2306 | } | 2286 | } |
2307 | 2287 | ||
2288 | |||
2289 | void renderRaycast(LLDrawable* drawablep) | ||
2290 | { | ||
2291 | if (drawablep->getVObj() != gDebugRaycastObject) | ||
2292 | { | ||
2293 | return; | ||
2294 | } | ||
2295 | |||
2296 | if (drawablep->getNumFaces()) | ||
2297 | { | ||
2298 | LLGLEnable blend(GL_BLEND); | ||
2299 | gGL.color4f(0,1,1,0.5f); | ||
2300 | |||
2301 | for (S32 i = 0; i < drawablep->getNumFaces(); i++) | ||
2302 | { | ||
2303 | pushVerts(drawablep->getFace(i), LLVertexBuffer::MAP_VERTEX); | ||
2304 | } | ||
2305 | |||
2306 | // draw intersection point | ||
2307 | glPushMatrix(); | ||
2308 | glLoadMatrixd(gGLModelView); | ||
2309 | LLVector3 translate = gDebugRaycastIntersection; | ||
2310 | glTranslatef(translate.mV[0], translate.mV[1], translate.mV[2]); | ||
2311 | LLCoordFrame orient; | ||
2312 | orient.lookDir(gDebugRaycastNormal, gDebugRaycastBinormal); | ||
2313 | LLMatrix4 rotation; | ||
2314 | orient.getRotMatrixToParent(rotation); | ||
2315 | glMultMatrixf((float*)rotation.mMatrix); | ||
2316 | |||
2317 | gGL.color4f(1,0,0,0.5f); | ||
2318 | drawBox(LLVector3(0, 0, 0), LLVector3(0.1f, 0.022f, 0.022f)); | ||
2319 | gGL.color4f(0,1,0,0.5f); | ||
2320 | drawBox(LLVector3(0, 0, 0), LLVector3(0.021f, 0.1f, 0.021f)); | ||
2321 | gGL.color4f(0,0,1,0.5f); | ||
2322 | drawBox(LLVector3(0, 0, 0), LLVector3(0.02f, 0.02f, 0.1f)); | ||
2323 | glPopMatrix(); | ||
2324 | |||
2325 | // draw bounding box of prim | ||
2326 | const LLVector3* ext = drawablep->getSpatialExtents(); | ||
2327 | |||
2328 | LLVector3 pos = (ext[0] + ext[1]) * 0.5f; | ||
2329 | LLVector3 size = (ext[1] - ext[0]) * 0.5f; | ||
2330 | |||
2331 | LLGLDepthTest depth(GL_FALSE, GL_TRUE); | ||
2332 | gGL.color4f(0,0.5f,0.5f,1); | ||
2333 | drawBoxOutline(pos, size); | ||
2334 | |||
2335 | } | ||
2336 | } | ||
2337 | |||
2308 | class LLOctreeRenderNonOccluded : public LLOctreeTraveler<LLDrawable> | 2338 | class LLOctreeRenderNonOccluded : public LLOctreeTraveler<LLDrawable> |
2309 | { | 2339 | { |
2310 | public: | 2340 | public: |
@@ -2318,16 +2348,19 @@ public: | |||
2318 | if (!mCamera || mCamera->AABBInFrustumNoFarClip(group->mBounds[0], group->mBounds[1])) | 2348 | if (!mCamera || mCamera->AABBInFrustumNoFarClip(group->mBounds[0], group->mBounds[1])) |
2319 | { | 2349 | { |
2320 | node->accept(this); | 2350 | node->accept(this); |
2351 | stop_glerror(); | ||
2321 | 2352 | ||
2322 | for (U32 i = 0; i < node->getChildCount(); i++) | 2353 | for (U32 i = 0; i < node->getChildCount(); i++) |
2323 | { | 2354 | { |
2324 | traverse(node->getChild(i)); | 2355 | traverse(node->getChild(i)); |
2356 | stop_glerror(); | ||
2325 | } | 2357 | } |
2326 | 2358 | ||
2327 | //draw tight fit bounding boxes for spatial group | 2359 | //draw tight fit bounding boxes for spatial group |
2328 | if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE)) | 2360 | if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE)) |
2329 | { | 2361 | { |
2330 | renderOctree(group); | 2362 | renderOctree(group); |
2363 | stop_glerror(); | ||
2331 | } | 2364 | } |
2332 | 2365 | ||
2333 | //render visibility wireframe | 2366 | //render visibility wireframe |
@@ -2339,6 +2372,7 @@ public: | |||
2339 | gGLLastMatrix = NULL; | 2372 | gGLLastMatrix = NULL; |
2340 | glLoadMatrixd(gGLModelView); | 2373 | glLoadMatrixd(gGLModelView); |
2341 | renderVisibility(group, mCamera); | 2374 | renderVisibility(group, mCamera); |
2375 | stop_glerror(); | ||
2342 | gGLLastMatrix = NULL; | 2376 | gGLLastMatrix = NULL; |
2343 | glPopMatrix(); | 2377 | glPopMatrix(); |
2344 | gGL.color4f(1,1,1,1); | 2378 | gGL.color4f(1,1,1,1); |
@@ -2381,6 +2415,11 @@ public: | |||
2381 | { | 2415 | { |
2382 | renderLights(drawable); | 2416 | renderLights(drawable); |
2383 | } | 2417 | } |
2418 | |||
2419 | if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST)) | ||
2420 | { | ||
2421 | renderRaycast(drawable); | ||
2422 | } | ||
2384 | } | 2423 | } |
2385 | 2424 | ||
2386 | for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i) | 2425 | for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i) |
@@ -2411,7 +2450,8 @@ void LLSpatialPartition::renderDebug() | |||
2411 | LLPipeline::RENDER_DEBUG_BBOXES | | 2450 | LLPipeline::RENDER_DEBUG_BBOXES | |
2412 | LLPipeline::RENDER_DEBUG_POINTS | | 2451 | LLPipeline::RENDER_DEBUG_POINTS | |
2413 | LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY | | 2452 | LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY | |
2414 | LLPipeline::RENDER_DEBUG_TEXTURE_ANIM)) | 2453 | LLPipeline::RENDER_DEBUG_TEXTURE_ANIM | |
2454 | LLPipeline::RENDER_DEBUG_RAYCAST)) | ||
2415 | { | 2455 | { |
2416 | return; | 2456 | return; |
2417 | } | 2457 | } |
@@ -2457,17 +2497,37 @@ BOOL LLSpatialPartition::isVisible(const LLVector3& v) | |||
2457 | return TRUE; | 2497 | return TRUE; |
2458 | } | 2498 | } |
2459 | 2499 | ||
2460 | class LLOctreePick : public LLSpatialGroup::OctreeTraveler | 2500 | class LLOctreeIntersect : public LLSpatialGroup::OctreeTraveler |
2461 | { | 2501 | { |
2462 | public: | 2502 | public: |
2463 | LLVector3 mStart; | 2503 | LLVector3 mStart; |
2464 | LLVector3 mEnd; | 2504 | LLVector3 mEnd; |
2465 | LLDrawable* mRet; | 2505 | S32 *mFaceHit; |
2506 | LLVector3 *mIntersection; | ||
2507 | LLVector2 *mTexCoord; | ||
2508 | LLVector3 *mNormal; | ||
2509 | LLVector3 *mBinormal; | ||
2510 | LLDrawable* mHit; | ||
2466 | 2511 | ||
2467 | LLOctreePick(LLVector3 start, LLVector3 end) | 2512 | LLOctreeIntersect(LLVector3 start, LLVector3 end, |
2468 | : mStart(start), mEnd(end) | 2513 | S32* face_hit, LLVector3* intersection, LLVector2* tex_coord, LLVector3* normal, LLVector3* binormal) |
2514 | : mStart(start), | ||
2515 | mEnd(end), | ||
2516 | mFaceHit(face_hit), | ||
2517 | mIntersection(intersection), | ||
2518 | mTexCoord(tex_coord), | ||
2519 | mNormal(normal), | ||
2520 | mBinormal(binormal), | ||
2521 | mHit(NULL) | ||
2469 | { | 2522 | { |
2470 | mRet = NULL; | 2523 | } |
2524 | |||
2525 | virtual void visit(const LLSpatialGroup::OctreeNode* branch) | ||
2526 | { | ||
2527 | for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) | ||
2528 | { | ||
2529 | check(*i); | ||
2530 | } | ||
2471 | } | 2531 | } |
2472 | 2532 | ||
2473 | virtual LLDrawable* check(const LLSpatialGroup::OctreeNode* node) | 2533 | virtual LLDrawable* check(const LLSpatialGroup::OctreeNode* node) |
@@ -2487,41 +2547,73 @@ public: | |||
2487 | size = group->mBounds[1]; | 2547 | size = group->mBounds[1]; |
2488 | center = group->mBounds[0]; | 2548 | center = group->mBounds[0]; |
2489 | 2549 | ||
2490 | if (LLLineSegmentAABB(mStart, mEnd, center, size)) | 2550 | LLVector3 local_start = mStart; |
2551 | LLVector3 local_end = mEnd; | ||
2552 | |||
2553 | if (group->mSpatialPartition->isBridge()) | ||
2554 | { | ||
2555 | LLMatrix4 local_matrix = group->mSpatialPartition->asBridge()->mDrawable->getRenderMatrix(); | ||
2556 | local_matrix.invert(); | ||
2557 | |||
2558 | local_start = mStart * local_matrix; | ||
2559 | local_end = mEnd * local_matrix; | ||
2560 | } | ||
2561 | |||
2562 | if (LLLineSegmentBoxIntersect(local_start, local_end, center, size)) | ||
2491 | { | 2563 | { |
2492 | check(child); | 2564 | check(child); |
2493 | } | 2565 | } |
2494 | } | 2566 | } |
2495 | 2567 | ||
2496 | return mRet; | 2568 | return mHit; |
2497 | } | 2569 | } |
2498 | 2570 | ||
2499 | virtual void visit(const LLSpatialGroup::OctreeNode* branch) | 2571 | virtual bool check(LLDrawable* drawable) |
2500 | { | 2572 | { |
2501 | for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) | 2573 | if (drawable->isSpatialBridge()) |
2502 | { | 2574 | { |
2503 | check(*i); | 2575 | LLSpatialPartition *part = drawable->asPartition(); |
2504 | } | 2576 | |
2577 | check(part->mOctree); | ||
2505 | } | 2578 | } |
2506 | 2579 | ||
2507 | virtual bool check(LLDrawable* drawable) | 2580 | else |
2508 | { | 2581 | { |
2509 | LLViewerObject* vobj = drawable->getVObj(); | 2582 | LLViewerObject* vobj = drawable->getVObj(); |
2510 | if (vobj->lineSegmentIntersect(mStart, mEnd)) | 2583 | |
2584 | if (vobj) | ||
2585 | { | ||
2586 | LLVector3 intersection; | ||
2587 | if (vobj->lineSegmentIntersect(mStart, mEnd, -1, mFaceHit, &intersection, mTexCoord, mNormal, mBinormal)) | ||
2588 | { | ||
2589 | mEnd = intersection; // shorten ray so we only find CLOSER hits | ||
2590 | if (mIntersection) | ||
2511 | { | 2591 | { |
2512 | mRet = vobj->mDrawable; | 2592 | *mIntersection = intersection; |
2593 | } | ||
2594 | |||
2595 | mHit = vobj->mDrawable; | ||
2596 | } | ||
2597 | } | ||
2513 | } | 2598 | } |
2514 | 2599 | ||
2515 | return false; | 2600 | return false; |
2516 | } | 2601 | } |
2517 | }; | 2602 | }; |
2518 | 2603 | ||
2519 | LLDrawable* LLSpatialPartition::pickDrawable(const LLVector3& start, const LLVector3& end, LLVector3& collision) | 2604 | LLDrawable* LLSpatialPartition::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, |
2605 | S32* face_hit, // return the face hit | ||
2606 | LLVector3* intersection, // return the intersection point | ||
2607 | LLVector2* tex_coord, // return the texture coordinates of the intersection point | ||
2608 | LLVector3* normal, // return the surface normal at the intersection point | ||
2609 | LLVector3* bi_normal // return the surface bi-normal at the intersection point | ||
2610 | ) | ||
2611 | |||
2520 | { | 2612 | { |
2521 | LLOctreePick pick(start, end); | 2613 | LLOctreeIntersect intersect(start, end, face_hit, intersection, tex_coord, normal, bi_normal); |
2522 | LLDrawable* ret = pick.check(mOctree); | 2614 | LLDrawable* drawable = intersect.check(mOctree); |
2523 | collision.setVec(pick.mEnd); | 2615 | |
2524 | return ret; | 2616 | return drawable; |
2525 | } | 2617 | } |
2526 | 2618 | ||
2527 | LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset, | 2619 | LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset, |