From c4a9eae961030280473f6df77e59cb53865535b6 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 9 Apr 2012 23:33:42 +0100 Subject: make llGetGeometricCenter() work as in current SL. Now this is not real geom center but a average of positions relative to root prim ignoring prims details, so no need to use physics engine. --- .../Region/Framework/Scenes/SceneObjectGroup.cs | 30 +++++++++++++++++++++- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 29 ++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 107d9b6..3fd1f5e 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -3955,7 +3955,35 @@ namespace OpenSim.Region.Framework.Scenes } } } - + + public Vector3 GetGeometricCenter() + { + // this is not real geometric center but a average of positions relative to root prim acording to + // http://wiki.secondlife.com/wiki/llGetGeometricCenter + // ignoring tortured prims details since sl also seems to ignore + // so no real use in doing it on physics + + Vector3 gc = Vector3.Zero; + + int nparts = m_parts.Count; + if (nparts <= 1) + return gc; + + SceneObjectPart[] parts = m_parts.GetArray(); + nparts = parts.Length; // just in case it changed + if (nparts <= 1) + return gc; + + // average all parts positions + for (int i = 0; i < nparts; i++) + gc += parts[i].GetWorldPosition(); + gc /= nparts; + + // relative to root: + gc -= AbsolutePosition; + return gc; + } + public float GetMass() { float retmass = 0f; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index d419710..511ab19 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2260,18 +2260,29 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 GetGeometricCenter() { - PhysicsActor pa = PhysActor; - - if (pa != null) - { - Vector3 vtmp = pa.CenterOfMass; - return vtmp; - } - else + // this is not real geometric center but a average of positions relative to root prim acording to + // http://wiki.secondlife.com/wiki/llGetGeometricCenter + // ignoring tortured prims details since sl also seems to ignore + // so no real use in doing it on physics + if (ParentGroup.IsDeleted) return new Vector3(0, 0, 0); + + return ParentGroup.GetGeometricCenter(); + + /* + PhysicsActor pa = PhysActor; + + if (pa != null) + { + Vector3 vtmp = pa.CenterOfMass; + return vtmp; + } + else + return new Vector3(0, 0, 0); + */ } - public float GetMass() + public float GetMass() { PhysicsActor pa = PhysActor; -- cgit v1.1