diff options
Diffstat (limited to 'linden/indra/newview/llvograss.cpp')
-rw-r--r-- | linden/indra/newview/llvograss.cpp | 155 |
1 files changed, 149 insertions, 6 deletions
diff --git a/linden/indra/newview/llvograss.cpp b/linden/indra/newview/llvograss.cpp index a028a63..4e7816c 100644 --- a/linden/indra/newview/llvograss.cpp +++ b/linden/indra/newview/llvograss.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2001&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2001-2008, Linden Research, Inc. | 7 | * Copyright (c) 2001-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -273,9 +273,9 @@ U32 LLVOGrass::processUpdateMessage(LLMessageSystem *mesgsys, | |||
273 | 273 | ||
274 | updateSpecies(); | 274 | updateSpecies(); |
275 | 275 | ||
276 | if ( (getVelocity().magVecSquared() > 0.f) | 276 | if ( (getVelocity().lengthSquared() > 0.f) |
277 | ||(getAcceleration().magVecSquared() > 0.f) | 277 | ||(getAcceleration().lengthSquared() > 0.f) |
278 | ||(getAngularVelocity().magVecSquared() > 0.f)) | 278 | ||(getAngularVelocity().lengthSquared() > 0.f)) |
279 | { | 279 | { |
280 | llinfos << "ACK! Moving grass!" << llendl; | 280 | llinfos << "ACK! Moving grass!" << llendl; |
281 | setVelocity(LLVector3::zero); | 281 | setVelocity(LLVector3::zero); |
@@ -322,7 +322,7 @@ void LLVOGrass::setPixelAreaAndAngle(LLAgent &agent) | |||
322 | { | 322 | { |
323 | // This should be the camera's center, as soon as we move to all region-local. | 323 | // This should be the camera's center, as soon as we move to all region-local. |
324 | LLVector3 relative_position = getPositionAgent() - agent.getCameraPositionAgent(); | 324 | LLVector3 relative_position = getPositionAgent() - agent.getCameraPositionAgent(); |
325 | F32 range = relative_position.magVec(); | 325 | F32 range = relative_position.length(); |
326 | 326 | ||
327 | F32 max_scale = getMaxScale(); | 327 | F32 max_scale = getMaxScale(); |
328 | 328 | ||
@@ -501,7 +501,7 @@ void LLVOGrass::getGeometry(S32 idx, | |||
501 | 501 | ||
502 | LLVector3 normal1 = (v1-v2) % (v2-v3); | 502 | LLVector3 normal1 = (v1-v2) % (v2-v3); |
503 | normal1.mV[VZ] = 0.75f; | 503 | normal1.mV[VZ] = 0.75f; |
504 | normal1.normVec(); | 504 | normal1.normalize(); |
505 | LLVector3 normal2 = -normal1; | 505 | LLVector3 normal2 = -normal1; |
506 | normal2.mV[VZ] = -normal2.mV[VZ]; | 506 | normal2.mV[VZ] = -normal2.mV[VZ]; |
507 | 507 | ||
@@ -578,3 +578,146 @@ void LLVOGrass::updateDrawable(BOOL force_damped) | |||
578 | } | 578 | } |
579 | clearChanged(SHIFTED); | 579 | clearChanged(SHIFTED); |
580 | } | 580 | } |
581 | |||
582 | // virtual | ||
583 | BOOL LLVOGrass::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, S32 face, BOOL pick_transparent, S32 *face_hitp, | ||
584 | LLVector3* intersection,LLVector2* tex_coord, LLVector3* normal, LLVector3* bi_normal) | ||
585 | |||
586 | { | ||
587 | BOOL ret = FALSE; | ||
588 | if (!mbCanSelect || | ||
589 | mDrawable->isDead() || | ||
590 | !gPipeline.hasRenderType(mDrawable->getRenderType())) | ||
591 | { | ||
592 | return FALSE; | ||
593 | } | ||
594 | |||
595 | LLVector3 dir = end-start; | ||
596 | |||
597 | mPatch = mRegionp->getLand().resolvePatchRegion(getPositionRegion()); | ||
598 | |||
599 | LLVector3 position; | ||
600 | // Create random blades of grass with gaussian distribution | ||
601 | F32 x,y,xf,yf,dzx,dzy; | ||
602 | |||
603 | LLColor4U color(255,255,255,255); | ||
604 | |||
605 | F32 width = sSpeciesTable[mSpecies]->mBladeSizeX; | ||
606 | F32 height = sSpeciesTable[mSpecies]->mBladeSizeY; | ||
607 | |||
608 | LLVector2 tc[4]; | ||
609 | LLVector3 v[4]; | ||
610 | // LLVector3 n[4]; // unused! | ||
611 | |||
612 | F32 closest_t = 1.f; | ||
613 | |||
614 | for (S32 i = 0; i < mNumBlades; i++) | ||
615 | { | ||
616 | x = exp_x[i] * mScale.mV[VX]; | ||
617 | y = exp_y[i] * mScale.mV[VY]; | ||
618 | xf = rot_x[i] * GRASS_BLADE_BASE * width * w_mod[i]; | ||
619 | yf = rot_y[i] * GRASS_BLADE_BASE * width * w_mod[i]; | ||
620 | dzx = dz_x [i]; | ||
621 | dzy = dz_y [i]; | ||
622 | |||
623 | LLVector3 v1,v2,v3; | ||
624 | F32 blade_height= GRASS_BLADE_HEIGHT * height * w_mod[i]; | ||
625 | |||
626 | tc[0] = LLVector2(0, 0); | ||
627 | tc[1] = LLVector2(0, 0.98f); | ||
628 | tc[2] = LLVector2(1, 0); | ||
629 | tc[3] = LLVector2(1, 0.98f); | ||
630 | |||
631 | position.mV[0] = mPosition.mV[VX] + x + xf; | ||
632 | position.mV[1] = mPosition.mV[VY] + y + yf; | ||
633 | position.mV[2] = mRegionp->getLand().resolveHeightRegion(position); | ||
634 | v[0] = v1 = position + mRegionp->getOriginAgent(); | ||
635 | |||
636 | |||
637 | |||
638 | position.mV[0] += dzx; | ||
639 | position.mV[1] += dzy; | ||
640 | position.mV[2] += blade_height; | ||
641 | v[1] = v2 = position + mRegionp->getOriginAgent(); | ||
642 | |||
643 | position.mV[0] = mPosition.mV[VX] + x - xf; | ||
644 | position.mV[1] = mPosition.mV[VY] + y - xf; | ||
645 | position.mV[2] = mRegionp->getLand().resolveHeightRegion(position); | ||
646 | v[2] = v3 = position + mRegionp->getOriginAgent(); | ||
647 | |||
648 | LLVector3 normal1 = (v1-v2) % (v2-v3); | ||
649 | normal1.normalize(); | ||
650 | |||
651 | position.mV[0] += dzx; | ||
652 | position.mV[1] += dzy; | ||
653 | position.mV[2] += blade_height; | ||
654 | v[3] = v1 = position + mRegionp->getOriginAgent(); | ||
655 | |||
656 | |||
657 | F32 a,b,t; | ||
658 | |||
659 | BOOL hit = FALSE; | ||
660 | |||
661 | |||
662 | U32 idx0 = 0,idx1 = 0,idx2 = 0; | ||
663 | |||
664 | if (LLTriangleRayIntersect(v[0], v[1], v[2], start, dir, &a, &b, &t, FALSE)) | ||
665 | { | ||
666 | hit = TRUE; | ||
667 | idx0 = 0; idx1 = 1; idx2 = 2; | ||
668 | } | ||
669 | else if (LLTriangleRayIntersect(v[1], v[3], v[2], start, dir, &a, &b, &t, FALSE)) | ||
670 | { | ||
671 | hit = TRUE; | ||
672 | idx0 = 1; idx1 = 3; idx2 = 2; | ||
673 | } | ||
674 | else if (LLTriangleRayIntersect(v[2], v[1], v[0], start, dir, &a, &b, &t, FALSE)) | ||
675 | { | ||
676 | normal1 = -normal1; | ||
677 | hit = TRUE; | ||
678 | idx0 = 2; idx1 = 1; idx2 = 0; | ||
679 | } | ||
680 | else if (LLTriangleRayIntersect(v[2], v[3], v[1], start, dir, &a, &b, &t, FALSE)) | ||
681 | { | ||
682 | normal1 = -normal1; | ||
683 | hit = TRUE; | ||
684 | idx0 = 2; idx1 = 3; idx2 = 1; | ||
685 | } | ||
686 | |||
687 | if (hit) | ||
688 | { | ||
689 | if (t >= 0.f && | ||
690 | t <= 1.f && | ||
691 | t < closest_t) | ||
692 | { | ||
693 | |||
694 | LLVector2 hit_tc = ((1.f - a - b) * tc[idx0] + | ||
695 | a * tc[idx1] + | ||
696 | b * tc[idx2]); | ||
697 | if (pick_transparent || | ||
698 | getTEImage(0)->getMask(hit_tc)) | ||
699 | { | ||
700 | closest_t = t; | ||
701 | if (intersection != NULL) | ||
702 | { | ||
703 | *intersection = start+dir*closest_t; | ||
704 | } | ||
705 | |||
706 | if (tex_coord != NULL) | ||
707 | { | ||
708 | *tex_coord = hit_tc; | ||
709 | } | ||
710 | |||
711 | if (normal != NULL) | ||
712 | { | ||
713 | *normal = normal1; | ||
714 | } | ||
715 | ret = TRUE; | ||
716 | } | ||
717 | } | ||
718 | } | ||
719 | } | ||
720 | |||
721 | return ret; | ||
722 | } | ||
723 | |||