Author Topic: Checking if a brick is completely covered by another brick.  (Read 1390 times)

I want to know if the the above brick to completely covers a brick below it.

I tried scratching my head for a bit and messing around with some world box vector math stuff, but I can't seem to get it quite right.

I found these in a posted console dump.
   virtual int getExposedAreaTop() {}
   virtual int getExposedAreaBottom() {}
Never used them before, tell me how they work.

If they don't work, you can try getWorldBox() and getWorldBoxCenter() to get the center point and vertex points. I've never used getWorldBox() either, so I'm not sure if it returns points or not

Here's some useful functions:


Exposure:
%brick.getExposedAreaBottom() - ()
%brick.getExposedAreaEast() - ()
%brick.getExposedAreaNorth()
%brick.getExposedAreaSouth() - ()
%brick.getExposedAreaTop() - ()
%brick.getExposedAreaWest() - ()

%brick.iloveposed() - ()exposed = no bricks attached to one end

Up/Down Bricks
%brick.getUpBrick() - (int index)Returns up brick at given index.
%brick.getDownBrick() - (int index)Returns down brick at given index.
%brick.getNumDownBricks() - ()Returns number of bricks in downlist.
%brick.getNumUpBricks() - ()Returns number of bricks in uplist.

%brick.dumpDownList() - ()Dumps the downbrick list.
%brick.dumpUpList() - ()Dumps the upbrick list.

Path-to-Ground
%brick.getDistanceFromGround() - Returns number of connections away from the ground
%brick.hasFakePathToGround() - ()Returns true if brick is attached to a baseplate (considers blown-up bricks to be dead).
%brick.hasPathToGround() - ()Returns true if brick is attached to a baseplate.

%brick.willCauseChainKill() - () returns true if killing this brick will cause others to fall
« Last Edit: April 28, 2012, 02:24:25 PM by Greek2me »

I've already considered all those functions and none of them seem to be any help.

I was surprised getExposedArea didn't help. It just said 0 each time.


If they don't work, you can try getWorldBox() and getWorldBoxCenter() to get the center point and vertex points. I've never used getWorldBox() either, so I'm not sure if it returns points or not
I tried scratching my head for a bit and messing around with some world box vector math stuff, but I can't seem to get it quite right.
derp

I've already considered all those functions and none of them seem to be any help.

I was surprised getExposedArea didn't help. It just said 0 each time.

Strange, they only seem to work on ghost bricks...

If you find me the getWorldBox() syntax, I'll write you a function

If you find me the getWorldBox() syntax, I'll write you a function
For what?

and there are no parameters (besides the object of course)

Code: [Select]
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;
}

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
« Last Edit: April 28, 2012, 09:43:16 PM by Treynolds416 »

I would guess that I have made one or two silly mistakes in the code, so look for them if it doesn't work.
the only syntactical error i see is one set of forgotten parenthesis

so i'll test that, thanks :D


works. :D
« Last Edit: April 28, 2012, 07:41:45 PM by otto-san »

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.