MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GetDisplayPosition

Function GetDisplayPosition

TombEngine/Scripting/Internal/TEN/Util/Util.cpp:80–89  ·  view source on GitHub ↗

Get the projected display space position of a 3D world position. Returns nil if the world position is behind the camera view. @function GetDisplayPosition @tparam Vec3 worldPos 3D world position. @treturn Vec2 Projected display space position in percent. @usage -- Example: Display a string at the player's position. local displayPos = TEN.Util.GetDisplayPosition(Lara:GetPosition()) local str = TEN.

Source from the content-addressed store, hash-verified

78 // local str = TEN.Strings.DisplayString('You are here!', displayPos)
79 // TEN.Strings.ShowString(str, 4)
80 static sol::optional<Vec2> GetDisplayPosition(const Vec3& worldPos)
81 {
82 auto displayPos = g_Renderer.Get2DPosition(worldPos.ToVector3());
83 if (!displayPos.has_value())
84 return sol::nullopt;
85
86 return Vec2(
87 (displayPos->x / DISPLAY_SPACE_RES.x) * 100,
88 (displayPos->y / DISPLAY_SPACE_RES.y) * 100);
89 }
90
91 /// Translate a pair display position coordinates to pixel coordinates.<br>
92 // To be used with `Strings.DisplayString` and `Strings.DisplayString:SetPosition`.

Callers

nothing calls this directly

Calls 4

Vec2Class · 0.85
Get2DPositionMethod · 0.80
ToVector3Method · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected