From c961cfe19e6dfaf26a0117748edbd66fc2d92823 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 3 Jan 2013 21:53:21 +0000 Subject: [PATCH] bug fix, cleanup... --- .../UbitOdePlugin/ODERayCastRequestManager.cs | 6 +-- .../Physics/UbitOdePlugin/ODESitAvatar.cs | 51 +++++++------------ .../Region/Physics/UbitOdePlugin/OdeApi.cs | 15 +++++- 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs index 31757a9bca..6e9281b1be 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs @@ -144,7 +144,7 @@ namespace OpenSim.Region.Physics.OdePlugin qtmp.Y = req.orientation.Y; qtmp.Z = req.orientation.Z; qtmp.W = req.orientation.W; - d.GeomSetOffsetWorldQuaternion(Box, ref qtmp); + d.GeomSetQuaternion(Box, ref qtmp); } else if (req.callbackMethod is ProbeSphereCallback) { @@ -480,12 +480,12 @@ namespace OpenSim.Region.Physics.OdePlugin if (count == 0) return; - +/* uint cat1 = d.GeomGetCategoryBits(g1); uint cat2 = d.GeomGetCategoryBits(g2); uint col1 = d.GeomGetCollideBits(g1); uint col2 = d.GeomGetCollideBits(g2); - +*/ uint ID = 0; PhysicsActor p2 = null; diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs index d6f66819f3..ecc732a129 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODESitAvatar.cs @@ -78,36 +78,20 @@ namespace OpenSim.Region.Physics.OdePlugin IntPtr geom = ((OdePrim)actor).prim_geom; - d.Vector3 dtmp = d.GeomGetPosition(geom); - Vector3 geopos; - geopos.X = dtmp.X; - geopos.Y = dtmp.Y; - geopos.Z = dtmp.Z; + Vector3 geopos = d.GeomGetPositionOMV(geom); + Quaternion geomOri = d.GeomGetQuaternionOMV(geom); + Quaternion geomInvOri = Quaternion.Conjugate(geomOri); - - d.AABB aabb; Quaternion ori = Quaternion.Identity; - d.Quaternion qtmp; - d.GeomCopyQuaternion(geom, out qtmp); - Quaternion geomOri; - geomOri.X = qtmp.X; - geomOri.Y = qtmp.Y; - geomOri.Z = qtmp.Z; - geomOri.W = qtmp.W; - Quaternion geomInvOri; - geomInvOri.X = -qtmp.X; - geomInvOri.Y = -qtmp.Y; - geomInvOri.Z = -qtmp.Z; - geomInvOri.W = qtmp.W; Vector3 rayDir = geopos + offset - avCameraPosition; + float raylen = rayDir.Length(); if (raylen < 0.001f) { PhysicsSitResponse(-1, actor.LocalID, offset, Quaternion.Identity); return; } - float t = 1 / raylen; rayDir.X *= t; rayDir.Y *= t; @@ -119,22 +103,25 @@ namespace OpenSim.Region.Physics.OdePlugin rayResults = m_scene.RaycastActor(actor, avCameraPosition, rayDir, raylen, 1, RaySitFlags); if (rayResults.Count == 0) { +/* if this fundamental ray failed, then just fail so user can try another spot and not be sitted far on a big prim + d.AABB aabb; d.GeomGetAABB(geom, out aabb); offset = new Vector3(avOffset.X, 0, aabb.MaxZ + avOffset.Z - geopos.Z); ori = geomInvOri; offset *= geomInvOri; - PhysicsSitResponse(1, actor.LocalID, offset, ori); +*/ + PhysicsSitResponse(0, actor.LocalID, offset, ori); return; } + int status = 1; offset = rayResults[0].Pos - geopos; d.GeomClassID geoclass = d.GeomGetClass(geom); if (geoclass == d.GeomClassID.SphereClass) { - int status = 1; float r = d.GeomSphereGetRadius(geom); offset.Normalize(); @@ -165,7 +152,7 @@ namespace OpenSim.Region.Physics.OdePlugin { status = 3; avOffset.X = -avOffset.X; - avOffset.Z += 0.4f; + avOffset.Z *= 1.6f; } } @@ -186,6 +173,7 @@ namespace OpenSim.Region.Physics.OdePlugin return; } + float SitNormX = -rayDir.X; float SitNormY = -rayDir.Y; @@ -204,7 +192,6 @@ namespace OpenSim.Region.Physics.OdePlugin { float rayDist = 4.0f; float curEdgeDist = 0.0f; - pivot = geopos + offset; for (int i = 0; i < 6; i++) { @@ -239,11 +226,8 @@ namespace OpenSim.Region.Physics.OdePlugin else { foundEdge = true; - if (curEdgeDist < edgeDist) - { - edgeDist = curEdgeDist; - edgePos = rayResults[0].Pos; - } + edgeDist = curEdgeDist; + edgePos = rayResults[0].Pos; break; } } @@ -267,7 +251,6 @@ namespace OpenSim.Region.Physics.OdePlugin { float rayDist = 1.0f; float curEdgeDist = 0.0f; - pivot = geopos + offset; for (int i = 0; i < 3; i++) { @@ -310,6 +293,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (foundEdge && edgeDist < 0.2f) break; + pivot = geopos + offset; + switch (j) { case 0: @@ -332,7 +317,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (!foundEdge) { avOffset.X = -avOffset.X; - avOffset.Z += 0.4f; + avOffset.Z *= 1.6f; RotAroundZ(SitNormX, SitNormY, ref ori); @@ -349,7 +334,6 @@ namespace OpenSim.Region.Physics.OdePlugin SitNormX = edgeNormalX; SitNormY = edgeNormalY; - offset = edgePos - geopos; if (edgeDirX * SitNormX + edgeDirY * SitNormY < 0) { SitNormX = -SitNormX; @@ -358,7 +342,8 @@ namespace OpenSim.Region.Physics.OdePlugin RotAroundZ(SitNormX, SitNormY, ref ori); - offset += avOffset * ori; + offset = edgePos + avOffset * ori; + offset -= geopos; ori = geomInvOri * ori; offset *= geomInvOri; diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs index 403a4ce85b..10d7d50d95 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs @@ -44,7 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; using System.Runtime.InteropServices; using System.Security; - +using OMV = OpenMetaverse; namespace OdeAPI { //#if dDOUBLE @@ -925,9 +925,20 @@ namespace OdeAPI { unsafe { return *(GeomGetPositionUnsafe(geom)); } } + public static OMV.Vector3 GeomGetPositionOMV(IntPtr geom) + { + Vector3 vtmp = GeomGetPosition(geom); + return new OMV.Vector3(vtmp.X, vtmp.Y, vtmp.Z); + } [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity] - public static extern void GeomCopyQuaternion(IntPtr geom, out Quaternion q); + public static extern void GeomCopyQuaternion(IntPtr geom, out Quaternion q); + public static OMV.Quaternion GeomGetQuaternionOMV(IntPtr geom) + { + Quaternion qtmp; + GeomCopyQuaternion(geom, out qtmp); + return new OMV.Quaternion(qtmp.X, qtmp.Y, qtmp.Z, qtmp.W); + } [DllImport("ode", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dGeomGetQuaternion"), SuppressUnmanagedCodeSecurity] public static extern void GeomCopyQuaternion(IntPtr geom, out dReal X);