| 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 | { |
no test coverage detected