don't mess ray direction..

avinationmerge
UbitUmarov 2015-09-24 06:57:53 +01:00
parent af34bfddd1
commit 58daecfccb
1 changed files with 77 additions and 73 deletions

View File

@ -2305,106 +2305,110 @@ namespace OpenSim.Region.Framework.Scenes
Vector3 rayEnd = RayEnd; Vector3 rayEnd = RayEnd;
Vector3 dir = rayEnd - RayStart; Vector3 dir = rayEnd - RayStart;
float dist = Vector3.Mag(dir) + 2.0f; float dist = dir.Length();
if (dist != 0)
Vector3 direction = dir * (1 / dist);
if (SupportsRayCastFiltered())
{ {
RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull; Vector3 direction = dir * (1 / dist);
rayfilter |= RayFilterFlags.land;
rayfilter |= RayFilterFlags.physical;
rayfilter |= RayFilterFlags.nonphysical;
rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors
// get some more contacts ??? dist += 2.0f;
int physcount = 4;
List<ContactResult> physresults = if (SupportsRayCastFiltered())
(List<ContactResult>)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter);
if (physresults != null && physresults.Count > 0)
{ {
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<ContactResult> physresults =
(List<ContactResult>)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter);
if (physresults != null && physresults.Count > 0)
{ {
// found something if (physresults[0].ConsumerID == 0 || RayTargetID == UUID.Zero)
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)
{ {
// found something
pos = physresults[0].Normal * scale; pos = physresults[0].Normal * scale;
pos *= 0.5f; pos *= 0.5f;
pos = physresults[0].Pos + pos; pos = physresults[0].Pos + pos;
return 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)
if (RayTargetID != UUID.Zero)
{
SceneObjectPart target = GetSceneObjectPart(RayTargetID);
Ray NewRay = new Ray(RayStart, direction);
if (target != null)
{ {
pos = target.AbsolutePosition; SceneObjectPart target = GetSceneObjectPart(RayTargetID);
// Ray Trace against target here Ray NewRay = new Ray(RayStart, direction);
EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
// Un-comment out the following line to Get Raytrace results printed to the console. if (target != null)
// 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)
{ {
Vector3 scaleComponent = ei.AAfaceNormal; pos = target.AbsolutePosition;
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);
//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 // Ray Trace against target here
//And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter);
// Un-offset the prim (it gets offset later by the consumer method)
//pos.Z -= 0.25F;
} // 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());
else float ScaleOffset = 0.5f;
{
// 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. // If we hit something
//m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); 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) //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
pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); // Un-offset the prim (it gets offset later by the consumer method)
//pos.Z -= 0.25F;
}
} }
else else
{ {
// fall back to our stupid functionality // We don't have a target here, so we're going to raytrace all the objects in the scene.
pos = RayEnd; 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 else
{ {
// fall back to our stupid functionality // fall back to our stupid functionality