Hazel
Hazel copied to clipboard
Fixed physics collider visualization offset
Describe the issue
The collider visualization rectangle does not match the actual position of the collider when using offset:
PR impact
List of related issues/PRs this will solve:
Impact | Issue/PR |
---|---|
Issues this solves | None |
Other PRs this solves | None |
Proposed fix
Adding the offset and rotation to the Box2D
box shape:
b2PolygonShape boxShape;
boxShape.SetAsBox(bc2d.Size.x * transform.Scale.x, bc2d.Size.y * transform.Scale.y,
b2Vec2(bc2d.Offset.x, bc2d.Offset.y), bc2d.Rotation);
Calculating the relative transform of the visualization rectangle before the entity's transform:
glm::vec3 scale = tc.Scale * glm::vec3(bc2d.Size * 2.0f, 1.0f);
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))
* glm::scale(glm::mat4(1.0f), scale);
Now it looks like:
Also fixed this for circle colliders.
Note:
Needed to add Rotation attribute to BoxCollider2DComponent
. You could expose this to the editor and serialize it.
Commit history is such a mess because I failed rebasing to master.
I applied your requested changes @TheCherno 👍