Difference between revisions of "Talk:Hierarchics"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 3: Line 3:
It's a good script but the rotation code leaves much to be desired. If the user specifies in the objects description that it should have a zero rotation, the script currently ignores it. Additionally it forces the user to use Euler notation. You need something like the following, it allows the user to supply either a quaternion on Euler.
It's a good script but the rotation code leaves much to be desired. If the user specifies in the objects description that it should have a zero rotation, the script currently ignores it. Additionally it forces the user to use Euler notation. You need something like the following, it allows the user to supply either a quaternion on Euler.
<lsl>
<lsl>
//Creator: Strife Onizuka
//http://creativecommons.org/licenses/by-sa/3.0/
rotation AngleString2Rot(string in, rotation bad){
rotation AngleString2Rot(string in, rotation bad){
     //we test if it is an angle type we can use by:
     //we test if it is an angle type we can use by:
Line 19: Line 22:
     //if it passes, we know the result should be ZERO_ROTATION
     //if it passes, we know the result should be ZERO_ROTATION
     integer index = llSubStringIndex(in, "<");
     integer index = llSubStringIndex(in, "<");
     if(~index)
     if(~index) {
    {
         //we insert a negative sign  
         //we insert a negative sign  
         //but we have to remove spaces or they will cause problems
         //but we have to remove spaces or they will cause problems
Line 34: Line 36:
     }
     }
     return bad;
     return bad;
}
}//Strife Onizuka 2009, cc-by-sa 3.0
 
//Less verbose
rotation AngleString2Rot(string in, rotation bad){
    rotation r = (rotation)in;
    if(r)//it's a rotation!
        return r;
 
    vector v = (vector)in;
    if(v)// it's not a rotation but it is a vector
        return llEuler2Rot(v * DEG_TO_RAD);
 
    integer index = llSubStringIndex(in, "<");
    if(~index) {//"<" was found, now insert "-"
        in = llGetSubString(in, 0, index) + "-" +
            llStringTrim(llDeleteSubString(in, 0, index), STRING_TRIM_HEAD);
        if((string)((vector)in) != (string)v)
            return r;
    }
    return bad;
}//Strife Onizuka 2009, cc-by-sa 3.0
</lsl>
</lsl>
-- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 20:46, 6 May 2009 (UTC)
-- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 20:46, 6 May 2009 (UTC)

Revision as of 13:59, 6 May 2009

Default Rotation etc

It's a good script but the rotation code leaves much to be desired. If the user specifies in the objects description that it should have a zero rotation, the script currently ignores it. Additionally it forces the user to use Euler notation. You need something like the following, it allows the user to supply either a quaternion on Euler. <lsl> //Creator: Strife Onizuka //http://creativecommons.org/licenses/by-sa/3.0/

rotation AngleString2Rot(string in, rotation bad){

   //we test if it is an angle type we can use by:
   //1) parse input and see if it has a value
   //2) flip the sign of an element and test again.
   rotation r = (rotation)in;
   if(r)//it's a rotation (or something greater)
       return r;//by greater it might be <x,y,z,s,...>
   vector v = (vector)in;
   if(v)// it's not a rotation but it is a vector
       return llEuler2Rot(v * DEG_TO_RAD);
   //now it's either default or invalid
   //to determine which, we modify the input string and test agian
   //if it passes, we know the result should be ZERO_ROTATION
   integer index = llSubStringIndex(in, "<");
   if(~index) {
       //we insert a negative sign 
       //but we have to remove spaces or they will cause problems
       //we don't care about negative negative zero because
       //breaking the parse is an indication that it did parse.
       in = llGetSubString(in, 0, index) + "-" + 
           llStringTrim(llDeleteSubString(in, 0, index), STRING_TRIM_HEAD);
       if((string)((vector)in) != (string)v)
           return r; 
       //r is Identity but could have negative zero's, waste not want not.
       //the user specified them, we should preserve them.
   }
   return bad;

}//Strife Onizuka 2009, cc-by-sa 3.0

//Less verbose rotation AngleString2Rot(string in, rotation bad){

   rotation r = (rotation)in;
   if(r)//it's a rotation!
       return r;
   vector v = (vector)in;
   if(v)// it's not a rotation but it is a vector
       return llEuler2Rot(v * DEG_TO_RAD);
   integer index = llSubStringIndex(in, "<");
   if(~index) {//"<" was found, now insert "-"
       in = llGetSubString(in, 0, index) + "-" + 
           llStringTrim(llDeleteSubString(in, 0, index), STRING_TRIM_HEAD);
       if((string)((vector)in) != (string)v)
           return r; 
   }
   return bad;

}//Strife Onizuka 2009, cc-by-sa 3.0 </lsl> -- Strife (talk|contribs) 20:46, 6 May 2009 (UTC)