add auxiliar functions float osVecMagSquare(a), float osVecDistSquare(vector a), float osAngleBetween(vector a, vector b) and float osRound(ffloat value, integer ndigits)

httptests
UbitUmarov 2018-04-03 23:00:37 +01:00
parent 86d8f2af5b
commit e031d79d48
4 changed files with 60 additions and 0 deletions

View File

@ -4804,5 +4804,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return -1; return -1;
return sog.GetLinkNumber(name); return sog.GetLinkNumber(name);
} }
// rounds to the nearest number with provided number of decimal places
public LSL_Float osRound(LSL_Float value, LSL_Integer ndigits)
{
if(ndigits <= 0)
return Math.Round(value, MidpointRounding.AwayFromZero);
if(ndigits > 15)
ndigits = 15;
return Math.Round(value, ndigits, MidpointRounding.AwayFromZero);
}
public LSL_Float osVecMagSquare(LSL_Vector a)
{
return LSL_Vector.MagSquare(a);
}
public LSL_Float osVecDistSquare(LSL_Vector a, LSL_Vector b)
{
return LSL_Vector.MagSquare(a - b);
}
// returns the angle between 2 vectors -pi to pi
public LSL_Float osAngleBetween(LSL_Vector a, LSL_Vector b)
{
double dot = LSL_Vector.Dot(a,b);
double mcross = LSL_Vector.Mag(LSL_Vector.Cross(a,b));
return Math.Atan2(mcross, dot);
}
} }
} }

View File

@ -506,5 +506,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_Integer osTeleportObject(LSL_Key objectUUID, vector targetPos, rotation targetrotation, LSL_Integer flags); LSL_Integer osTeleportObject(LSL_Key objectUUID, vector targetPos, rotation targetrotation, LSL_Integer flags);
LSL_Integer osGetLinkNumber(LSL_String name); LSL_Integer osGetLinkNumber(LSL_String name);
LSL_Float osRound(LSL_Float value, LSL_Integer digits);
LSL_Float osVecMagSquare(vector a);
LSL_Float osVecDistSquare(vector a, vector b);
LSL_Float osAngleBetween(vector a, vector b);
} }
} }

View File

@ -1195,5 +1195,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{ {
return m_OSSL_Functions.osGetLinkNumber(name); return m_OSSL_Functions.osGetLinkNumber(name);
} }
public LSL_Float osRound(LSL_Float value, LSL_Integer digits)
{
return m_OSSL_Functions.osRound(value, digits);
}
public LSL_Float osVecMagSquare(vector a)
{
return m_OSSL_Functions.osVecMagSquare(a);
}
public LSL_Float osVecDistSquare(vector a, vector b)
{
return m_OSSL_Functions.osVecDistSquare(a, b);
}
public LSL_Float osAngleBetween(vector a, vector b)
{
return m_OSSL_Functions.osAngleBetween(a, b);
}
} }
} }

View File

@ -304,6 +304,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
); );
} }
public static double MagSquare(Vector3 v)
{
return v.x * v.x + v.y * v.y + v.z * v.z;
}
public static double Mag(Vector3 v) public static double Mag(Vector3 v)
{ {
return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);