Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions Hazel/src/Hazel/Scene/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ namespace Hazel {
{
glm::vec2 Offset = { 0.0f, 0.0f };
glm::vec2 Size = { 0.5f, 0.5f };
float Rotation = 0.0f;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this Rotation variable been added to BoxCollider2DComponent? It doesn't seem to have any UI for setting it anywhere, so it seems like it would just always be 0.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

@AkliDev AkliDev Oct 29, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a box collider should be able to be rotated independently. Instead of removing rotation. You can add the field in SceneHierarchyPanel and make it serializable.


// TODO(Yan): move into physics material in the future maybe
float Density = 1.0f;
Expand Down
2 changes: 1 addition & 1 deletion Hazel/src/Hazel/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ namespace Hazel {
auto& bc2d = entity.GetComponent<BoxCollider2DComponent>();

b2PolygonShape boxShape;
boxShape.SetAsBox(bc2d.Size.x * transform.Scale.x, bc2d.Size.y * transform.Scale.y);
boxShape.SetAsBox(bc2d.Size.x * transform.Scale.x, bc2d.Size.y * transform.Scale.y, b2Vec2(bc2d.Offset.x, bc2d.Offset.y), bc2d.Rotation);
Comment thread
erikrl2 marked this conversation as resolved.
Outdated

b2FixtureDef fixtureDef;
fixtureDef.shape = &boxShape;
Expand Down
12 changes: 7 additions & 5 deletions Hazelnut/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,12 @@ namespace Hazel {
{
auto [tc, bc2d] = view.get<TransformComponent, BoxCollider2DComponent>(entity);

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

glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation)
glm::mat4 transform = glm::translate(glm::mat4(1.0f), tc.Translation)
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
* glm::translate(glm::mat4(1.0f), glm::vec3(bc2d.Offset, 0.001f))
* glm::rotate(glm::mat4(1.0f), bc2d.Rotation, glm::vec3(0.0f, 0.0f, 1.0f))
Comment thread
erikrl2 marked this conversation as resolved.
Outdated
* glm::scale(glm::mat4(1.0f), scale);

Renderer2D::DrawRect(transform, glm::vec4(0, 1, 0, 1));
Expand All @@ -546,11 +547,12 @@ namespace Hazel {
{
auto [tc, cc2d] = view.get<TransformComponent, CircleCollider2DComponent>(entity);

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

glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation)
* glm::scale(glm::mat4(1.0f), scale);
glm::mat4 transform = glm::translate(glm::mat4(1.0f), tc.Translation)
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
* glm::translate(glm::mat4(1.0f), glm::vec3(cc2d.Offset, 0.001f))
* glm::scale(glm::mat4(1.0f), glm::vec3(scale.x, scale.x, scale.z));

Renderer2D::DrawCircle(transform, glm::vec4(0, 1, 0, 1), 0.01f);
}
Expand Down