From 58daecfccb026be20fb3b124dee2c25d266e13b4 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 24 Sep 2015 06:57:53 +0100 Subject: [PATCH] don't mess ray direction.. --- OpenSim/Region/Framework/Scenes/Scene.cs | 150 ++++++++++++----------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index fced0cc6d1..111b74d9c4 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2305,106 +2305,110 @@ namespace OpenSim.Region.Framework.Scenes Vector3 rayEnd = RayEnd; Vector3 dir = rayEnd - RayStart; - float dist = Vector3.Mag(dir) + 2.0f; - - Vector3 direction = dir * (1 / dist); - - if (SupportsRayCastFiltered()) + float dist = dir.Length(); + if (dist != 0) { - RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull; - rayfilter |= RayFilterFlags.land; - rayfilter |= RayFilterFlags.physical; - rayfilter |= RayFilterFlags.nonphysical; - rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors + Vector3 direction = dir * (1 / dist); - // get some more contacts ??? - int physcount = 4; + dist += 2.0f; - List physresults = - (List)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter); - if (physresults != null && physresults.Count > 0) + if (SupportsRayCastFiltered()) { - if (physresults[0].ConsumerID == 0 || RayTargetID == UUID.Zero) + RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull; + rayfilter |= RayFilterFlags.land; + rayfilter |= RayFilterFlags.physical; + rayfilter |= RayFilterFlags.nonphysical; + rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors + + // get some more contacts ??? + int physcount = 4; + + List physresults = + (List)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter); + if (physresults != null && physresults.Count > 0) { - // found something - pos = physresults[0].Normal * scale ; - pos *= 0.5f; - pos = physresults[0].Pos +pos; - return pos; - } - foreach (ContactResult r in physresults) - { - SceneObjectPart part = GetSceneObjectPart(r.ConsumerID); - if (part == null) - continue; - if (part.UUID == RayTargetID) + if (physresults[0].ConsumerID == 0 || RayTargetID == UUID.Zero) { + // found something pos = physresults[0].Normal * scale; pos *= 0.5f; pos = physresults[0].Pos + pos; return pos; } + foreach (ContactResult r in physresults) + { + SceneObjectPart part = GetSceneObjectPart(r.ConsumerID); + if (part == null) + continue; + if (part.UUID == RayTargetID) + { + pos = physresults[0].Normal * scale; + pos *= 0.5f; + pos = physresults[0].Pos + pos; + return pos; + } + } } + } - } - if (RayTargetID != UUID.Zero) - { - SceneObjectPart target = GetSceneObjectPart(RayTargetID); - - Ray NewRay = new Ray(RayStart, direction); - - if (target != null) + if (RayTargetID != UUID.Zero) { - pos = target.AbsolutePosition; + SceneObjectPart target = GetSceneObjectPart(RayTargetID); - // Ray Trace against target here - EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); + Ray NewRay = new Ray(RayStart, direction); - // Un-comment out the following line to Get Raytrace results printed to the console. - // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); - float ScaleOffset = 0.5f; - - // If we hit something - if (ei.HitTF) + if (target != null) { - Vector3 scaleComponent = ei.AAfaceNormal; - if (scaleComponent.X != 0) ScaleOffset = scale.X; - if (scaleComponent.Y != 0) ScaleOffset = scale.Y; - if (scaleComponent.Z != 0) ScaleOffset = scale.Z; - ScaleOffset = Math.Abs(ScaleOffset); - Vector3 intersectionpoint = ei.ipoint; - Vector3 normal = ei.normal; - // Set the position to the intersection point - Vector3 offset = (normal * (ScaleOffset / 2f)); - pos = (intersectionpoint + offset); + pos = target.AbsolutePosition; - //Seems to make no sense to do this as this call is used for rezzing from inventory as well, and with inventory items their size is not always 0.5f - //And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method - // Un-offset the prim (it gets offset later by the consumer method) - //pos.Z -= 0.25F; + // Ray Trace against target here + EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); - } - } - else - { - // We don't have a target here, so we're going to raytrace all the objects in the scene. - EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(NewRay, true, false); + // Un-comment out the following line to Get Raytrace results printed to the console. + // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); + float ScaleOffset = 0.5f; - // Un-comment the following line to print the raytrace results to the console. - //m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); + // If we hit something + if (ei.HitTF) + { + Vector3 scaleComponent = ei.AAfaceNormal; + if (scaleComponent.X != 0) ScaleOffset = scale.X; + if (scaleComponent.Y != 0) ScaleOffset = scale.Y; + if (scaleComponent.Z != 0) ScaleOffset = scale.Z; + ScaleOffset = Math.Abs(ScaleOffset); + Vector3 intersectionpoint = ei.ipoint; + Vector3 normal = ei.normal; + // Set the position to the intersection point + Vector3 offset = (normal * (ScaleOffset / 2f)); + pos = (intersectionpoint + offset); - if (ei.HitTF) - { - pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); + //Seems to make no sense to do this as this call is used for rezzing from inventory as well, and with inventory items their size is not always 0.5f + //And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method + // Un-offset the prim (it gets offset later by the consumer method) + //pos.Z -= 0.25F; + + } } else { - // fall back to our stupid functionality - pos = RayEnd; + // We don't have a target here, so we're going to raytrace all the objects in the scene. + EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(NewRay, true, false); + + // Un-comment the following line to print the raytrace results to the console. + //m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); + + if (ei.HitTF) + { + pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); + } + else + { + // fall back to our stupid functionality + pos = RayEnd; + } } } } - else { // fall back to our stupid functionality