Sign in to follow this  
pyroExtreme

Collision between a point and a box

Recommended Posts

pyroExtreme    105
I'm currently working on a 3d game and have been looking into and working on the collisions. I have collision of two OBBs working using the separating axis theorem. But I also need to be able to check if a single point lies within a OBB, obviously I could use SAT and give my OBB representing the point a half size of 0 but I was wondering if the is a different more efficient way of doing this calculation?

Any suggestions would be greatly appreciated, even just the names of some methods.

Thanks in advance.

Share this post


Link to post
Share on other sites
jyk    2094
1. Transform the point into the local space of the box.

2. See if the (transformed) point coordinates are in the range [-extent, extent] for each of the cardinal axes.

Share this post


Link to post
Share on other sites
pyroExtreme    105
thanks for the advice, I kinda have it working can rotate my box through the Y (up) axis and the collision detection works and well as when there is no rotation at all, the problem I have is when I rotate X or Z axis. Not sure if I'm doing everything correctly.

1. Transform the point to local space: Am I right in thinking you do this by multiplying the point by the inverse world matrix of the box.

2. check agains the -extended and extended cardinal axes, this is probably where I'm going wrong. Do I need to do something special when the box is rotated???

Thanks again in advance

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Transform the point to local space: Am I right in thinking you do this by multiplying the point by the inverse world matrix of the box.
Yes.
Quote:
Do I need to do something special when the box is rotated???
No.

If it's not working as you expect, you might post your code.

Share this post


Link to post
Share on other sites
pyroExtreme    105
Well with a little digging i've worked out what it is :).

The box when getting rotated in world around the X and Z isn't rotated around the boxes center it getting rotated around the bottom of the box, cos the boxes are constructed from data from Max. so I'm guessing instead of checking if it between -extend and extend for X and Z I just need to check if it inbetween 0 and extend *2?

cos this is part of a group project i'm working on so if i go changing the way the boxes read in from max it will break other areas of the game.

Share this post


Link to post
Share on other sites
pyroExtreme    105
sorry I meant check from 0 to extend*2 for Y axis cos obviously the Y values in local space will need to be worked out from the bottom not the center and from -extend to extend for X and Z axes

Share this post


Link to post
Share on other sites
jyk    2094
Correct, if your boxes are not centered at the origin you'll have to adjust your code accordingly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this