diff options
author | UbitUmarov | 2018-04-03 23:00:37 +0100 |
---|---|---|
committer | UbitUmarov | 2018-04-03 23:00:37 +0100 |
commit | e031d79d48cb4cb42ccb160d2894d078f835eb10 (patch) | |
tree | cecf42bc736df641d480edfc1fe6de760b918cff /OpenSim/Region/ScriptEngine | |
parent | try fix git (diff) | |
download | opensim-SC-e031d79d48cb4cb42ccb160d2894d078f835eb10.zip opensim-SC-e031d79d48cb4cb42ccb160d2894d078f835eb10.tar.gz opensim-SC-e031d79d48cb4cb42ccb160d2894d078f835eb10.tar.bz2 opensim-SC-e031d79d48cb4cb42ccb160d2894d078f835eb10.tar.xz |
add auxiliar functions float osVecMagSquare(a), float osVecDistSquare(vector a), float osAngleBetween(vector a, vector b) and float osRound(ffloat value, integer ndigits)
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
4 files changed, 60 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index e156582..51b289b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -4804,5 +4804,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4804 | return -1; | 4804 | return -1; |
4805 | return sog.GetLinkNumber(name); | 4805 | return sog.GetLinkNumber(name); |
4806 | } | 4806 | } |
4807 | |||
4808 | // rounds to the nearest number with provided number of decimal places | ||
4809 | public LSL_Float osRound(LSL_Float value, LSL_Integer ndigits) | ||
4810 | { | ||
4811 | if(ndigits <= 0) | ||
4812 | return Math.Round(value, MidpointRounding.AwayFromZero); | ||
4813 | if(ndigits > 15) | ||
4814 | ndigits = 15; | ||
4815 | return Math.Round(value, ndigits, MidpointRounding.AwayFromZero); | ||
4816 | } | ||
4817 | |||
4818 | public LSL_Float osVecMagSquare(LSL_Vector a) | ||
4819 | { | ||
4820 | return LSL_Vector.MagSquare(a); | ||
4821 | } | ||
4822 | |||
4823 | public LSL_Float osVecDistSquare(LSL_Vector a, LSL_Vector b) | ||
4824 | { | ||
4825 | return LSL_Vector.MagSquare(a - b); | ||
4826 | } | ||
4827 | |||
4828 | // returns the angle between 2 vectors -pi to pi | ||
4829 | public LSL_Float osAngleBetween(LSL_Vector a, LSL_Vector b) | ||
4830 | { | ||
4831 | double dot = LSL_Vector.Dot(a,b); | ||
4832 | double mcross = LSL_Vector.Mag(LSL_Vector.Cross(a,b)); | ||
4833 | return Math.Atan2(mcross, dot); | ||
4834 | } | ||
4807 | } | 4835 | } |
4808 | } | 4836 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index ffb7ded..5cabf30 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -506,5 +506,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
506 | 506 | ||
507 | LSL_Integer osTeleportObject(LSL_Key objectUUID, vector targetPos, rotation targetrotation, LSL_Integer flags); | 507 | LSL_Integer osTeleportObject(LSL_Key objectUUID, vector targetPos, rotation targetrotation, LSL_Integer flags); |
508 | LSL_Integer osGetLinkNumber(LSL_String name); | 508 | LSL_Integer osGetLinkNumber(LSL_String name); |
509 | |||
510 | LSL_Float osRound(LSL_Float value, LSL_Integer digits); | ||
511 | |||
512 | LSL_Float osVecMagSquare(vector a); | ||
513 | LSL_Float osVecDistSquare(vector a, vector b); | ||
514 | LSL_Float osAngleBetween(vector a, vector b); | ||
509 | } | 515 | } |
510 | } | 516 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 30ff764..16b368c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -1195,5 +1195,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1195 | { | 1195 | { |
1196 | return m_OSSL_Functions.osGetLinkNumber(name); | 1196 | return m_OSSL_Functions.osGetLinkNumber(name); |
1197 | } | 1197 | } |
1198 | |||
1199 | public LSL_Float osRound(LSL_Float value, LSL_Integer digits) | ||
1200 | { | ||
1201 | return m_OSSL_Functions.osRound(value, digits); | ||
1202 | } | ||
1203 | |||
1204 | public LSL_Float osVecMagSquare(vector a) | ||
1205 | { | ||
1206 | return m_OSSL_Functions.osVecMagSquare(a); | ||
1207 | } | ||
1208 | |||
1209 | public LSL_Float osVecDistSquare(vector a, vector b) | ||
1210 | { | ||
1211 | return m_OSSL_Functions.osVecDistSquare(a, b); | ||
1212 | } | ||
1213 | |||
1214 | public LSL_Float osAngleBetween(vector a, vector b) | ||
1215 | { | ||
1216 | return m_OSSL_Functions.osAngleBetween(a, b); | ||
1217 | } | ||
1218 | |||
1198 | } | 1219 | } |
1199 | } | 1220 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index a65f71f..1c152be 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -304,6 +304,11 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
304 | ); | 304 | ); |
305 | } | 305 | } |
306 | 306 | ||
307 | public static double MagSquare(Vector3 v) | ||
308 | { | ||
309 | return v.x * v.x + v.y * v.y + v.z * v.z; | ||
310 | } | ||
311 | |||
307 | public static double Mag(Vector3 v) | 312 | public static double Mag(Vector3 v) |
308 | { | 313 | { |
309 | return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); | 314 | return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); |