PDA

View Full Version : Exiting bouding box


bendingiscool
01-13-2009, 08:51 PM
Hey, back to bug some more ;)

Here is some code to check when a cylinder enters a bounding box of a group of cubes. When it enters it prints a word, what I need is for it to record when it exits aswell.

int $objectIsInside;// on/off switch

float $cylBBox[] = `xform -q -ws -boundingBox pCylinder1`;// cylinder's BBox
float $cubeBBox[] = `xform -q -ws -boundingBox group1`;// group's BBox

if ( ($cylBBox[0] < $cubeBBox[0]) && ($cylBBox[2] > $cubeBBox[2]) ||//check X BBox
($cylBBox[3] < $cubeBBox[3]) && ($cylBBox[5] > $cubeBBox[5]) ||//check Y BBox
($cylBBox[3] < $cubeBBox[3]) && ($cylBBox[4] > $cubeBBox[4]) ||//check Z BBox
($cylBBox[2] < $cubeBBox[2]) && ($cylBBox[0] > $cubeBBox[0]) ||//check -X BBox
($cylBBox[4] < $cubeBBox[4]) && ($cylBBox[3] > $cubeBBox[3]) ) //check -Z BBox
{
if (!$objectIsInside){// if not inside set to yes
$objectIsInside = yes;// check if object is in BBox
}
} else {
if ($objectIsInside) // if inside set to no
print "entered BBox";// print word
$objectIsInside = no;// check if object is in BBox
}

It only prints the word when the cylinder enters the first bounding box, I presume this is because of the off switch, but I can't work out how to switch it back on when it leaves the bounding box so that it can be used again.

Anyhelp with this one would be great as I am not sure how to get it to turn back on.

Thanks, Chris

bendingiscool
01-14-2009, 10:38 PM
I tried some suggestions, made a couple of changes to sort out syntax, now it says its ok as is doesn't give any errors, but for some reason its not printing out anything, no matter where the cylinder is.


$boolPrinted = 0;

float $cylBBox[] = `xform -q -ws -boundingBox pCylinder1`;// cylinder's BBox
float $grpBBox[] = `xform -q -ws -boundingBox group1`;// group's BBox

if ( ($cylBBox[0] < $grpBBox[0]) && ($cylBBox[3] > $grpBBox[3]) ||//check X BBox
($cylBBox[2] < $grpBBox[2]) && ($cylBBox[5] > $grpBBox[5]) )//check Z BBox
{
if ($boolPrinted == 0)
{
print "Object is in";
$boolPrinted = 1;
}
}
else
{
if ($boolPrinted == 1)
{
print "Object is out";
$boolPrinted = 0;
}

}

The bouding box numbers should be ok but for some reason it isn't printing the words.

Any ideas on this one?

Thanks, Chris

trancor
01-17-2009, 08:53 PM
Hey Chris, lookin through the code, you almost had it, you checked the X and Z but left out Y in the latest version of your script. But the major thing is that you were checking outside of the bounding box like this --
< -- | BBox | -- >
instead of --
| --> BBox < -- |

And for why it wasn't printing, you set it to print only if $boolPrinted = 1 when it was out; anyway, heres my touch up on the script --

$boolPrinted = 0;

float $cylBBox[] = `xform -q -ws -boundingBox pCylinder1`;// cylinder's BBox
float $grpBBox[] = `xform -q -ws -boundingBox group1`;// group's BBox

if( (($cylBBox[0] > $grpBBox[0]) && ($cylBBox[3] < $grpBBox[3])) && (($cylBBox[1] > $grpBBox[1]) && ($cylBBox[4] < $grpBBox[4])) && (($cylBBox[2] > $grpBBox[2]) && ($cylBBox[5] < $grpBBox[5])) ){
print "Object is in";
$boolPrinted = 1;
}else{
print "Object is out";
$boolPrinted = 0;
}


edit: sorry about reorganizing your script, I started on javascript and all that so I'm used to putting the {}'s on the same line as the elses and ifs

CGTalk Moderation
01-17-2009, 08:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.