Looking into collision detection, I found some books that are three years old. I have also found a two tutorials that were one page long.
Is collision detection something that is hard enough that I should get the book on this subject?
Do the higher level languages have built in resources to handle this issue?
8 replies to this topic
#1
Posted 24 October 2010 - 07:03 PM
|
|
|
#2
Posted 24 October 2010 - 07:21 PM
It depends a lot on what you're doing. Collision detection with sprites is a lot easier than with 3D graphics.
#3
Posted 25 October 2010 - 04:59 AM
Is there a way to gage in which direction I should go? Currently I have no preference so I am thinking that I should go the easy path for now. My goal is 3D but working in on two dimensional arena is fine with me. Humm... I am guessing I should go the sprite route.
#4
Posted 25 October 2010 - 08:59 AM
Listen, basic collision detection is fine. I had a VB5 function that checks for collision between two 2D squares - the simplest form of collision detection. I'm gonna search for it a bit and post back when I'll find it.
-EDIT-
Aw man, I forgot that I formatted my HD. My friend will bring me the code tomorrow. I found something, but I'm not sure if it works.
Here's some VB5 code -
In C/C++ it will look like so -
Again, I'm not sure if it works. Try it, if it doesn't I'll post the working version tomorrow.
-EDIT-
Aw man, I forgot that I formatted my HD. My friend will bring me the code tomorrow. I found something, but I'm not sure if it works.
Here's some VB5 code -
Quote
If (Image1.Top+Image1.Height)>=Image2.Top _ 'move Image1 from top downto image2
Or Image1.Top<=(Image2.Top+Image2.Height) _ 'move image1 from bottom upto image2
Or (Image1.Left+Image1.Width)>=Image2.Left _ ' move Image1 from Left to Image2
Or Image1.Left<=(Image2.Left+Image2.Width) _ 'move Image1 from Right to Image2
Then
Msg "Crashed"
End If
Or Image1.Top<=(Image2.Top+Image2.Height) _ 'move image1 from bottom upto image2
Or (Image1.Left+Image1.Width)>=Image2.Left _ ' move Image1 from Left to Image2
Or Image1.Left<=(Image2.Left+Image2.Width) _ 'move Image1 from Right to Image2
Then
Msg "Crashed"
End If
Quote
if( (Image1.Top+Image1.Height)>=Image2.Top || Image1.Top<=(Image2.Top+Image2.Height) || (Image1.Left+Image1.Width)>=Image2.Left || Image1.Left<=(Image2.Left+Image2.Width) )
{
//If it turns out to be true, then both objects are colliding.
}
{
//If it turns out to be true, then both objects are colliding.
}
Again, I'm not sure if it works. Try it, if it doesn't I'll post the working version tomorrow.

There is no problem that cannot be solved by the use of high explosives.
#5
Posted 25 October 2010 - 12:15 PM
Collision detections isn't that hard; it just is expensive in 3d if you do pixel by pixel detection.
I would start with 2D circles, say a simplistic pool/snooker graphic. Then 2d rectangles, then 2d polygons. Then move into the 3rd dimension. It shouldn't take long to
create some code to demo these things.
All the math exists already so it's just reading and experimenting.
I would start with 2D circles, say a simplistic pool/snooker graphic. Then 2d rectangles, then 2d polygons. Then move into the 3rd dimension. It shouldn't take long to
create some code to demo these things.
All the math exists already so it's just reading and experimenting.
#6
Posted 25 October 2010 - 02:35 PM
Thanks, I will start with simple shapes. AdvMutant, thanks for the code, I will play with it over the next two weeks. I have to tare these things down and build them many times.
#7
Posted 25 October 2010 - 09:55 PM
No problem :)
@abzero, Can you please post the circle collision code? It might be useful.
@abzero, Can you please post the circle collision code? It might be useful.

There is no problem that cannot be solved by the use of high explosives.
#8
Posted 26 October 2010 - 01:12 PM
@AdvMutant - Circles are easy. For a circle just store the centre point and the radius. Then if the distance between the two centre points is equal to or less than the sum of the two radii then a collision has taken place.
Ofcause you need to work out the distance between the centre points; this is also simple using Pythagoras:
Given centre of circle one: x_1, y_1 and circle two x_2, y_2
and radii's r_1 and r_2, then it would be somthing like this:
There are some speed ups, like eliminating the SQRT etc. Btw this is off the top of my head from an article about collison detection that i read a while back.
Ofcause you need to work out the distance between the centre points; this is also simple using Pythagoras:
Given centre of circle one: x_1, y_1 and circle two x_2, y_2
and radii's r_1 and r_2, then it would be somthing like this:
//Calculate distance between the two points. // a*a + b*b = c*c c = sqrt ( pow(x_1-x_2,2), pow(y_1-y_2,2)); // Check collision return c<=(r_1+r_2);
There are some speed ups, like eliminating the SQRT etc. Btw this is off the top of my head from an article about collison detection that i read a while back.
#9
Posted 26 October 2010 - 08:41 PM
Thanks.
As usually, I'm not that good at maths, so I'll try to mess with it a bit and figure out how it works.
As usually, I'm not that good at maths, so I'll try to mess with it a bit and figure out how it works.

There is no problem that cannot be solved by the use of high explosives.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









