add llWorldPosToHUD

This commit is contained in:
UbitUmarov
2025-08-16 04:31:17 +01:00
parent 4ec6248dad
commit 392d324863
3 changed files with 68 additions and 0 deletions

View File

@@ -19609,6 +19609,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return 0;
}
public LSL_Vector llWorldPosToHUD(LSL_Vector wp)
{
if(!m_host.ParentGroup.IsAttachment)
return LSL_Vector.Zero;
uint atp = m_host.ParentGroup.AttachmentPoint;
if(atp < (uint)AttachmentPoint.HUDCenter2 || atp > (uint)AttachmentPoint.HUDBottomRight)
return LSL_Vector.Zero;
if (m_item.PermsGranter.NotEqual(m_host.OwnerID) ||
(m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
Error("llGetCameraPos", "No permissions to track the camera");
return LSL_Vector.Zero;
}
ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
if(sp is null)
return LSL_Vector.Zero;
Vector3 totarget = (Vector3)wp - sp.CameraPosition;
totarget.Normalize();
float at = totarget.Dot(sp.CameraAtAxis);
float left = totarget.Dot(sp.CameraLeftAxis);
float up = totarget.Dot(sp.CameraUpAxis);
if(atp != (uint)AttachmentPoint.HUDCenter2 && atp != (uint)AttachmentPoint.HUDCenter2)
{
int h = sp.ControllingClient.viewHeight;
if(h > 0)
{
float aspect = 0.5f * (float)sp.ControllingClient.viewWidth / h;
switch(atp)
{
case (uint)AttachmentPoint.HUDTop:
up -= 0.5f;
break;
case (uint)AttachmentPoint.HUDTopLeft:
up -= 0.5f;
left -= aspect;
break;
case (uint)AttachmentPoint.HUDTopRight:
up -= 0.5f;
left += aspect;
break;
case (uint)AttachmentPoint.HUDBottom:
up += 0.5f;
break;
case (uint)AttachmentPoint.HUDBottomLeft:
up += 0.5f;
left -= aspect;
break;
case (uint)AttachmentPoint.HUDBottomRight:
up += 0.5f;
left += aspect;
break;
}
}
}
return new(at > 0 ? 1 : -1, left, up);
}
static string HMAC_SHA224(string key, string message)
{
const int blockSize = 64;

View File

@@ -536,5 +536,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_String llComputeHash(LSL_String message, LSL_String algo);
LSL_String llGetRenderMaterial(LSL_Integer face);
LSL_Integer llIsLinkGLTFMaterial(LSL_Integer linknum, LSL_Integer face);
LSL_Vector llWorldPosToHUD(LSL_Vector WorldPosition);
}
}

View File

@@ -2894,5 +2894,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_LSL_Functions.llIsLinkGLTFMaterial(linknum, face);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LSL_Vector llWorldPosToHUD(LSL_Vector WorldPosition)
{
return m_LSL_Functions.llWorldPosToHUD(WorldPosition);
}
}
}