Skip to content

Commit

Permalink
feat: make bboxes more visible
Browse files Browse the repository at this point in the history
  • Loading branch information
developer239 committed Dec 3, 2023
1 parent cb04670 commit 3168ce4
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/apps/day3/src/systems/RenderColliderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,32 @@ class RenderCollidersSystem : public ECS::System {
}

void Render(Core::Renderer& renderer) {
const int borderWidth = 5;

for (auto entity : GetSystemEntities()) {
auto& boxCollider =
ECS::Registry::Instance().GetComponent<BoxColliderComponent>(entity);
auto& rigidBody =
ECS::Registry::Instance().GetComponent<RigidBodyComponent>(entity);

SDL_Rect colliderRect = {
static_cast<int>(rigidBody.position.x + boxCollider.offset.x),
static_cast<int>(rigidBody.position.y + boxCollider.offset.y),
boxCollider.width,
boxCollider.height};

SDL_SetRenderDrawColor(
renderer.Get().get(),
boxCollider.color.r,
boxCollider.color.g,
boxCollider.color.b,
boxCollider.color.a
);
SDL_RenderDrawRect(renderer.Get().get(), &colliderRect);

for (int i = 0; i < borderWidth; ++i) {
SDL_Rect colliderRect = {
static_cast<int>(rigidBody.position.x + boxCollider.offset.x - i),
static_cast<int>(rigidBody.position.y + boxCollider.offset.y - i),
boxCollider.width + i * 2,
boxCollider.height + i * 2};
SDL_RenderDrawRect(renderer.Get().get(), &colliderRect);
}
}

SDL_SetRenderDrawColor(
renderer.Get().get(),
0,
0,
0,
255
);
SDL_SetRenderDrawColor(renderer.Get().get(), 0, 0, 0, 255);
}
};

0 comments on commit 3168ce4

Please sign in to comment.