add osSlerp()

0.9.1.0-post-fixes
UbitUmarov 2019-09-04 23:27:48 +01:00
parent 7771cc00c4
commit 93f13aa00d
5 changed files with 72 additions and 1 deletions

View File

@ -5554,5 +5554,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
DateTime time = TimeZoneInfo.ConvertTime(DateTime.UtcNow, PSTTimeZone);
return time.TimeOfDay.TotalSeconds;
}
public LSL_Rotation osSlerp(LSL_Rotation a, LSL_Rotation b, LSL_Float amount)
{
if(amount < 0)
amount= 0;
else if(amount > 1.0)
amount = 1.0;
a.Normalize();
b.Normalize();
return LSL_Rotation.Slerp(a, b, amount);
}
}
}

View File

@ -36,6 +36,7 @@ using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
@ -554,5 +555,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_String osGetInventoryDesc(LSL_String itemNameOrId);
LSL_Key osGetLastChangedEventKey();
LSL_Float osGetPSTWallclock();
LSL_Rotation osSlerp(LSL_Rotation a, LSL_Rotation b, LSL_Float amount);
}
}

View File

@ -35,7 +35,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public partial class ScriptBaseClass
{
// SCRIPTS CONSTANTS
public static readonly LSLInteger OS_APIVERSION = 7;
public static readonly LSLInteger OS_APIVERSION = 8;
public static readonly LSLInteger TRUE = 1;
public static readonly LSLInteger FALSE = 0;

View File

@ -1407,5 +1407,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_OSSL_Functions.osGetPSTWallclock();
}
public rotation osSlerp(rotation a, rotation b, LSL_Float amount)
{
return m_OSSL_Functions.osSlerp(a, b, amount);
}
}
}

View File

@ -434,6 +434,58 @@ namespace OpenSim.Region.ScriptEngine.Shared
return this;
}
public static Quaternion Slerp(Quaternion q1, Quaternion q2, double amount)
{
double angle = (q1.x * q2.x) + (q1.y * q2.y) + (q1.z * q2.z) + (q1.s * q2.s);
if (angle < 0f)
{
q1.x = -q1.x;
q1.y = -q1.y;
q1.z = -q1.z;
q1.s = -q1.s;
angle *= -1.0;
}
double scale;
double invscale;
if ((angle + 1f) > 0.05f)
{
if ((1f - angle) >= 0.05f)
{
// slerp
double theta = Math.Acos(angle);
double invsintheta = 1.0 / Math.Sin(theta);
scale = Math.Sin(theta * (1.0 - amount)) * invsintheta;
invscale = Math.Sin(theta * amount) * invsintheta;
}
else
{
// lerp
scale = 1.0 - amount;
invscale = amount;
}
}
else
{
q2.x = -q1.y;
q2.y = q1.x;
q2.z = -q1.s;
q2.s = q1.z;
scale = Math.Sin(Math.PI * (0.5 - amount));
invscale = Math.Sin(Math.PI * amount);
}
return new Quaternion(
q1.x * scale + q2.x * invscale,
q1.y * scale + q2.y * invscale,
q1.z * scale + q2.z * invscale,
q1.s * scale + q2.s * invscale
);
}
#endregion
#region Overriders