From 67bbed820290b0307f09f29343e5fc96bdfc669a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 28 Dec 2007 05:25:21 +0000 Subject: [PATCH] * Added ability to create new prim on existing prim (rezzing prim from inventory on other prim coming soon). No more new prim buried in the ground by accident. * The prim are at the absolute position of the prim you rezzed it on top of + (0,0,0.5) for now. --- OpenSim/Framework/IClientAPI.cs | 2 +- OpenSim/Framework/Util.cs | 12 ++ OpenSim/Region/ClientStack/ClientView.cs | 17 ++- OpenSim/Region/Environment/Scenes/Scene.cs | 134 ++++++++++++------ .../Environment/Scenes/SceneObjectPart.cs | 7 +- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 17 +-- 6 files changed, 128 insertions(+), 61 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 8ef5576831..9072035f91 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -332,7 +332,7 @@ namespace OpenSim.Framework public delegate void UUIDNameRequest(LLUUID id, IClientAPI remote_client); - public delegate void AddNewPrim(LLUUID ownerID, LLVector3 pos, LLQuaternion rot, PrimitiveBaseShape shape); + public delegate void AddNewPrim(LLUUID ownerID, LLVector3 RayEnd, LLQuaternion rot, PrimitiveBaseShape shape, byte bypassRaycast, LLVector3 RayStart, LLUUID RayTargetID, byte RayEndIsIntersection); public delegate void RequestGodlikePowers(LLUUID AgentID, LLUUID SessionID, LLUUID token, IClientAPI remote_client); diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 3654a7dca5..e6512c277c 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -46,6 +46,8 @@ namespace OpenSim.Framework private static object XferLock = new object(); private static Dictionary capsURLS = new Dictionary(); + #region Vector Equasions + public static double GetDistanceTo(LLVector3 a, LLVector3 b) { float dx = a.X - b.X; @@ -53,6 +55,16 @@ namespace OpenSim.Framework float dz = a.Z - b.Z; return Math.Sqrt(dx*dx + dy*dy + dz*dz); } + public static double GetMagnitude(LLVector3 a) { + return Math.Sqrt((a.X * a.X) + (a.Y * a.Y) + (a.Z * a.Z)); + } + public static LLVector3 GetNormal(LLVector3 a) + { + float Mag = (float)GetMagnitude(a); + return new LLVector3(a.X / Mag, a.Y / Mag, a.Z / Mag); + + } + # endregion public static ulong UIntsToLong(uint X, uint Y) { diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index b232ed6c0b..e8ae2a7f29 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -2534,6 +2534,15 @@ namespace OpenSim.Region.ClientStack RezObjectPacket rezPacket = (RezObjectPacket) Pack; if (OnRezObject != null) { + //rezPacket.RezData.BypassRaycast; + //rezPacket.RezData.RayEnd; + //rezPacket.RezData.RayEndIsIntersection; + //rezPacket.RezData.RayStart; + //rezPacket.RezData.RayTargetID; + //rezPacket.RezData.RemoveItem; + //rezPacket.RezData.RezSelected; + //rezPacket.RezData.FromTaskID; + //MainLog.Instance.Verbose("REZData", rezPacket.ToString()); OnRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd); } break; @@ -2713,7 +2722,13 @@ namespace OpenSim.Region.ClientStack { ObjectAddPacket addPacket = (ObjectAddPacket) Pack; PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket); - OnAddPrim(AgentId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape); + MainLog.Instance.Verbose("REZData", addPacket.ToString()); + //BypassRaycast: 1 + //RayStart: <69.79469, 158.2652, 98.40343> + //RayEnd: <61.97724, 141.995, 92.58341> + //RayTargetID: 00000000-0000-0000-0000-000000000000 + + OnAddPrim(AgentId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape,addPacket.ObjectData.BypassRaycast,addPacket.ObjectData.RayStart,addPacket.ObjectData.RayTargetID,addPacket.ObjectData.RayEndIsIntersection); } break; case PacketType.ObjectShape: diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index afceaab3ad..077157f76c 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -925,7 +925,89 @@ namespace OpenSim.Region.Environment.Scenes return myID; } - public virtual void AddNewPrim(LLUUID ownerID, LLVector3 pos, LLQuaternion rot, PrimitiveBaseShape shape) + public LLVector3 GetNewRezLocation(LLVector3 RayStart, LLVector3 RayEnd, LLUUID RayTargetID, LLQuaternion rot, byte bypassRayCast, byte RayEndIsIntersection) + { + LLVector3 pos = LLVector3.Zero; + if (RayEndIsIntersection == (byte)1) + { + pos = RayEnd; + return pos; + } + if (RayTargetID != LLUUID.Zero) + { + SceneObjectPart target = GetSceneObjectPart(RayTargetID); + if (target != null) + { + pos = target.AbsolutePosition; + + //MainLog.Instance.Verbose("RAYTRACE", pos.ToString()); + //EntityIntersection rayTracing = null; + //ScenePresence presence = ((ScenePresence)GetScenePresence(ownerID)); + //if (presence != null) + //{ + //Vector3 CameraPosition = presence.CameraPosition; + //Vector3 rayEnd = new Vector3(pos.X, pos.Y, pos.Z); + + //float rayMag = m_innerScene.Vector3Distance(CameraPosition, rayEnd); + //LLVector3 rayDirectionLL = Util.GetNormal(pos); + + //Vector3 rayDirection = new Vector3(rayDirectionLL.X, rayDirectionLL.Y, rayDirectionLL.Z); + + //Ray rezRay = new Ray(CameraPosition, rayDirection); + + //Vector3 RezDirectionFromCamera = rezRay.Direction; + + //rayTracing = m_innerScene.GetClosestIntersectingPrim(rezRay); + //} + + //if ((rayTracing != null) && (rayTracing.HitTF)) + //{ + // We raytraced and found a prim in the way of the ground.. so + // We will rez the object somewhere close to the prim. Better math needed. This is a Stub + //Vector3 Newpos = new Vector3(rayTracing.obj.AbsolutePosition.X,rayTracing.obj.AbsolutePosition.Y,rayTracing.obj.AbsolutePosition.Z); + //Vector3 Newpos = rayTracing.ipoint; + //Vector3 NewScale = + //new Vector3(rayTracing.obj.Scale.X, rayTracing.obj.Scale.Y, rayTracing.obj.Scale.Z); + + //Quaternion ParentRot = rayTracing.obj.ParentGroup.Rotation; + //Quaternion ParentRot = new Quaternion(primParentRot.W,primParentRot.X,primParentRot.Y,primParentRot.Z); + + //LLQuaternion primLocalRot = rayTracing.obj.RotationOffset; + //Quaternion LocalRot = new Quaternion(primLocalRot.W, primLocalRot.X, primLocalRot.Y, primLocalRot.Z); + + //Quaternion NewRot = LocalRot * ParentRot; + + //Vector3 RezPoint = Newpos; + + //MainLog.Instance.Verbose("REZINFO", "Possible Rez Point:" + RezPoint.ToString()); + //pos = new LLVector3(RezPoint.x, RezPoint.y, RezPoint.z); + //} + + + + + + return pos; + } + else + { + // fall back to our stupid functionality + pos = RayEnd; + return pos; + } + } + else + { + // fall back to our stupid functionality + pos = RayEnd; + return pos; + } + + } + + public virtual void AddNewPrim(LLUUID ownerID, LLVector3 RayEnd, LLQuaternion rot, PrimitiveBaseShape shape, + byte bypassRaycast, LLVector3 RayStart, LLUUID RayTargetID, + byte RayEndIsIntersection) { // What we're *supposed* to do is raytrace from the camera position given by the client to the nearest collision // in the direction the client supplies (the ground level that we clicked) @@ -933,53 +1015,17 @@ namespace OpenSim.Region.Environment.Scenes // Test it if you like. The console will write where it guesses a collision took place. if it thinks one did. // It's wrong many times though. + LLVector3 pos = GetNewRezLocation(RayStart, RayEnd, RayTargetID, rot, bypassRaycast, RayEndIsIntersection); + + + + if (PermissionsMngr.CanRezObject(ownerID, pos)) { - EntityIntersection rayTracing = null; - ScenePresence presence = ((ScenePresence) GetScenePresence(ownerID)); - if (presence != null) - { - Vector3 CameraPosition = presence.CameraPosition; - Vector3 rayEnd = new Vector3(pos.X, pos.Y, pos.Z); - float raydistance = m_innerScene.Vector3Distance(CameraPosition, rayEnd); - - Vector3 rayDirection = new Vector3(rayEnd.x/raydistance, rayEnd.y/raydistance, rayEnd.z/raydistance); - - Ray rezRay = new Ray(CameraPosition, rayDirection); - - Vector3 RezDirectionFromCamera = rezRay.Direction; - - rayTracing = m_innerScene.GetClosestIntersectingPrim(rezRay); - } - - if ((rayTracing != null) && (rayTracing.HitTF)) - { - // We raytraced and found a prim in the way of the ground.. so - // We will rez the object somewhere close to the prim. Better math needed. This is a Stub - //Vector3 Newpos = new Vector3(rayTracing.obj.AbsolutePosition.X,rayTracing.obj.AbsolutePosition.Y,rayTracing.obj.AbsolutePosition.Z); - Vector3 Newpos = rayTracing.ipoint; - Vector3 NewScale = - new Vector3(rayTracing.obj.Scale.X, rayTracing.obj.Scale.Y, rayTracing.obj.Scale.Z); - - Quaternion ParentRot = rayTracing.obj.ParentGroup.Rotation; - //Quaternion ParentRot = new Quaternion(primParentRot.W,primParentRot.X,primParentRot.Y,primParentRot.Z); - - LLQuaternion primLocalRot = rayTracing.obj.RotationOffset; - Quaternion LocalRot = new Quaternion(primLocalRot.W, primLocalRot.X, primLocalRot.Y, primLocalRot.Z); - - Quaternion NewRot = LocalRot*ParentRot; - - Vector3 RezPoint = Newpos; - - MainLog.Instance.Verbose("REZINFO", "Possible Rez Point:" + RezPoint.ToString()); - //pos = new LLVector3(RezPoint.x, RezPoint.y, RezPoint.z); - } - else - { // rez ON the ground, not IN the ground pos.Z += 0.25F; - } + SceneObjectGroup sceneOb = new SceneObjectGroup(this, m_regionHandle, ownerID, PrimIDAllocate(), pos, rot, shape); @@ -1018,7 +1064,7 @@ namespace OpenSim.Region.Environment.Scenes treeShape.PCode = newTree ? (byte) PCode.NewTree : (byte) PCode.Tree; treeShape.Scale = scale; treeShape.State = (byte) treeType; - AddNewPrim(LLUUID.Random(), position, rotation, treeShape); + AddNewPrim(LLUUID.Random(), position, rotation, treeShape,(byte)1,LLVector3.Zero,LLUUID.Zero,(byte)1); } public void RemovePrim(uint localID, LLUUID avatar_deleter) diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 90a975c606..dad881219d 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -694,19 +694,22 @@ namespace OpenSim.Region.Environment.Scenes EntityIntersection returnresult = new EntityIntersection(); Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z); + Vector3 vScale = new Vector3(Scale.X, Scale.Y, Scale.Z); Quaternion qRotation = new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z); - Quaternion worldRotation = (qRotation*parentrot); - Matrix3 worldRotM = worldRotation.ToRotationMatrix(); + //Quaternion worldRotation = (qRotation*parentrot); + //Matrix3 worldRotM = worldRotation.ToRotationMatrix(); Vector3 rOrigin = iray.Origin; Vector3 rDirection = iray.Direction; + + //rDirection = rDirection.Normalize(); // Buidling the first part of the Quadratic equation Vector3 r2ndDirection = rDirection*rDirection; float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z; diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 2193d07297..006d82938e 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -299,10 +299,7 @@ namespace OpenSim.Region.Physics.OdePlugin p2.PhysicsActorType == (int) ActorTypes.Prim)) { if (p2.PhysicsActorType == (int) ActorTypes.Agent) - { if (p1.IsPhysical) - { - int q = 1; - } + { p2.CollidingObj = true; //contacts[i].depth = 0.003f; p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); @@ -313,18 +310,12 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - if (p1.IsPhysical) - { - int q = 1; - } - contacts[i].depth = 0.0000000f; + + //contacts[i].depth = 0.0000000f; } if (p1.PhysicsActorType == (int) ActorTypes.Agent) { - if (p2.IsPhysical) - { - int q = 1; - } + p1.CollidingObj = true; //contacts[i].depth = 0.003f; p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f);