fix: compose camera viewport within parent render area
This commit is contained in:
@@ -56,13 +56,18 @@ Math::RectInt ResolveCameraRenderArea(
|
||||
const Components::CameraComponent& camera,
|
||||
const RenderSurface& surface) {
|
||||
const Math::Rect viewportRect = camera.GetViewportRect();
|
||||
const float surfaceWidth = static_cast<float>(surface.GetWidth());
|
||||
const float surfaceHeight = static_cast<float>(surface.GetHeight());
|
||||
const Math::RectInt parentRenderArea = surface.GetRenderArea();
|
||||
const float parentWidth = static_cast<float>(std::max(parentRenderArea.width, 0));
|
||||
const float parentHeight = static_cast<float>(std::max(parentRenderArea.height, 0));
|
||||
|
||||
const int32_t left = static_cast<int32_t>(std::floor(viewportRect.x * surfaceWidth));
|
||||
const int32_t top = static_cast<int32_t>(std::floor(viewportRect.y * surfaceHeight));
|
||||
const int32_t right = static_cast<int32_t>(std::ceil((viewportRect.x + viewportRect.width) * surfaceWidth));
|
||||
const int32_t bottom = static_cast<int32_t>(std::ceil((viewportRect.y + viewportRect.height) * surfaceHeight));
|
||||
const int32_t left = parentRenderArea.x +
|
||||
static_cast<int32_t>(std::floor(viewportRect.x * parentWidth));
|
||||
const int32_t top = parentRenderArea.y +
|
||||
static_cast<int32_t>(std::floor(viewportRect.y * parentHeight));
|
||||
const int32_t right = parentRenderArea.x +
|
||||
static_cast<int32_t>(std::ceil((viewportRect.x + viewportRect.width) * parentWidth));
|
||||
const int32_t bottom = parentRenderArea.y +
|
||||
static_cast<int32_t>(std::ceil((viewportRect.y + viewportRect.height) * parentHeight));
|
||||
return Math::RectInt(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user