summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2024-10-08 15:40:12 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2024-10-08 15:40:12 +0300
commitccc7fffb22b347149bf807b9d92677e5616c5017 (patch)
tree44a3abe1b70e48daacda86ebf77cdc56abd6da0f /indra/newview
parent8a44149b481bf118d30a457514711c6ba4cf29b6 (diff)
Lua api to get avatar screen position
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llagentlistener.cpp36
-rw-r--r--indra/newview/llagentlistener.h1
-rw-r--r--indra/newview/scripts/lua/require/LLAgent.lua9
-rw-r--r--indra/newview/scripts/lua/test_screen_position.lua8
4 files changed, 53 insertions, 1 deletions
diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp
index f6029e7297..9255a850e5 100644
--- a/indra/newview/llagentlistener.cpp
+++ b/indra/newview/llagentlistener.cpp
@@ -49,7 +49,7 @@
#include "llsdutil_math.h"
#include "lltoolgrab.h"
#include "llhudeffectlookat.h"
-#include "llagentcamera.h"
+#include "llviewercamera.h"
#include "resultset.h"
#include <functional>
@@ -199,6 +199,13 @@ LLAgentListener::LLAgentListener(LLAgent &agent)
"reply contains \"result\" table with \"id\", \"global_pos\", \"region_pos\" fields",
&LLAgentListener::getNearbyObjectsList,
llsd::map("reply", LLSD()));
+
+ add("getAgentScreenPos",
+ "Return screen position of the [\"avatar_id\"] avatar or own avatar if not specified\n"
+ "reply contains \"x\", \"y\" coordinates and \"onscreen\" flag to indicate if it's actually in within the current window\n"
+ "avatar render position is used as the point",
+ &LLAgentListener::getAgentScreenPos,
+ llsd::map("reply", LLSD()));
}
void LLAgentListener::requestTeleport(LLSD const & event_data) const
@@ -810,3 +817,30 @@ void LLAgentListener::getNearbyObjectsList(LLSD const& event_data)
}
response["result"] = objresult->getKeyLength();
}
+
+void LLAgentListener::getAgentScreenPos(LLSD const& event_data)
+{
+ Response response(LLSD(), event_data);
+ LLVector3 render_pos;
+ if (event_data.has("avatar_id"))
+ {
+ LLUUID avatar_id(event_data["avatar_id"]);
+ for (LLCharacter* character : LLCharacter::sInstances)
+ {
+ LLVOAvatar* avatar = (LLVOAvatar*)character;
+ if (!avatar->isDead() && (avatar->getID() == avatar_id))
+ {
+ render_pos = avatar->getRenderPosition();
+ break;
+ }
+ }
+ }
+ else if (gAgentAvatarp.notNull() && gAgentAvatarp->isValid())
+ {
+ render_pos = gAgentAvatarp->getRenderPosition();
+ }
+ LLCoordGL screen_pos;
+ response["onscreen"] = LLViewerCamera::getInstance()->projectPosAgentToScreen(render_pos, screen_pos, false);
+ response["x"] = screen_pos.mX;
+ response["y"] = screen_pos.mY;
+}
diff --git a/indra/newview/llagentlistener.h b/indra/newview/llagentlistener.h
index f1e85f0923..8801c9f7ea 100644
--- a/indra/newview/llagentlistener.h
+++ b/indra/newview/llagentlistener.h
@@ -70,6 +70,7 @@ private:
void getID(LLSD const& event_data);
void getNearbyAvatarsList(LLSD const& event_data);
void getNearbyObjectsList(LLSD const& event_data);
+ void getAgentScreenPos(LLSD const& event_data);
LLViewerObject * findObjectClosestTo( const LLVector3 & position, bool sit_target = false ) const;
diff --git a/indra/newview/scripts/lua/require/LLAgent.lua b/indra/newview/scripts/lua/require/LLAgent.lua
index 70f3cdfffb..b2be69dcdf 100644
--- a/indra/newview/scripts/lua/require/LLAgent.lua
+++ b/indra/newview/scripts/lua/require/LLAgent.lua
@@ -131,6 +131,15 @@ function LLAgent.getNearbyObjectsList(...)
return result(leap.request('LLAgent', args))
end
+-- Get screen position of your own avatar or any other (if "avatar_id is specified)
+-- reply contains "x", "y" coordinates and "onscreen" flag to indicate if it's actually in within the current window
+-- avatar render position is used as the point
+function LLAgent.getAgentScreenPos(...)
+ local args = mapargs('avatar_id', ...)
+ args.op = 'getAgentScreenPos'
+ return leap.request('LLAgent', args)
+end
+
-- ***************************************************************************
-- Autopilot
-- ***************************************************************************
diff --git a/indra/newview/scripts/lua/test_screen_position.lua b/indra/newview/scripts/lua/test_screen_position.lua
new file mode 100644
index 0000000000..94d57339b1
--- /dev/null
+++ b/indra/newview/scripts/lua/test_screen_position.lua
@@ -0,0 +1,8 @@
+LLAgent = require 'LLAgent'
+
+local screen_pos = LLAgent.getAgentScreenPos()
+if screen_pos.onscreen then
+ print("Avatar screen coordinates X: " .. screen_pos.x .. " Y: " .. screen_pos.y)
+else
+ print("Avatar is not on the screen")
+end