Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detecting collisions between a line and a sprite.
#11
I ment length + width.

Mine pretty fast, no muls.
Works with any size pics.
Get the x, y coordinate without no muls.
Doesn't even need to be on a coordinate plane, as long as the units are the same....

Why eight ifs?
Well the theory in mine is that if any corner of any pic is within the range of the other pic or = to it then the pics are touching.

Simple, fast, no muls, I don't see why you need to make this overcomplicated with circles.
i]"But...it was so beautifully done"[/i]
Reply
#12
Your method is called bounding-box collision detection, which is fine and commonly used for two rectangles colliding. I thought I would mention the line-circle collision detection because the topic is about detecting the collision between a line and an entity. You cannot create a bounding box around a line and the code required to detect whether a line intersects a box would be a lot longer than the code to detect whether a line intersects a circle/sphere.

-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#13
Quote:Your method is called bounding-box collision detection, which is fine and commonly used for two rectangles colliding. I thought I would mention the line-circle collision detection because the topic is about detecting the collision between a line and an entity. You cannot create a bounding box around a line and the code required to detect whether a line intersects a box would be a lot longer than the code to detect whether a line intersects a circle/sphere.

-shiftLynx


With that in mind, you can do a bounding box collision test first, since it's faster... especially when checking alot of objects. If your bounding box test returns true, then you go ahead with the sphere->plane test. Wink
Reply
#14
Bounding-box, never heard that before, but if the shoe fits. Big Grin

You could do my routine for a line w/a pic just like any other 2D object.

You make the Len = 1 and the Hig = however long it is (note: x/y coordinate must be top left corner)

You make your second one the dimensions of whatever they are.

So whats the problem? :???:
i]"But...it was so beautifully done"[/i]
Reply
#15
Consider a diagonal line; the bounding box around that line will occupy the area of a rectangle, of which the line is the hypotenuse. You will detect a collision between the "line" and an object even if the object appears to be a great distance from the line.

It works fine for horizontal and vertical lines, but for line at any orientation, it will fail.

-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#16
Your right.

BTW on a rectangle its called a diagonal, the hypotenuse is for a right triangle ONLY. Big Grin

FYI the long side on other triangles are called just the base. :wink:
i]"But...it was so beautifully done"[/i]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)