Sign in to follow this  
jagguy2

collisions

Recommended Posts

I am using silverlight and have found the collision test hitTest doesnt work well with images. The missile passes through the spaceship on occasions. I am using vb.net and want to know a way to test for collisions on 2D moving shapes. One is a image of a missile I fire and another of a spaceship.

Share this post


Link to post
Share on other sites
ok can detect a collision if i test both rectangles(approx space of each shape) of each object to see if they overlap.

Now what i want is a further test to see how accurate the hit was because an object is usually not a perfect rectangle Maybe the rectangle objects overlapped at the corners where the actual object isnt contained there.

What is a further test to be more accurate about where the objects collided?

Share this post


Link to post
Share on other sites
Quote:
Original post by CableGuy
Try searching for pixel perfect intersection test/collision detection. Basically you check whether two non transparent pixels occupy the same space. Of course there are ways to speed this up...


i cant detect pixels from a bitmap in silverlight so i cant do that.

Also lets go back a bit and look at how i detect intersecting rectangles for starters.NOw i thought i could test each corner of 2 rectangles and see if they fall in the boundary of the others rectangle.

Rect1 and rect2 will have 8 corners to test for. Also there is the case where both rectangles will intersect but no corners touch. Each corner has X,Y point

That means there are at least 9 tests.
Is there an easier way?

Share this post


Link to post
Share on other sites
It sounds like you're basically stuck, because you don't have any information about the shape of your objects beyond their bounding rectangles. You're going to have to build that information, either encoding it mathematically (1 circle + 2 rectangles - 1 triangle), or encoding it more explicitly in something like a bitmap or polygon list.

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
It sounds like you're basically stuck, because you don't have any information about the shape of your objects beyond their bounding rectangles. You're going to have to build that information, either encoding it mathematically (1 circle + 2 rectangles - 1 triangle), or encoding it more explicitly in something like a bitmap or polygon list.



what i am going to do is test for 1 sprie with each of its corner to see if it lies in the other rectangle. Also I test for 2 rects seperated, and also I test for 2 corners of other sprite to see if the lie in the 1st sprite (1 sprite is long and the other is wide).

This doesnt solve the case where 1 sprite hits the other at an angle or is just outside it.

If I do get a hit with what i got i do a more accurate pixel test on say 3-5 points on 1 sprite . I split the object into further smaller rectangles and do further tests and see if 3 points lie withing these rectangles.

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