Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ViewportCulling.cpp
Go to the documentation of this file.
1/**
2 * @file ViewportCulling.cpp
3 * @brief Viewport culling implementation (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 */
7
8#include "ViewportCulling.h"
9
10#include <cstddef>
11
12namespace Olympe {
13
14// ============================================================================
15// IsNodeVisible
16// ============================================================================
17
19 float nodeW, float nodeH,
20 const ViewRect& viewport,
21 float margin)
22{
23 // Expand the viewport by margin on all sides.
24 float vpLeft = viewport.x - margin;
25 float vpTop = viewport.y - margin;
26 float vpRight = viewport.x + viewport.w + margin;
27 float vpBottom = viewport.y + viewport.h + margin;
28
29 // Node AABB
30 float nLeft = nodeX;
31 float nTop = nodeY;
32 float nRight = nodeX + nodeW;
33 float nBottom = nodeY + nodeH;
34
35 // AABB overlap test: no overlap when one rect is entirely outside the other.
36 if (nRight < vpLeft ) return false;
37 if (nLeft > vpRight ) return false;
38 if (nBottom < vpTop ) return false;
39 if (nTop > vpBottom ) return false;
40
41 return true;
42}
43
44// ============================================================================
45// FilterVisibleNodes
46// ============================================================================
47
49 const std::vector<std::pair<int, ViewRect>>& nodeRects,
50 const ViewRect& viewport,
51 float margin)
52{
53 std::vector<int> visible;
54 visible.reserve(nodeRects.size());
55
56 for (size_t i = 0; i < nodeRects.size(); ++i)
57 {
58 const ViewRect& r = nodeRects[i].second;
59
60 if (IsNodeVisible(r.x, r.y, r.w, r.h, viewport, margin))
61 visible.push_back(nodeRects[i].first);
62 }
63
64 return visible;
65}
66
67} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Viewport culling helpers for the VS graph canvas (Phase 7).
static std::vector< int > FilterVisibleNodes(const std::vector< std::pair< int, ViewRect > > &nodeRects, const ViewRect &viewport, float margin=50.0f)
Filters a list of (id, rect) pairs and returns only the visible IDs.
static bool IsNodeVisible(float nodeX, float nodeY, float nodeW, float nodeH, const ViewRect &viewport, float margin=50.0f)
Tests whether a single node rectangle overlaps the viewport.
< Provides AssetID and INVALID_ASSET_ID
An axis-aligned rectangle used to describe the viewport or a node bounds.
float x
Left edge.
float y
Top edge.