Collision of moving object with rectangular target
Posted: Tue Jul 28, 2009 4:06 am
I'm having a terrible time with this... and I was pretty sure I'd done what I needed and I'm getting really odd results. Here's what I have at this point...
Everything is in .12 fixed point to work with the Lerp trig functions. I have a "gun" that rotates and bullets that fire with a velocity found with the negative cosLerp for x and sinLerp for y. I'm testing different bullet speeds with varied multipliers.
At the same time, I record the angle of fire (from the gun's angle) in the bullet's structure and begin to use a similar to cohen-sutherland type algorithm to check for simple rejections...
At certain points, however, I begin to check if line segments intersect with borders of the target like this for example:
The problem is that I'm getting odd intersect points. When I test the slope (tanLerp(angle)) by testing two points on the line vs. the original angle they end up differing... Any thoughts?
Everything is in .12 fixed point to work with the Lerp trig functions. I have a "gun" that rotates and bullets that fire with a velocity found with the negative cosLerp for x and sinLerp for y. I'm testing different bullet speeds with varied multipliers.
At the same time, I record the angle of fire (from the gun's angle) in the bullet's structure and begin to use a similar to cohen-sutherland type algorithm to check for simple rejections...
At certain points, however, I begin to check if line segments intersect with borders of the target like this for example:
Code: Select all
y = ymax; // bottom border of target...
x = x0 + divf32(y - y0, tanLerp(angle)); // find intersect x value where y = ymax...
if(x < xmax && x > xmin){//etc