MiniB3D Sphere collision example

BlitzMax Forums/BlitzMax Programming/MiniB3D Sphere collision example

ozak(Posted 2006) [#1]
Yup. Just a quickie I needed for a project.
Just hacked it together from the primitives example :)

Control sphere with keys, it turns red when there's collision.

Here goes:




Punksmurf(Posted 2006) [#2]
Havent tested this yet but you are using the following calculation for the distance:
Local dist:Float = relx * relx + rely * rely + relz * relz

If I remember geometry well enough, you should take 3th root of that.
Since you compare it to the 2nd power of minDist, you actually took the 2nd root.


daaan(Posted 2006) [#3]
You know, with sin and cos, you could prevent the two spheres from going through one another.


Gabriel(Posted 2006) [#4]
Havent tested this yet but you are using the following calculation for the distance:

Local dist:Float = relx * relx + rely * rely + relz * relz


If I remember geometry well enough, you should take 3th root of that.
Since you compare it to the 2nd power of minDist, you actually took the 2nd root.


EDIT: Nope, on second read, I misread his code. You're right.


Punksmurf(Posted 2006) [#5]
Danielwooden, why on earth would you mess with sin and cos here? That's an awfully slow way to calculate the distance.


ozak(Posted 2006) [#6]
Yup. No need for sin and cos. And you can still do the velocity thing if need be. (To prevent collision to fail on two moving objects passing through each other in rare cases.)