12 September 2011

B is for Bounding Box: Alphabet Game

Bounding box

How tall is your avatar? If you script, you know that while llGetAgentSize() claims to tell you, it isn't as accurate as getting the avatar's bounding box with llGetBoundingBox().

I am very amused that there's no way via script to guesstimate how thin or fat an avatar is. llGetMass(), llGetAgentSize(), and llGetBoundingBox() all assume default values for an avatar's x and y dimensions, and so any variation in their results is based entirely on the height of the avatar.

Add the following script to a prim and touch it to see how tall your avatar is.


default
{
    touch_start(integer total_number)
    {
        key avatar = llDetectedKey(0);
        string name   = llDetectedName(0); 
        list BB  = llGetBoundingBox( avatar );
        vector size =  llList2Vector(BB,1) - llList2Vector(BB,0);
       
        integer feet = llFloor( size.z * 3.28084 );
        integer inches = llRound( (size.z * 39.37008)  - (feet*12 ));
       
        string meters = (string)size.z + " meters";
        string us = (string)feet + " feet " + (string)inches + " inches";

        llSay( 0, name + ", counting your shoes you are " + meters + 

                 " or " + us + " tall."); 
    }
}

No comments: