Code archives/3D Graphics - Maths/Boxes Collide

This code has been declared by its author to be Public Domain code.

Download source code

Boxes Collide by Leon Drake2007
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
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

IPete22007
Don't forget to add in

Z2#

in the function call!

IPete2.


Leon Drake2007
LOLZ oh man.


Code Archives Forum