libgdx / libgdx/libgdx

IntersectRayBoundsFast does not give correct results when testing against bounding boxes with zero height

Open
#5,128 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
25.4k
Forks
6.5k
Avg merge
1d 16h
Merged PRs (30d)
5

Description

Using the intersectRayBoundsFast method with a boundingbox that is zero in one dimension results in false negatives.

Issue details

Consider the example below: Creating a bounding box from (3,3,0) to (4,4,0) and casting a ray from the origin (0,0,0) in the direction (1,1,0) should result in true when invoking Intersector.intersectRayBoundsFast. However, it returns false.

A workaround is to give the box "volume", as the bounding box from (3,3,-1) to (4,4,1) is intersected correctly.

Intersector.intersectRayBounds works as desired, even with the zero-coordinates.

Reproduction steps/code
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.badlogic.gdx.math.collision.Ray;

public class TestClass {
    public static void main(String[] args) {
        Vector3 bottomLeft = new Vector3(3f, 3f, 0f);
        Vector3 topRight = new Vector3(4f, 4f, 0f);
        //Bounding box from (3,3) to (4,4)
        BoundingBox boundingBox = new BoundingBox(bottomLeft, topRight);
        //Ray from (0,0), direction (1,1)
        Ray ray = new Ray(Vector3.Zero, new Vector3(1f, 1f, 0f));
        System.out.println(Intersector.intersectRayBoundsFast(ray, boundingBox)); //prints "false", should print true
        System.out.println(Intersector.intersectRayBounds(ray, boundingBox, new Vector3())); //prints "true", should print true
    }
}
Version of LibGDX and/or relevant dependencies

1.9.8

Please select the affected platforms
  • Windows
  • Possibly others

I'll be happy to provide more clarification if needed - thank you for your time!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Intersector.intersectRayBoundsFast entry point and run the supplied Java reproduction with the zero-height BoundingBox and ray. Compare its result with Intersector.intersectRayBounds; done means the fast method returns true for the reported case without breaking the existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.