Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Inside or Outside llGetBoundingBox()?

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-09-2009 04:57
Is this the right way to do it? I'm testing it with llTouch_Start() at the moment (though ultimately I will be using llCollisionStart()) . It seems to be giving me the right results, depending on whether I'm inside or outside the box when I touch it, no matter how i rotate it.

I ask because I want to multiply min and max by llGetRot(), but that gives me the wrong results, so I guess I shouldn't. So it seems to work but I don't quite understand why, a situation with which I am not wholly comfortable though sadly familiar.

CODE

vector min;
vector max;
vector detected;
default
{
state_entry()
{
min=llList2Vector(llGetBoundingBox(llGetKey()),0);
max=llList2Vector(llGetBoundingBox(llGetKey()),1);
}

touch_start(integer total_number)
{
detected=llDetectedPos(0);
min=llList2Vector(llGetBoundingBox(llGetKey()),0);
// min*=llGetRot();
llOwnerSay("min is "+(string)min);
max=llList2Vector(llGetBoundingBox(llGetKey()),1);
// max*=llGetRot();
llOwnerSay("max is "+(string)max);
vector offset = detected-llGetPos();
offset = offset*llGetRot(); //convert to local rotation
llOwnerSay("offset is "+(string)offset);

if(offset.x > min.x&&offset.x < max.x &&
offset.y > min.y&&offset.y < max.y &&
offset.z > min.z&&offset.z < max.z ){
llOwnerSay("inside");
}
else{
llOwnerSay("outside");
}

}
}
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
12-09-2009 05:59
You are already rotating offset by llGetRot(), so you don't need to rotate the bounding-box values as they are now within the same local-space. So unless I missed something it looks correct to me, my only advice would be to avoid calling the llGetBoundingBox() twice, in case the values change between operations; i.e - call it once and assign the value to a list, then extract the individual values like-so:

vector myPos = llGetPos();
list bounding = llGetBoundingBox(llGetKey());
vector min = llList2Vector(bounding, 0);
vector max = llList2Vector(bounding, 1);

Also, I don't understand your use of global variables, and why you're grabbing the bounding-box in state_entry() when you grab the values in touch_start() as well? You can probably trim the state_entry() stuff and move the variables into touch_start(), unless you think you can reliably detect when the bounding-box has changed.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-09-2009 07:33
From: Haravikk Mistral
You are already rotating offset by llGetRot(), so you don't need to rotate the bounding-box values as they are now within the same local-space. So unless I missed something it looks correct to me, my only advice would be to avoid calling the llGetBoundingBox() twice, in case the values change between operations; i.e - call it once and assign the value to a list, then extract the individual values like-so:

vector myPos = llGetPos();
list bounding = llGetBoundingBox(llGetKey());
vector min = llList2Vector(bounding, 0);
vector max = llList2Vector(bounding, 1);

Also, I don't understand your use of global variables, and why you're grabbing the bounding-box in state_entry() when you grab the values in touch_start() as well? You can probably trim the state_entry() stuff and move the variables into touch_start(), unless you think you can reliably detect when the bounding-box has changed.
Thanks so much, Haravikk. Point taken about the globals and calling llBoundingBox() twice; what I posted was my rough draft for part of something larger, made to see if I could correctly detect my position relative to the box. I was so surprised I'd got it working, though not sure how, that I posted it here to check before tidying it up!

Thanks so much for the explanation.