From dd745f60c201aee7ff48ba81d567e7b38a8f186c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 28 Apr 2012 21:36:38 +0100 Subject: fix llGetCenterOfMass ( checked with ubitODE only) --- .../Region/Framework/Scenes/SceneObjectGroup.cs | 33 ++++++++++++++++++ OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 40 ++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index ba353c4..b0f2015 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -4041,6 +4041,39 @@ namespace OpenSim.Region.Framework.Scenes return retmass; } + // center of mass of full object + public Vector3 GetCenterOfMass() + { + PhysicsActor pa = RootPart.PhysActor; + + if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null) + { + // physics knows better about center of mass of physical prims + Vector3 tmp = pa.CenterOfMass; + return tmp; + } + + Vector3 Ptot = Vector3.Zero; + float totmass = 0f; + float m; + + SceneObjectPart[] parts = m_parts.GetArray(); + for (int i = 0; i < parts.Length; i++) + { + m = parts[i].GetMass(); + Ptot += parts[i].GetPartCenterOfMass() * m; + totmass += m; + } + + if (totmass == 0) + totmass = 0; + else + totmass = 1 / totmass; + Ptot *= totmass; + + return Ptot; + } + /// /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that /// the physics engine can use it. diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index c9659cb..b198ca7 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1865,7 +1865,7 @@ namespace OpenSim.Region.Framework.Scenes { if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible)) - AddToPhysics(isPhysical, isPhantom, building, true); + AddToPhysics(isPhysical, isPhantom, building, isPhysical); else PhysActor = null; // just to be sure } @@ -2308,7 +2308,7 @@ namespace OpenSim.Region.Framework.Scenes */ } - public float GetMass() + public float GetMass() { PhysicsActor pa = PhysActor; @@ -2318,6 +2318,40 @@ namespace OpenSim.Region.Framework.Scenes return 0; } + public Vector3 GetCenterOfMass() + { + if (ParentGroup.RootPart == this) + { + if (ParentGroup.IsDeleted) + return AbsolutePosition; + return ParentGroup.GetCenterOfMass(); + } + + PhysicsActor pa = PhysActor; + + if (pa != null) + { + Vector3 tmp = pa.CenterOfMass; + return tmp; + } + else + return AbsolutePosition; + } + + public Vector3 GetPartCenterOfMass() + { + PhysicsActor pa = PhysActor; + + if (pa != null) + { + Vector3 tmp = pa.CenterOfMass; + return tmp; + } + else + return AbsolutePosition; + } + + public Vector3 GetForce() { return Force; @@ -4802,7 +4836,7 @@ namespace OpenSim.Region.Framework.Scenes { Velocity = velocity; AngularVelocity = rotationalVelocity; - pa.Velocity = velocity; +// pa.Velocity = velocity; pa.RotationalVelocity = rotationalVelocity; // if not vehicle and root part apply force and torque -- cgit v1.1