Hit Testing
        by Danko Kozar : 3 December 2004

Back to 3d
You can easily imagine this 2d view being converted into 3d isometric view - with only difference that y axis becomes z axis with adding a new y axis. hitTest2 function then becomes:

// --- hit test function --------------------------------
function hitTest2(obj1, obj2) {
if ((Math.abs((obj1.x+obj1.a/2)-(obj2.x+obj2.a/2))<(obj1.a+obj2.a)/2) and (Math.abs((obj1.y+obj1.b/2)-(obj2.y+obj2.b/2))<(obj1.b+obj2.b)/2) and (Math.abs((obj1.z+obj1.c/2)-(obj2.z+obj2.c/2))<(obj1.c+obj2.c)/2)) {
return (true);

Using grey buttons, try to hit a purple box with the blue one (box sizes are 50x36x50):

[ rectangular hit testing in 3d ]

Download ZIP

Never mind if objects are displayed with wrong depth - that's because depth sorting cannot be done at this stage (the objects are still overlapping).




page 3 of 3



SUPPORTERS:'s fast and reliable hosting provided by Media Temple.