mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
add vector variant of osSlerp; update script syntax
This commit is contained in:
@@ -5647,6 +5647,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
return LSL_Rotation.Slerp(a, b, amount);
|
||||
}
|
||||
|
||||
public LSL_Vector osSlerp(LSL_Vector a, LSL_Vector b, LSL_Float amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
amount = 0;
|
||||
else if (amount > 1.0)
|
||||
amount = 1.0;
|
||||
|
||||
return LSL_Vector.Slerp(a, b, amount);
|
||||
}
|
||||
|
||||
public void osResetAllScripts(LSL_Integer linkset)
|
||||
{
|
||||
UUID me = m_item.ItemID;
|
||||
|
||||
@@ -561,6 +561,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_Key osGetLastChangedEventKey();
|
||||
LSL_Float osGetPSTWallclock();
|
||||
LSL_Rotation osSlerp(LSL_Rotation a, LSL_Rotation b, LSL_Float amount);
|
||||
vector osSlerp(vector a, vector b, LSL_Float amount);
|
||||
|
||||
void osResetAllScripts(LSL_Integer AllLinkset);
|
||||
LSL_Integer osIsNotValidNumber(LSL_Float v);
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
public partial class ScriptBaseClass
|
||||
{
|
||||
// SCRIPTS CONSTANTS
|
||||
public static readonly LSLInteger OS_APIVERSION = 15;
|
||||
public static readonly LSLInteger OS_APIVERSION = 16;
|
||||
|
||||
public static readonly LSLInteger TRUE = 1;
|
||||
public static readonly LSLInteger FALSE = 0;
|
||||
|
||||
@@ -1432,6 +1432,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
return m_OSSL_Functions.osSlerp(a, b, amount);
|
||||
}
|
||||
|
||||
public vector osSlerp(vector a, vector b, LSL_Float amount)
|
||||
{
|
||||
return m_OSSL_Functions.osSlerp(a, b, amount);
|
||||
}
|
||||
|
||||
public void osResetAllScripts(LSL_Integer allLinkSet)
|
||||
{
|
||||
m_OSSL_Functions.osResetAllScripts(allLinkSet);
|
||||
|
||||
@@ -366,6 +366,30 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||
return new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
public static Vector3 Slerp(Vector3 v1, Vector3 v2, double amount)
|
||||
{
|
||||
double angle = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
|
||||
double scale;
|
||||
double invscale;
|
||||
|
||||
if (angle < 0.999f)
|
||||
{
|
||||
angle = Math.Acos(angle);
|
||||
invscale = 1.0f / Math.Sin(angle);
|
||||
scale = Math.Sin((1.0f - amount) * angle) * invscale;
|
||||
invscale *= Math.Sin((amount * angle));
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = 1.0f - amount;
|
||||
invscale = amount;
|
||||
}
|
||||
return new Vector3(
|
||||
v1.x * scale + v2.x * invscale,
|
||||
v1.y * scale + v2.y * invscale,
|
||||
v1.z * scale + v2.z * invscale
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user