[bmx] Boxes Collide by Leon Drake [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : Boxes Collide
Author : Leon Drake
Posted : 1+ years ago

Description : An Alternate way to detect is two 3d Bounding boxes are colliding using only a simple if. Accepts 2 types of coordinates defaults are x,y,z,w,h,d

where w h d are the distances from x y z

the other way uses w h d as 3d coordinates not distances from x y z


Code :
Code (blitzmax) Select
Function boxescollide(x#,y#,z#,w#,h#,d#,x2#,y2#,z2#,w2#,h2#,d2#,coordtype=True)


If coordtype=True Then

w# = x#+w#
h# = y#+h#
z# = z#+d#

w2# = x2#+w2#
h2# = y2#+h2#
z2# = z2#+d2#


EndIf


If x# <= w2# And w# >= x2# And y# <= h2# And h# >= y2# And z# <= d2# And d# >= z2# Then
Return True
Else
Return False
EndIf


End Function


Comments :


IPete2(Posted 1+ years ago)

 Don't forget to add in Z2# in the function call!IPete2.


Leon Drake(Posted 1+ years ago)

 LOLZ oh man.