Collision Detection

Im trying to find some simple sample code on collision detection. Ive been looking on the internet for some but there is f*** all out there.

Would anyone please be able to put up some sample code of a sphere colliding with a cone or something like that.

Havent had much luck over in the java programmers forum, please help.

[342 byte] By [scolari21a] at [2007-10-2 4:56:25]
# 1
> Im trying to find some simple sample code on> collision detection.What do you mean exactly?
prometheuzza at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 2

im doing a 3d game. Lets say that i have a sphere and a cube. I move the sphere around the screen using the keyboard...

I dont want the sphere to go through the cube, so i need some collision detection..

Im just looking for some sample code to get started.

I cannot find even one line of code on the internet that looks like collision detection.

scolari21a at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 3

This tutorial handles collision detection (2D, but it's a start):

[url=http://www.planetalia.com/cursos/Java-Invaders/JAVA-INVADERS-20.tutorial]Writing a Space Invaders game in Java[/url]

And please stop cross posting aka flooding.

http://forum.java.sun.com/thread.jspa?threadID=681769

http://forum.java.sun.com/thread.jspa?threadID=681774

prometheuzza at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 4

A very simple solution:

- surely, you have assigned a position (xy, xyz, it doesn't matter) to each object

- enclose each object in an imaginary sphere, and define its radius as an attribute of each object

- define a function distance(A, B), where A and B are two points with their 3D coordinates - for 2D the third square difference is not required. The formula, for 2D, would be (sorry for the horrible math display...)

__

/22 2

distance = \ / (A.x - B.x)+ (A.y - B.y)+ (A.z - B.z)

Now, given two objects, check if their distance is more than A.radius + B.radius:

- if ==, the objects are in contact

- if >, the objects are detached

- if <, crash! The objects collide.

Hope this helps...

@dm@

@dm@a at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 5
Sorry for the unformatted formula... it is:sqrt((A.x-B.x)^2+(A.y-B.y)^2+(C.x-C.y)^2)where ^2 is square, sqrt is square root
@dm@a at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 6
Sorry for the little spam, but the formula was wrong. It issqrt((A.x-B.x)^2+(A.y-B.y)^2+(A.z+B.z)^2)Now it's definitely ok. Sorry again....
@dm@a at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...
# 7
The last is a difference, not a sum:(A.z-B.z)In other words:difference of x'sdifference of y'sdifference of z'ssum all three previous resultssquare root of the sumSorry again, this is my last consecutive post.
@dm@a at 2007-7-16 1:00:43 > top of Java-index,Other Topics,Algorithms...