Here is my problem.
My game, for efficient rendering and collision is divided into regions. There will be many objects in each region that will dynamically move. When they move, I need a way to quickly determine which regions they are in.
An object can never be longer or wider than a region. Thus it can never be in more than 4 regions at once.
The tricky part is that the object's rectangles are Oriented Bounding Boxes using the separate axis theorem in 2D, thus they can be rotated.
The main way I have thought of doing this is by determining the regions of each point:
static public int colFromPos(float startX,float width, float x)
{
x -= startX;
return (int)Math.floor(x / width);
}
static public int rowFromPos(float startY,float height, float y)
{
y -= startY;
return (int)Math.floor(y / height);
}
This seems pretty fast.
I have thought of a couple ways to do it like this:
- I generate a bounding rectangle of the OBB and find the 4 regions of this rectangle. The drawback here is that a furthur test must then be done to determine if the object really is in.
- I determine the region of each corner and each midpoint of the OBB.
Are there better, faster ways of going about this? Are either of my solutions good ideas?
Thanks
