Skip to content

Fix world to collider local in shape containsPoint#926

Closed
jmiskovic wants to merge 1 commit intobjornbytes:devfrom
jmiskovic:fix/shapeContainsPoint
Closed

Fix world to collider local in shape containsPoint#926
jmiskovic wants to merge 1 commit intobjornbytes:devfrom
jmiskovic:fix/shapeContainsPoint

Conversation

@jmiskovic
Copy link
Contributor

@jmiskovic jmiskovic commented Feb 2, 2026

I noticed that shape attached to collider does incorrect query on :containsPoint().

containsPoint

I think the order of translation/rotation was wrong, but since inverseTransformPoint is used twice it was easier to switch to lovrColliderGetLocalPoint. The added benefit is that it will work better with motion interpolation.

Minimal reproduction:

local world = lovr.physics.newWorld()

local c = world:newBoxCollider(1, 0, 0, 1, 4, 1)
c:setOrientation(math.pi/2, 0,0,1)

print(c:getShape():containsPoint(2, 0, 0)) -- should be true

I also checked Shape:raycast(), that one gives correct results.

@bjornbytes
Copy link
Owner

I think inverseTransformPoint was just broken, it should be this to match inverseTransformRay, right? (translate, then rotate)

diff --git src/modules/physics/physics.c src/modules/physics/physics.c
index b17b08a4..74a46368 100644
--- src/modules/physics/physics.c
+++ src/modules/physics/physics.c
@@ -2090,8 +2090,8 @@ void lovrShapeGetAABB(Shape* shape, float aabb[6]) {
 static void inverseTransformPoint(float* point, float* position, float* orientation) {
   float inverse[4];
   quat_conjugate(quat_init(inverse, orientation));
-  quat_rotate(inverse, point);
   vec3_sub(point, position);
+  quat_rotate(inverse, point);
 }
 
 static void inverseTransformRay(float* origin, float* direction, float* position, float* orientation) {

Also, it looks like all the getLocalPoint/WorldPoint/LocalVector/WorldVector don't work with interpolation, whereas getPose does.

@jmiskovic
Copy link
Contributor Author

You're right. I've added to my test the shape offset with rotation and that broke down my fix.

containsPoint
Your version works as expected, aside from inertia wonkiness when shape is off center.

Interpolation is a separate issue I guess.

@bjornbytes
Copy link
Owner

Ok, I applied the diff from the comment. Thanks!

@bjornbytes bjornbytes closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants