Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed visualization for box/circle collider. #567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Hazelnut/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,19 @@ namespace Hazel {

if (m_ShowPhysicsColliders)
{
// Calculate z index for translation
float zIndex = 0.001f;
glm::vec3 cameraForwardDirection = m_EditorCamera.GetForwardDirection();
glm::vec3 projectionCollider = cameraForwardDirection * glm::vec3(zIndex);

// Box Colliders
{
auto view = m_ActiveScene->GetAllEntitiesWith<TransformComponent, BoxCollider2DComponent>();
for (auto entity : view)
{
auto [tc, bc2d] = view.get<TransformComponent, BoxCollider2DComponent>(entity);

glm::vec3 translation = tc.Translation + glm::vec3(bc2d.Offset, 0.001f);
glm::vec3 translation = tc.Translation + glm::vec3(bc2d.Offset, -projectionCollider.z);
glm::vec3 scale = tc.Scale * glm::vec3(bc2d.Size * 2.0f, 1.0f);

glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation)
Expand All @@ -500,7 +505,7 @@ namespace Hazel {
{
auto [tc, cc2d] = view.get<TransformComponent, CircleCollider2DComponent>(entity);

glm::vec3 translation = tc.Translation + glm::vec3(cc2d.Offset, 0.001f);
glm::vec3 translation = tc.Translation + glm::vec3(cc2d.Offset, -projectionCollider.z);
glm::vec3 scale = tc.Scale * glm::vec3(cc2d.Radius * 2.0f);

glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation)
Expand Down