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.

avinationmerge
UbitUmarov 2012-04-09 23:33:42 +01:00
parent 39079a62c0
commit c4a9eae961
2 changed files with 49 additions and 10 deletions

View File

@ -3956,6 +3956,34 @@ 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;

View File

@ -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;