From 95c68a316af53368b6463caa1b7219c9f2ac9b65 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 30 Nov 2007 16:29:23 +0000 Subject: *Refactored the initial raytracer so it doesn't use the Parent reference. *Fixed a 'statement out of order' error in the setting of the permissions that are sent to the client. --- OpenSim/Region/Environment/Scenes/InnerScene.cs | 2 +- .../Region/Environment/Scenes/SceneObjectGroup.cs | 19 +++++--- .../Region/Environment/Scenes/SceneObjectPart.cs | 50 ++++++++++++++-------- 3 files changed, 48 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes') diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 7c13b49..bdcd840 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -300,7 +300,7 @@ namespace OpenSim.Region.Environment.Scenes if (ent is SceneObjectGroup) { SceneObjectGroup reportingG = (SceneObjectGroup)ent; - EntityIntersection result = reportingG.testIntersection(hray); + EntityIntersection result = reportingG.TestIntersection(hray); if (result.HitTF) { if (result.distance < closestDistance) diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 8038a83..24fc484 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -358,17 +358,27 @@ namespace OpenSim.Region.Environment.Scenes } } - public EntityIntersection testIntersection(Ray hRay) + public EntityIntersection TestIntersection(Ray hRay) { + // We got a request from the inner_scene to raytrace along the Ray hRay + // We're going to check all of the prim in this group for intersection with the ray + // If we get a result, we're going to find the closest result to the origin of the ray + // and send back the intersection information back to the innerscene. + EntityIntersection returnresult = new EntityIntersection(); - bool gothit = false; + foreach (SceneObjectPart part in m_parts.Values) { - SceneObjectPart returnThisPart = null; + Vector3 partPosition = new Vector3(part.AbsolutePosition.X,part.AbsolutePosition.Y,part.AbsolutePosition.Z); Quaternion parentrotation = new Quaternion(GroupRotation.W,GroupRotation.X,GroupRotation.Y,GroupRotation.Z); - EntityIntersection inter = part.testIntersection(hRay,parentrotation); + + // Telling the prim to raytrace. + EntityIntersection inter = part.TestIntersection(hRay,parentrotation); + // This may need to be updated to the maximum draw distance possible.. + // We might (and probably will) be checking for prim creation from other sims + // when the camera crosses the border. float idist = 256f; @@ -384,7 +394,6 @@ namespace OpenSim.Region.Environment.Scenes returnresult.obj = part; returnresult.normal = inter.normal; returnresult.distance = inter.distance; - gothit = true; } } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 6770812..99dafac 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -561,10 +561,12 @@ namespace OpenSim.Region.Environment.Scenes serializer.Serialize(xmlWriter, this); } - public EntityIntersection testIntersection(Ray iray, Quaternion parentrot) + public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot) { - //Sphere dummysphere = new Sphere(); + // In this case we're using a sphere with a radius of the largest dimention of the prim + // TODO: Change to take shape into account + EntityIntersection returnresult = new EntityIntersection(); Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z); @@ -582,23 +584,25 @@ namespace OpenSim.Region.Environment.Scenes Vector3 rDirection = iray.Direction; - + // Buidling the first part of the Quadratic equation Vector3 r2ndDirection = rDirection * rDirection; - float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z; + // Buidling the second part of the Quadratic equation Vector3 tmVal2 = rOrigin - vAbsolutePosition; - Vector3 r2Direction = rDirection * 2.0f; Vector3 tmVal3 = r2Direction * tmVal2; float itestPart2 = tmVal3.x + tmVal3.y + tmVal3.z; + // Buidling the third part of the Quadratic equation Vector3 tmVal4 = rOrigin * rOrigin; Vector3 tmVal5 = vAbsolutePosition * vAbsolutePosition; Vector3 tmVal6 = vAbsolutePosition * rOrigin; + + // Set Radius to the largest dimention of the prim float radius = 0f; if (vScale.x > radius) radius = vScale.x; @@ -611,11 +615,11 @@ namespace OpenSim.Region.Environment.Scenes float itestPart3 = tmVal4.x + tmVal4.y + tmVal4.z + tmVal5.x + tmVal5.y + tmVal5.z -(2.0f * (tmVal6.x + tmVal6.y + tmVal6.z + (radius * radius))); - // Yuk Quadradrics + // Yuk Quadradrics.. Solve first float rootsqr = (itestPart2 * itestPart2) - (4.0f * itestPart1 * itestPart3); if (rootsqr < 0.0f) { - + // No intersection return returnresult; } float root = ((-itestPart2) - (float)Math.Sqrt((double)rootsqr)) / (itestPart1 * 2.0f); @@ -628,18 +632,30 @@ namespace OpenSim.Region.Environment.Scenes // is there any intersection? if (root < 0.0f) { - + // nope, no intersection return returnresult; } } + // We got an intersection. putting together an EntityIntersection object with the + // intersection information Vector3 ipoint = new Vector3(iray.Origin.x + (iray.Direction.x * root),iray.Origin.y + (iray.Direction.y * root),iray.Origin.z + (iray.Direction.z * root)); returnresult.HitTF = true; returnresult.ipoint = ipoint; + + // Normal is calculated by the difference and then normalizing the result Vector3 normalpart = ipoint-vAbsolutePosition; returnresult.normal = normalpart.Normalize(); - returnresult.distance = ParentGroup.m_scene.m_innerScene.Vector3Distance(iray.Origin, ipoint); + + // It's funny how the LLVector3 object has a Distance function, but the Axiom.Math object doesnt. + // I can write a function to do it.. but I like the fact that this one is Static. + + LLVector3 distanceConvert1 = new LLVector3(iray.Origin.x,iray.Origin.y,iray.Origin.z); + LLVector3 distanceConvert2 = new LLVector3(ipoint.x, ipoint.y, ipoint.z); + float distance = (float)distanceConvert1.GetDistanceTo(distanceConvert2); + + returnresult.distance = distance; return returnresult; } @@ -1235,15 +1251,15 @@ namespace OpenSim.Region.Environment.Scenes } } // If you can't edit it, send the base permissions minus the flag to edit + + + // We're going to be moving this into ScenePresence and the PermissionsManager itself. if (!ParentGroup.m_scene.PermissionsMngr.BypassPermissions) { if (ParentGroup.m_scene.PermissionsMngr.CanEditObject(remoteClient.AgentId, this.ParentGroup.UUID)) { - //clientFlags = ObjectFlags &= ~(uint)LLObject.ObjectFlags.ObjectModify; - //clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.ObjectMove; - //clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.AllowInventoryDrop; - //clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.ObjectTransfer; - // Send EveryoneMask + // we should be merging the objectflags with the ownermask here. + // TODO: Future refactoring here. clientFlags = ObjectFlags; } @@ -1259,13 +1275,13 @@ namespace OpenSim.Region.Environment.Scenes { clientFlags = clientFlags &= ~(uint) LLObject.ObjectFlags.ObjectMove; } - + clientFlags = EveryoneMask; clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.ObjectModify; clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.AllowInventoryDrop; clientFlags = clientFlags &= ~(uint)LLObject.ObjectFlags.ObjectTransfer; - // TODO, FIXME, ERROR : This whole block amounts to moot because of this. - clientFlags = EveryoneMask; + + } } -- cgit v1.1