Ray casting or general segment2segment
Posted: Wed Apr 30, 2008 3:53 am
I have been trying to write a physics based shooter using chipmunk. So far the biggest problem I've run into is that there is no general support for raycasting or line/line intersection.
What I am trying to do, from a fixed point, get the closest intersection in the direction of a vector, with some max distance I care about. Right now I am adding a static line to the scene with a collision type handler. And for every collision I get during the update, I keep track of the one closest to the start. This has a few disadvantages, one, it takes alot of external management to keep track of multiple instances of this. I have to do the query during an update for example, when I only really care what happens at one particular time. Two, line segments don't intersect other line segments. That one is really a problem, right now my 'laser' goes right though my walls. The help docs list "Line segments: Meant mainly as a static shape. They can be attached to moving bodies, but they don’t generate collisions with other line segments." but it doesn't say why this is the case. Has nobody bothered to write it? Or is there some fundamental problem with line collisions? I can see how they would be hard to physically simulate, but I don't want them to move, just register collisions. I've written line/line collision more times then I can count but the thought of writing it again saddens me.
Has anyone written an extension to handle this? Either segment2segment or a more general mechanism for this? Would adding segment2segment to the list of collision types cause the simulation to freak out, even if they are all static?
Thanks,
Alex
What I am trying to do, from a fixed point, get the closest intersection in the direction of a vector, with some max distance I care about. Right now I am adding a static line to the scene with a collision type handler. And for every collision I get during the update, I keep track of the one closest to the start. This has a few disadvantages, one, it takes alot of external management to keep track of multiple instances of this. I have to do the query during an update for example, when I only really care what happens at one particular time. Two, line segments don't intersect other line segments. That one is really a problem, right now my 'laser' goes right though my walls. The help docs list "Line segments: Meant mainly as a static shape. They can be attached to moving bodies, but they don’t generate collisions with other line segments." but it doesn't say why this is the case. Has nobody bothered to write it? Or is there some fundamental problem with line collisions? I can see how they would be hard to physically simulate, but I don't want them to move, just register collisions. I've written line/line collision more times then I can count but the thought of writing it again saddens me.
Has anyone written an extension to handle this? Either segment2segment or a more general mechanism for this? Would adding segment2segment to the list of collision types cause the simulation to freak out, even if they are all static?
Thanks,
Alex