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

Method Get2DPosition

TombEngine/Renderer/RendererHelper.cpp:548–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546 }
547
548 std::optional<Vector2> Renderer::Get2DPosition(const Vector3& pos) const
549 {
550 auto point = Vector4(pos.x, pos.y, pos.z, 1.0f);
551 auto cameraPos = Vector4(
552 _gameCamera.Camera.WorldPosition.x,
553 _gameCamera.Camera.WorldPosition.y,
554 _gameCamera.Camera.WorldPosition.z,
555 1.0f);
556 auto cameraDir = Vector4(
557 _gameCamera.Camera.WorldDirection.x,
558 _gameCamera.Camera.WorldDirection.y,
559 _gameCamera.Camera.WorldDirection.z,
560 1.0f);
561
562 // Point is behind camera; return nullopt.
563 if ((point - cameraPos).Dot(cameraDir) < 0.0f)
564 return std::nullopt;
565
566 // Calculate clip space coords.
567 point = Vector4::Transform(point, _gameCamera.Camera.ViewProjection);
568
569 // w is close to 0; return nullopt.
570 if (std::abs(point.w) <= EPSILON)
571 return std::nullopt;
572
573 // Calculate NDC.
574 point /= point.w;
575
576 // Calculate and return 2D position.
577 return TEN::Utils::ConvertNDCTo2DPosition(Vector2(point));
578 }
579
580 std::pair<Vector3, Vector3> Renderer::GetRay(const Vector2& pos) const
581 {

Callers 6

DrawDebugStringFunction · 0.80
DrawMethod · 0.80
UpdateMethod · 0.80
AddCrosshairMethod · 0.80
AddDisplayPickupMethod · 0.80
GetDisplayPositionFunction · 0.80

Calls 4

ConvertNDCTo2DPositionFunction · 0.85
Vector4Function · 0.50
Vector2Function · 0.50
DotMethod · 0.45

Tested by

no test coverage detected