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

This commit is contained in:
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 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);
}
}
}