From f220a2c5eb9bbd15602adb146624b959be3c0314 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 2 Oct 2010 00:19:30 +0200 Subject: Replace CalculateMass with a more accurate version, contributed by Ubit. Thank you. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 453 ++++++++++++++-------------- 1 file changed, 219 insertions(+), 234 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 87cccad..c37c9bd 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -403,300 +403,285 @@ namespace OpenSim.Region.Physics.OdePlugin private float CalculateMass() { - float volume = 0; - - // No material is passed to the physics engines yet.. soo.. - // we're using the m_density constant in the class definition + float volume = _size.X * _size.Y * _size.Z; // default + float tmp; float returnMass = 0; - + float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f; + float hollowVolume = hollowAmount * hollowAmount; + switch (_pbs.ProfileShape) { case ProfileShape.Square: - // Profile Volume + // default box - volume = _size.X*_size.Y*_size.Z; + if (_pbs.PathCurve == (byte)Extrusion.Straight) + { + if (hollowAmount > 0.0) + { + switch (_pbs.HollowShape) + { + case HollowShape.Square: + case HollowShape.Same: + break; - // If the user has 'hollowed out' - // ProfileHollow is one of those 0 to 50000 values :P - // we like percentages better.. so turning into a percentage + case HollowShape.Circle: - if (((float) _pbs.ProfileHollow/50000f) > 0.0) - { - float hollowAmount = (float) _pbs.ProfileHollow/50000f; + hollowVolume *= 0.78539816339f; + break; - // calculate the hollow volume by it's shape compared to the prim shape - float hollowVolume = 0; - switch (_pbs.HollowShape) - { - case HollowShape.Square: - case HollowShape.Same: - // Cube Hollow volume calculation - float hollowsizex = _size.X*hollowAmount; - float hollowsizey = _size.Y*hollowAmount; - float hollowsizez = _size.Z*hollowAmount; - hollowVolume = hollowsizex*hollowsizey*hollowsizez; - break; + case HollowShape.Triangle: - case HollowShape.Circle: - // Hollow shape is a perfect cyllinder in respect to the cube's scale - // Cyllinder hollow volume calculation - float hRadius = _size.X/2; - float hLength = _size.Z; - - // pi * r2 * h - hollowVolume = ((float) (Math.PI*Math.Pow(hRadius, 2)*hLength)*hollowAmount); - break; + hollowVolume *= (0.5f * .5f); + break; - case HollowShape.Triangle: - // Equilateral Triangular Prism volume hollow calculation - // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } + } - float aLength = _size.Y; - // 1/2 abh - hollowVolume = (float) ((0.5*aLength*_size.X*_size.Z)*hollowAmount); - break; + else if (_pbs.PathCurve == (byte)Extrusion.Curve1) + { + //a tube - default: - hollowVolume = 0; - break; + volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX); + tmp= 1.0f -2.0e-2f * (float)(200 - _pbs.PathScaleY); + volume -= volume*tmp*tmp; + + if (hollowAmount > 0.0) + { + hollowVolume *= hollowAmount; + + switch (_pbs.HollowShape) + { + case HollowShape.Square: + case HollowShape.Same: + break; + + case HollowShape.Circle: + hollowVolume *= 0.78539816339f;; + break; + + case HollowShape.Triangle: + hollowVolume *= 0.5f * 0.5f; + break; + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } } - volume = volume - hollowVolume; - } break; + case ProfileShape.Circle: - if (_pbs.PathCurve == (byte)Extrusion.Straight) - { - // Cylinder - float volume1 = (float)(Math.PI * Math.Pow(_size.X/2, 2) * _size.Z); - float volume2 = (float)(Math.PI * Math.Pow(_size.Y/2, 2) * _size.Z); - // Approximating the cylinder's irregularity. - if (volume1 > volume2) - { - volume = (float)volume1 - (volume1 - volume2); - } - else if (volume2 > volume1) - { - volume = (float)volume2 - (volume2 - volume1); - } - else + if (_pbs.PathCurve == (byte)Extrusion.Straight) { - // Regular cylinder - volume = volume1; - } - } - else - { - // We don't know what the shape is yet, so use default - volume = _size.X * _size.Y * _size.Z; - } - // If the user has 'hollowed out' - // ProfileHollow is one of those 0 to 50000 values :P - // we like percentages better.. so turning into a percentage + volume *= 0.78539816339f; // elipse base - if (((float)_pbs.ProfileHollow / 50000f) > 0.0) - { - float hollowAmount = (float)_pbs.ProfileHollow / 50000f; + if (hollowAmount > 0.0) + { + switch (_pbs.HollowShape) + { + case HollowShape.Same: + case HollowShape.Circle: + break; - // calculate the hollow volume by it's shape compared to the prim shape - float hollowVolume = 0; - switch (_pbs.HollowShape) + case HollowShape.Square: + hollowVolume *= 0.5f * 2.5984480504799f; + break; + + case HollowShape.Triangle: + hollowVolume *= .5f * 1.27323954473516f; + break; + + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } + } + + else if (_pbs.PathCurve == (byte)Extrusion.Curve1) { - case HollowShape.Same: - case HollowShape.Circle: - // Hollow shape is a perfect cyllinder in respect to the cube's scale - // Cyllinder hollow volume calculation - float hRadius = _size.X / 2; - float hLength = _size.Z; - - // pi * r2 * h - hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount); - break; + volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX); + tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY); + volume *= (1.0f - tmp * tmp); + + if (hollowAmount > 0.0) + { - case HollowShape.Square: - // Cube Hollow volume calculation - float hollowsizex = _size.X * hollowAmount; - float hollowsizey = _size.Y * hollowAmount; - float hollowsizez = _size.Z * hollowAmount; - hollowVolume = hollowsizex * hollowsizey * hollowsizez; - break; + // calculate the hollow volume by it's shape compared to the prim shape + hollowVolume *= hollowAmount; - case HollowShape.Triangle: - // Equilateral Triangular Prism volume hollow calculation - // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y + switch (_pbs.HollowShape) + { + case HollowShape.Same: + case HollowShape.Circle: + break; - float aLength = _size.Y; - // 1/2 abh - hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); - break; + case HollowShape.Square: + hollowVolume *= 0.5f * 2.5984480504799f; + break; - default: - hollowVolume = 0; - break; + case HollowShape.Triangle: + hollowVolume *= .5f * 1.27323954473516f; + break; + + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } } - volume = volume - hollowVolume; - } break; case ProfileShape.HalfCircle: if (_pbs.PathCurve == (byte)Extrusion.Curve1) { - if (_size.X == _size.Y && _size.Y == _size.Z) - { - // regular sphere - // v = 4/3 * pi * r^3 - float sradius3 = (float)Math.Pow((_size.X / 2), 3); - volume = (float)((4f / 3f) * Math.PI * sradius3); - } - else - { - // we treat this as a box currently - volume = _size.X * _size.Y * _size.Z; - } - } - else - { - // We don't know what the shape is yet, so use default - volume = _size.X * _size.Y * _size.Z; + volume *= 0.52359877559829887307710723054658f; } break; case ProfileShape.EquilateralTriangle: - /* - v = (abs((xB*yA-xA*yB)+(xC*yB-xB*yC)+(xA*yC-xC*yA))/2) * h - // seed mesh - Vertex MM = new Vertex(-0.25f, -0.45f, 0.0f); - Vertex PM = new Vertex(+0.5f, 0f, 0.0f); - Vertex PP = new Vertex(-0.25f, +0.45f, 0.0f); - */ - float xA = -0.25f * _size.X; - float yA = -0.45f * _size.Y; + if (_pbs.PathCurve == (byte)Extrusion.Straight) + { + volume *= 0.32475953f; - float xB = 0.5f * _size.X; - float yB = 0; + if (hollowAmount > 0.0) + { - float xC = -0.25f * _size.X; - float yC = 0.45f * _size.Y; + // calculate the hollow volume by it's shape compared to the prim shape + switch (_pbs.HollowShape) + { + case HollowShape.Same: + case HollowShape.Triangle: + hollowVolume *= .25f; + break; - volume = (float)((Math.Abs((xB * yA - xA * yB) + (xC * yB - xB * yC) + (xA * yC - xC * yA)) / 2) * _size.Z); + case HollowShape.Square: + hollowVolume *= 0.499849f * 3.07920140172638f; + break; - // If the user has 'hollowed out' - // ProfileHollow is one of those 0 to 50000 values :P - // we like percentages better.. so turning into a percentage - float fhollowFactor = ((float)_pbs.ProfileHollow / 1.9f); - if (((float)fhollowFactor / 50000f) > 0.0) - { - float hollowAmount = (float)fhollowFactor / 50000f; + case HollowShape.Circle: + // Hollow shape is a perfect cyllinder in respect to the cube's scale + // Cyllinder hollow volume calculation - // calculate the hollow volume by it's shape compared to the prim shape - float hollowVolume = 0; - switch (_pbs.HollowShape) + hollowVolume *= 0.1963495f * 3.07920140172638f; + break; + + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } + } + else if (_pbs.PathCurve == (byte)Extrusion.Curve1) { - case HollowShape.Same: - case HollowShape.Triangle: - // Equilateral Triangular Prism volume hollow calculation - // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y - - float aLength = _size.Y; - // 1/2 abh - hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); - break; + volume *= 0.32475953f; + volume *= 0.01f * (float)(200 - _pbs.PathScaleX); + tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY); + volume *= (1.0f - tmp * tmp); - case HollowShape.Square: - // Cube Hollow volume calculation - float hollowsizex = _size.X * hollowAmount; - float hollowsizey = _size.Y * hollowAmount; - float hollowsizez = _size.Z * hollowAmount; - hollowVolume = hollowsizex * hollowsizey * hollowsizez; - break; + if (hollowAmount > 0.0) + { - case HollowShape.Circle: - // Hollow shape is a perfect cyllinder in respect to the cube's scale - // Cyllinder hollow volume calculation - float hRadius = _size.X / 2; - float hLength = _size.Z; + hollowVolume *= hollowAmount; - // pi * r2 * h - hollowVolume = ((float)((Math.PI * Math.Pow(hRadius, 2) * hLength)/2) * hollowAmount); - break; + switch (_pbs.HollowShape) + { + case HollowShape.Same: + case HollowShape.Triangle: + hollowVolume *= .25f; + break; - default: - hollowVolume = 0; - break; - } - volume = volume - hollowVolume; - } - break; + case HollowShape.Square: + hollowVolume *= 0.499849f * 3.07920140172638f; + break; - default: - // we don't have all of the volume formulas yet so - // use the common volume formula for all - volume = _size.X*_size.Y*_size.Z; - break; - } + case HollowShape.Circle: - // Calculate Path cut effect on volume - // Not exact, in the triangle hollow example - // They should never be zero or less then zero.. - // we'll ignore it if it's less then zero + hollowVolume *= 0.1963495f * 3.07920140172638f; + break; - // ProfileEnd and ProfileBegin are values - // from 0 to 50000 + default: + hollowVolume = 0; + break; + } + volume *= (1.0f - hollowVolume); + } + } + break; - // Turning them back into percentages so that I can cut that percentage off the volume + default: + break; + } - float PathCutEndAmount = _pbs.ProfileEnd; - float PathCutStartAmount = _pbs.ProfileBegin; - if (((PathCutStartAmount + PathCutEndAmount)/50000f) > 0.0f) - { - float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount)/50000f); - // Check the return amount for sanity - if (pathCutAmount >= 0.99f) - pathCutAmount = 0.99f; - volume = volume - (volume*pathCutAmount); - } - UInt16 taperX = _pbs.PathScaleX; - UInt16 taperY = _pbs.PathScaleY; - float taperFactorX = 0; - float taperFactorY = 0; + float taperX1; + float taperY1; + float taperX; + float taperY; + float pathBegin; + float pathEnd; + float profileBegin; + float profileEnd; - // Mass = density * volume - if (taperX != 100) - { - if (taperX > 100) + if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible) { - taperFactorX = 1.0f - ((float)taperX / 200); - //m_log.Warn("taperTopFactorX: " + extr.taperTopFactorX.ToString()); - } - else - { - taperFactorX = 1.0f - ((100 - (float)taperX) / 100); - //m_log.Warn("taperBotFactorX: " + extr.taperBotFactorX.ToString()); - } - volume = (float)volume * ((taperFactorX / 3f) + 0.001f); - } + taperX1 = _pbs.PathScaleX * 0.01f; + if (taperX1 > 1.0f) + taperX1 = 2.0f - taperX1; + taperX = 1.0f - taperX1; - if (taperY != 100) - { - if (taperY > 100) - { - taperFactorY = 1.0f - ((float)taperY / 200); - //m_log.Warn("taperTopFactorY: " + extr.taperTopFactorY.ToString()); + taperY1 = _pbs.PathScaleY * 0.01f; + if (taperY1 > 1.0f) + taperY1 = 2.0f - taperY1; + taperY = 1.0f - taperY1; } - else + else { - taperFactorY = 1.0f - ((100 - (float)taperY) / 100); - //m_log.Warn("taperBotFactorY: " + extr.taperBotFactorY.ToString()); + taperX = _pbs.PathTaperX * 0.01f; + if (taperX < 0.0f) + taperX = -taperX; + taperX1 = 1.0f - taperX; + + taperY = _pbs.PathTaperY * 0.01f; + if (taperY < 0.0f) + taperY = -taperY; + taperY1 = 1.0f - taperY; + } - volume = (float)volume * ((taperFactorY / 3f) + 0.001f); - } - returnMass = m_density*volume; - if (returnMass <= 0) returnMass = 0.0001f;//ckrinke: Mass must be greater then zero. + + + volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY); + + pathBegin = (float)_pbs.PathBegin * 2.0e-5f; + pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f; + volume *= (pathEnd - pathBegin); + +// this is crude aproximation + profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f; + profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f; + volume *= (profileEnd - profileBegin); + + returnMass = m_density * volume; + + if (returnMass <= 0) + returnMass = 0.0001f;//ckrinke: Mass must be greater then zero. +// else if (returnMass > _parent_scene.maximumMassObject) +// returnMass = _parent_scene.maximumMassObject; + -- cgit v1.1 From b01020b84a1ec6aea29732fd2d930522d1348213 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 2 Oct 2010 18:45:48 +0100 Subject: Revert "Forward-port 0.6 fix" This reverts commit 90b51dc7d67507e27c4baa529e979de19dce8de1. --- .../CoreModules/World/Objects/BuySell/BuySellModule.cs | 14 +------------- OpenSim/Region/Framework/Interfaces/IBuySellModule.cs | 4 ++-- .../OptionalModules/World/MoneyModule/SampleMoneyModule.cs | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs index a674d60..c8fb9da 100644 --- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs @@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell part.GetProperties(client); } - public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice) + public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType) { SceneObjectPart part = m_scene.GetSceneObjectPart(localID); @@ -114,18 +114,6 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell if (part.ParentGroup == null) return false; - if (part.ObjectSaleType != saleType) - { - m_dialogModule.SendAlertToUser(remoteClient, "This item is not available for the type of sale specified"); - return false; - } - - if (part.SalePrice != salePrice) - { - m_dialogModule.SendAlertToUser(remoteClient, "This item is not available for the price specified"); - return false; - } - SceneObjectGroup group = part.ParentGroup; switch (saleType) diff --git a/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs b/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs index d1ce4c0..0132bae 100644 --- a/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs @@ -42,6 +42,6 @@ namespace OpenSim.Region.Framework.Interfaces /// /// True on a successful purchase, false on failure /// - bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice); + bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs index d364df6..cc51c3b 100644 --- a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs +++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs @@ -814,7 +814,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule IBuySellModule module = s.RequestModuleInterface(); if (module != null) - module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice); + module.BuyObject(remoteClient, categoryID, localID, saleType); } } @@ -825,4 +825,4 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule Gift = 2, Purchase = 3 } -} +} \ No newline at end of file -- cgit v1.1 From 87c63868840705e479c9c11123e27ce191c38619 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 2 Oct 2010 18:47:26 +0100 Subject: Reapplying the parts of the prior revert that were not derived from the original patch --- OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs | 2 +- OpenSim/Region/Framework/Interfaces/IBuySellModule.cs | 4 ++-- OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs index c8fb9da..c06ccb2 100644 --- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs @@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell part.GetProperties(client); } - public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType) + public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice) { SceneObjectPart part = m_scene.GetSceneObjectPart(localID); diff --git a/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs b/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs index 0132bae..d1ce4c0 100644 --- a/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IBuySellModule.cs @@ -42,6 +42,6 @@ namespace OpenSim.Region.Framework.Interfaces /// /// True on a successful purchase, false on failure /// - bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType); + bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice); } -} \ No newline at end of file +} diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs index cc51c3b..d364df6 100644 --- a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs +++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs @@ -814,7 +814,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule IBuySellModule module = s.RequestModuleInterface(); if (module != null) - module.BuyObject(remoteClient, categoryID, localID, saleType); + module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice); } } @@ -825,4 +825,4 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule Gift = 2, Purchase = 3 } -} \ No newline at end of file +} -- cgit v1.1