Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Prim thickness in whatever the vertical direction is

Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
05-25-2009 11:48
I started fiddling with a simple question in another forum this morning, trying to come up with an answer that I could script to satisfy a general case .... and have found myself running around in tight mental circles.

If I rez a new prim, stretch it manually at random, and then want to know what its thickness in the vertical dimension is, all I have to do is write

CODE

vector Big = llGetScale();
float VertThick = Big.z;


If I rotate the prim manually so that its +X axis points straight up, I have to look for Big.x instead. That's easy. Suppose, though, that I turn my back while some other person rotates the prim manually in a random way so that I have no idea which end of the prim is up. It might be +Y or -X or, more likely, some totally unknown direction. How do I calculate the thickness in whatever that vertical direction is?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-25-2009 11:54
eek, that is a very puzzling one, i know about making an axis point up, but i have no idea how to figure out which one is
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
05-25-2009 15:19
From: Ruthven Willenov
eek, that is a very puzzling one, i know about making an axis point up, but i have no idea how to figure out which one is


I was afraid of that. Actually, I'd be happy with a solution that's short of the general case (where the "up" direction is a random vector) and settle for being able to tell whether it's +Z, -Z, +X, -X, +Y, or -Y that's up. That should make the prim thickness problem LOTS simpler, since it wouldn't involve calculating anything. I've been poking at this for hours .... well, OK, not continuously .... and can think of ways to do it by interacting with the prim (using llDetectedTouchFace, for example), but I still can't come up with a way for a script to determine "up" by itself. :(
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
05-25-2009 15:45
For a box (bounding box or whatever) I state without a proof that this routine does the trick:)
CODE

// Dora Gustafson, Studio Dora 2009
// thickness of box, any dimensions and any rotation

float thickness( vector dimensions, rotation rot )
{
vector A = < dimensions.x, dimensions.y, dimensions.z >*rot;
vector B = < -dimensions.x, dimensions.y, dimensions.z >*rot;
vector C = < dimensions.x, -dimensions.y, dimensions.z >*rot;
vector D = < -dimensions.x, -dimensions.y, dimensions.z >*rot;
float t = llFabs( A.z );
if ( llFabs( B.z )>t ) t = llFabs( B.z );
if ( llFabs( C.z )>t ) t = llFabs( C.z );
if ( llFabs( D.z )>t ) t = llFabs( D.z );
return t;
}

default
{
state_entry()
{
llOwnerSay("Thickness = "+(string)thickness( llGetScale(), llGetRot()));
}

touch_end(integer n)
{
llOwnerSay("Thickness = "+(string)thickness( llGetScale(), llGetRot()));
}
}
_____________________
From Studio Dora
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-25-2009 17:34
Here's how you can figure out which of the primary axes points most upward:

CODE

rotation rot = llGetRot();
vector fwd = llRot2Fwd(rot);
vector left = llRot2Left(rot);
vector up = llRot2Up(rot);
float fwdZAbs = llAbs(fwd.z);
float leftZAbs = llAbs(left.z);
float upZAbs = llAbs(up.z);
if (fwdZAbs > leftZAbs)
{
if (fwdZAbs > upZAbs)
{
if (fwd.z > 0.0)
{
// +x axis
} else
{
// -x axis
}
} else
{
if (up.z > 0.0)
{
// +z axis
} else
{
// -z axis
}
}
} else if (leftZAbs > upZAbs)
{
if (left.z > 0.0)
{
// +y axis
} else
{
// -y axis
}
} else
{
if (up.z > 0.0)
{
// +z axis
} else
{
// +z axis
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-25-2009 18:03
so you want the global z size? and are you realizing that might not be a nice neat rotation? or that cuts and different shapes will change that apparent vertical space?

that means calculating all possible points, as offset from the center, rotating all those offsets, and checking the z components for highest and lowest values.

if you eliminate odd rotations an other things like cuts, the process is dead simply
test = llGetScale() * llGetRot();
answer = test.z

@Dora,
interesting solution, only the cross corner cords for a rectilinear solid.
EDITED: to avoid confusion.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
05-25-2009 21:02
Dora,
I started down the path you used and got lost. Your solution is beautiful. I've been testing it out for the past half hour with a variety of simple prims and it seems to work quite nicely. Now I need to take time to digest exactly HOW it works. ;)

Void,
Yes, of course you are right. I didn't have in mind the truly general case of a prim that has been mangled and twisted. Doing that exercise really would require dealing with offsets and doing a mess of calculation.

Hewee,
Thanks for the logical framework. It helps me visualize the geometry better.

As I said at the top of this thread, I started fiddling with this because I got sucked in by a trivial question on another forum and started wondering how to generalize my quick answer. I love a good puzzle, but I'm smart enough to know when I've reached my limits of understanding. Thanks, Dora, Hewee and Void, for helping me learn something from this one. :)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-25-2009 23:47
eh I screwd up, Dora's solution is just fine, I was reading the wrong numbers / cords (<-x,-y,z> is equivalent to <x,y,-z> for this, they are the opposing corners).

it works by setting up cross corner cords of the proper magnitude, treating 0 as the center.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Basement Desade
Registered User
Join date: 14 Jul 2006
Posts: 91
True statement
06-01-2009 22:10
From: Dora Gustafson
For a box (bounding box or whatever) I state without a proof that this routine does the trick:)


I tried it, it works. I changed the message to "Vertical Thickness" just so I don't get confused the next time I drag it out. :)