Using a screen-drawn line to check for a collision [Vectrosity]

alt text alt text

So, I have been learning some of the basics of programming for the Android, and one of the things I'm trying to find out now is how to check and see if a "drawn GUI line" (Vectrosity Line) has overlapped a 3D object and if so to count it as a collision. I also want to let the 3D object to be notified of this (Like a SendMessage)

Edit: I am now using Vectrosity to draw my lines, which is a BIG help, but now I need to use check and see if a line was drawn over a particular object on screen

Also, i'm not trying to cut anything or looking for a complex collision, i just want to see if the line overlaps a certain object.

Well, as I see it you don't really have to calculate if the line intersected the objects. Your input is the touch interface. All you have to do is check if at any time did the user moved his finger over one of the objects (unless you don't want to consider a half-way cut object as a success - in which case you'll need some math).

You can just Raycast with the help of Camera.ScreenPointToRay and get the list of objects the user touched.

I don't know how worried you are with performance, but if a raycast is too expensive for some reason, you might even try and use the OnMouseOver event. It might just work.

I don't think there is an easy solution for this, especially if your objects have a complex geometry and you need very accurate information about where the object was slashed.

However the solution might be to calculate an "on-screen-bounding-box" for your object. To do this you could transform the vertices of your object's bounding box to ScreenSpace (using Camera.WorldToScreenPoint). That leaves you with 8 points. Now find the 4 that form the bounding box (contain the other 4 points). Now you have a rectangle. Checking if your line intersects this rectangle should be straightforward maths.

I would approach this by transforming the collider of your 3d objects into screen space, and using a Line to Line collision test for each polygon in your model.

I also assume that your collision info for the line is an actual line or an array of line segments for your curvature. You can do some early logic to help the performance:ie: segment.bounds overlaps model.bounds

If you were to resort to onmouseover for your raycasting, why not use onmousedrag and just get the start and stop points?