aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvosurfacepatch.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-12-01 17:39:58 -0600
committerJacek Antonelli2008-12-01 17:40:06 -0600
commit7abecb48babe6a6f09bf6692ba55076546cfced9 (patch)
tree8d18a88513fb97adf32c10aae78f4be1984942db /linden/indra/newview/llvosurfacepatch.cpp
parentSecond Life viewer sources 1.21.6 (diff)
downloadmeta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.zip
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.gz
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.bz2
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.xz
Second Life viewer sources 1.22.0-RC
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llvosurfacepatch.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/linden/indra/newview/llvosurfacepatch.cpp b/linden/indra/newview/llvosurfacepatch.cpp
index 310a745..7055b30 100644
--- a/linden/indra/newview/llvosurfacepatch.cpp
+++ b/linden/indra/newview/llvosurfacepatch.cpp
@@ -916,6 +916,87 @@ void LLVOSurfacePatch::getGeomSizesEast(const S32 stride, const S32 east_stride,
916 } 916 }
917} 917}
918 918
919BOOL LLVOSurfacePatch::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, S32 face, BOOL pick_transparent, S32 *face_hitp,
920 LLVector3* intersection,LLVector2* tex_coord, LLVector3* normal, LLVector3* bi_normal)
921
922{
923
924 if (!lineSegmentBoundingBox(start, end))
925 {
926 return FALSE;
927 }
928
929 LLVector3 delta = end-start;
930
931 LLVector3 pdelta = delta;
932 pdelta.mV[2] = 0;
933
934 F32 plength = pdelta.length();
935
936 F32 tdelta = 1.f/plength;
937
938 LLVector3 origin = start - mRegionp->getOriginAgent();
939
940 if (mRegionp->getLandHeightRegion(origin) > origin.mV[2])
941 {
942 //origin is under ground, treat as no intersection
943 return FALSE;
944 }
945
946 //step one meter at a time until intersection point found
947
948 F32 t = 0.f;
949 while ( t <= 1.f)
950 {
951 LLVector3 sample = origin + delta*t;
952
953 F32 height = mRegionp->getLandHeightRegion(sample);
954 if (height > sample.mV[2])
955 { //ray went below ground, positive intersection
956 //quick and dirty binary search to get impact point
957 tdelta = -tdelta*0.5f;
958 F32 err_dist = 0.001f;
959 F32 dist = fabsf(sample.mV[2] - height);
960
961 while (dist > err_dist && tdelta*tdelta > 0.0f)
962 {
963 t += tdelta;
964 sample = origin+delta*t;
965 height = mRegionp->getLandHeightRegion(sample);
966 if ((tdelta < 0 && height < sample.mV[2]) ||
967 (height > sample.mV[2] && tdelta > 0))
968 { //jumped over intersection point, go back
969 tdelta = -tdelta;
970 }
971 tdelta *= 0.5f;
972 dist = fabsf(sample.mV[2] - height);
973 }
974
975 if (intersection)
976 {
977 sample.mV[2] = mRegionp->getLandHeightRegion(sample);
978 *intersection = sample + mRegionp->getOriginAgent();
979 }
980
981 if (normal)
982 {
983 *normal = mRegionp->getLand().resolveNormalGlobal(mRegionp->getPosGlobalFromRegion(sample));
984 }
985
986 return TRUE;
987 }
988
989 t += tdelta;
990 if (t > 1 && t < 1.f+tdelta*0.99f)
991 { //make sure end point is checked (saves vertical lines coming up negative)
992 t = 1.f;
993 }
994 }
995
996
997 return FALSE;
998}
999
919void LLVOSurfacePatch::updateSpatialExtents(LLVector3& newMin, LLVector3 &newMax) 1000void LLVOSurfacePatch::updateSpatialExtents(LLVector3& newMin, LLVector3 &newMax)
920{ 1001{
921 LLVector3 posAgent = getPositionAgent(); 1002 LLVector3 posAgent = getPositionAgent();