Blockland Forums > Modification Help
Checking if a brick is completely covered by another brick.
Treynolds416:
If you find me the getWorldBox() syntax, I'll write you a function
otto-san:
--- Quote from: Treynolds416 on April 28, 2012, 02:56:38 PM ---If you find me the getWorldBox() syntax, I'll write you a function
--- End quote ---
For what?
and there are no parameters (besides the object of course)
Treynolds416:
--- Code: ---function isCoveredCompletely(%bBrick,%tBrick)
{
%bBox = %bBrick.getWorldBox();
%bMinX = getWord(%bBox,0);
%bMinY = getWord(%bBox,1);
%bMaxX = getWord(%bBox,3);
%bMaxY = getWord(%bBox,4);
%bMaxZ = getWord(%bBox,5);
%tBox = %tBrick.getWorldBox();
%tMinX = getWord(%tBox,0);
%tMinY = getWord(%tBox,1);
%tMinZ = getWord(%tBox,2);
%tMaxX = getWord(%tBox,3);
%tMaxY = getWord(%tBox,4);
if(%bBrick.getNumUpBricks() != 1 || %bMaxZ != %tMinZ)
return 0;
%bDiag = mSqrt(mPow(%bMaxX - %bMinX,2) + mPow(%bMaxY - %bMinY,2));
%tDiag = mSqrt(mPow(%tMaxX - %tMinX,2) + mPow(%tMaxY - %tMinY,2));
if(%tDiag < %bDiag || %tMaxX < %bMaxX || %tMaxY < %bMaxY || %tMinX > %bMinX || %tMinY > %bMinY)
return 0;
return 1;
}
--- End code ---
I used a lot of variables so you can see what I did. I also used two if statements instead of one because I do not like monolithic if statements. This should work, but it is untested. Knowing myself, I would guess that I have made one or two silly mistakes in the code, so look for them if it doesn't work.
Edit: Added parentheses after getNumUpBricks
Edit2: Added more triggers to if statement
otto-san:
--- Quote from: Treynolds416 on April 28, 2012, 03:45:18 PM ---I would guess that I have made one or two silly mistakes in the code, so look for them if it doesn't work.
--- End quote ---
the only syntactical error i see is one set of forgotten parenthesis
so i'll test that, thanks :D
works. :D
Treynolds416:
Just added more to the second if statement, I forgot to check the mins in it. Anyway, if you want I can make a compressed version that uses fewer variables.