Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

bounding box coords

Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-25-2007 17:55
Hi everyone - would someone please let know how to derive the region coordinate vectors of the 8 corners of the box represented by the results returned from llGetBoundingBox. I think I have my head around the concept that a box can be defined by just 2 vectors but anything beyond that is beyond my humble LSL skills.
_____________________
Love Liberty
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
04-25-2007 20:19
Some stuff about this at http://rpgstats.com/wiki/index.php?title=LlGetBoundingBox
Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-25-2007 20:30
Thanks Ed. I looked at that but all it does is scale the object containing the script to the same size - not much help.
_____________________
Love Liberty
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
04-25-2007 23:36
I'll stick my neck out and tell you how I think it works. Anyone else can jump in and correct me!

Think of a cardboard box's diagonally opposite corners (think longest diagonal between two faces). They go from the corner of the box with lowest x,y,z values up to the corner with the highest x,y and z vealues. The list contains the x,y,z position vectors at the ends of that diagonal.

The example quoted shows how to get two vectors min and max and put values to them.

So if we look at the box so that min is at the bottom left, closest to us, we are facing north. x increases from left to right, y increases as we look further into the opposite side of the box, and z increases upwards. Vector max will be on the top right corner of the opposing face without changing our pov.

So the four corners of the closest face will be:

bottom left: min.x, min.y, min.z
top left: min.x, min.y, max.z
top right: max.x, min.y, max.z
bottom right: max.x, min.y, min.z

Notice they all used min.y

and looking through the box to the far face, we should have

bottom left: min.x, max.y, min.z
top left: min.x, max.y, max.z
top right: max.x, max.y, max.z
bottom right: max.x, max.y, min.z

Notice they all used max.y


hth

Ed
Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-26-2007 00:38
I've figured out that much. Its the rest of it I need help with.

I think we have to apply a rotation about the root(not the geometric centre) and then convert them from local to region coords. How do I do this?
_____________________
Love Liberty
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
04-26-2007 00:59
There is no rotation information in a bounding box that I can see.

Might help if you explain what you trying to do?
Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-26-2007 01:10
Its for a collision-avoidance system.

For an obstacle detected by a sensor, we can get the root pos, rotation and a bounding box for it. I think (I hope) thats enough info to derive the coords of the bounding box.

But this rotation/vector stuff is all voodoo to me at the moment, so i suppose this is what they call the learning curve.
_____________________
Love Liberty
Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-26-2007 01:36
I was just thinking...

Maybe there's a quick way - What i want I suppose is the coords relative to me, so maybe there is some voodoo to directly translate the obstacle's corners' local coords into my local coords by doing some math with the 2 positions and rotations(mine and the obstacle's)
_____________________
Love Liberty
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
I think...
04-26-2007 07:24
vector in world coord = vector in my coord * my rotation.

vector in my coord = vector in world coord / *my rotation.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
04-26-2007 09:49
The following function returns the Min and Max corners of a world-aligned bounding box, when passed a list containing the Min and Max corners of an object's locally-aligned bounding box (i.e., return value of llGetBoundingBox ), that object's position, and it's rotation.
CODE
list WorldBox( list Box, vector Pos, rotation Rot )
{
vector Min = llList2Vector( Box, 0 );
vector Max = llList2Vector( Box, 1 );

// Build a list of the object's 8 locally-aligned bounding box corners
Box = [ Min,
< Min.x, Min.y, Max.z >,
< Min.x, Max.y, Min.z >,
< Min.x, Max.y, Max.z >,
< Max.x, Max.y, Min.z >,
< Max.x, Min.y, Max.z >,
< Max.x, Min.y, Min.z >,
Max ];

// reset Min and Max
Min = ZERO_VECTOR;
Max = ZERO_VECTOR;

integer i = 8;

while( i )
{
// Apply the object's rotation to each corner
vector Corner = llList2Vector( Box, --i ) * Rot;

// Determine if this corner's x/y/z values are
// less than those previously tested
if( Corner.x < Min.x )
Min.x = Corner.x;

if( Corner.y < Min.y )
Min.y = Corner.y;

if( Corner.z < Min.z )
Min.z = Corner.z;

// Determine if this corner's x/y/z values are
// greater than those previously tested
if( Corner.x > Max.x )
Max.x = Corner.x;

if( Corner.y > Max.y )
Max.y = Corner.y;

if( Corner.z > Max.z )
Max.z = Corner.z;
}

// return the Min and Max values, in world coordinates
return [ Min + Pos, Max + Pos ];
}
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
04-26-2007 09:54
Close, Lee:

vector in world coord = vector in my coord * my rotation + my position

vector in my coord = ( vector in world coord - my position ) / my rotation
Ave Amat
Love Liberty
Join date: 21 Mar 2007
Posts: 10
04-26-2007 23:46
Ok - I've done it! Thanks everyone for your input. Heres the guts of the method. I know I could use loops and lists to make it more concise, but I'm happy.

CODE
   

//properties of detected object -
key k = llDetectedKey(i);
vector pos = llDetectedPos(i);
rotation rot = llDetectedRot(i);
list bb = llGetBoundingBox(k);
vector min = llList2Vector(bb, 0); // min corner
vector max = llList2Vector(bb, 1); // max corner

//the four corners of the south (min x) face (clockwise)
//local relative to bb root
vector vC_1 = < min.x, min.y, min.z >; //bot left
vector vC_2 = < min.x, min.y, max.z >; //top left
vector vC_3 = < min.x, max.y, max.z >; //top right
vector vC_4 = < min.x, max.y, min.z >; //bot right
// north (max x) face
vector vC_5 = < max.x, min.y, min.z >; //bot left
vector vC_6 = < max.x, min.y, max.z >; //top left
vector vC_7 = < max.x, max.y, max.z >; //top right
vector vC_8 = < max.x, max.y, min.z >; //bot right

//rotate
vC_1 *= rot; vC_2 *= rot; vC_3 *= rot; vC_4 *= rot;
vC_5 *= rot; vC_6 *= rot; vC_7 *= rot; vC_8 *= rot;
//new region coords TADAAAAH!
vC_1 += pos; vC_2 += pos; vC_3 += pos; vC_4 += pos;
vC_5 += pos; vC_6 += pos; vC_7 += pos; vC_8 += pos;

//#DEBUG rez a small temp phantom prim at each corner
llRezObject("corner", vC_1, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_2, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_3, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_4, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_5, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_6, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_7, ZERO_VECTOR, ZERO_ROTATION, 0);
llRezObject("corner", vC_8, ZERO_VECTOR, ZERO_ROTATION, 0);


I've now discovered the interesting behaviour of sensors when you try to combine type flags. Did someone actually get paid to create these (mal)functions? Or is this another 'clever' way to throttle us.
_____________________
Love Liberty