Difference between revisions of "User:Lum Pfohl/LSL Goodies/LoopRez v0.6 Lum Mods"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {| width="100%" |- |valign="top"| <div id="box"> ==LoopRez v0.6 Lum Mods== <div style="padding: 0.5em"> This is a posting of Ged Larsen's '''LoopRez v0.6''' script. I have modified it sli...)
 
(cleaned up the math)
Line 6: Line 6:
<div style="padding: 0.5em">
<div style="padding: 0.5em">
This is a posting of Ged Larsen's '''LoopRez v0.6''' script.  I have modified it slightly so that it automatically rezzes a root prim of the correct orientation.
This is a posting of Ged Larsen's '''LoopRez v0.6''' script.  I have modified it slightly so that it automatically rezzes a root prim of the correct orientation.
<pre>
<lsl>////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// LoopRez v0.6, by Ged Larsen, 20 December 2006
// LoopRez v0.6, by Ged Larsen, 20 December 2006
// Strife Onizuka was here in 2008
//
//
// - rez a number of objects in an ellipse, whose size is determined by xRadius and yRadius
// - rez a number of objects in an ellipse, whose size is determined by xRadius and yRadius
Line 52: Line 52:
makeLoop()
makeLoop()
{
{
     integer n;                           // which object is being placed
     integer n = 0;                     // which object is being placed
     float theta;                       // angle in radians
     float cos;                         // cosine of the angle
     vector pos;                           // position
    float sin;                          // sine of the angle
     rotation rot;                       // rotation in quaternion format
     vector pos;                         // position
     rotation rot;                       // rotation in quaternion format


     vector rezzerPos = llGetPos();
     vector rezzerPos = llGetPos();
     vector rootPrimPos = rezzerPos + posOffset + <0.0, 0.0, 0.5>;
     vector rootPrimPos = rezzerPos + posOffset + <0.0, 0.0, 0.5>;
      
     float s = TWO_PI / numObjects;
 
    for(n = 0; n < numObjects; n++) {


        theta = TWO_PI * ( (float)n / (float)numObjects );
    for(; n < numObjects; ++n) {
         pos.x = xRadius * llCos(theta);                           // ellipse: 2x xRadius meters wide
         cos = llCos(s * n);
         pos.y = yRadius * llSin(theta);                            // ellipse: 2x yRadius meters wide
         sin = llSin(s * n);
        pos.z = -bendCoefficient*llCos(theta)*llCos(theta);        // saddle shape, bending downwards on X-axis
        pos = pos + rezzerPos + posOffset;


         rot = llEuler2Rot(<rotOffset.x*DEG_TO_RAD, rotOffset.y*DEG_TO_RAD, rotOffset.z*DEG_TO_RAD>);    // user-chosen rotation offset correction
         //x = ellipse: 2x xRadius meters wide
         rot = rot * llEuler2Rot(<0, -1*flareAngle*DEG_TO_RAD, 0>);                                       // flare generation (poof)
        //y = ellipse: 2x yRadius meters wide
        //z = saddle shape, bending downwards on X-axis
         pos = <xRadius * cos, yRadius * sin, -bendCoefficient * cos * cos> +
              rezzerPos +
              posOffset;  


        // user-chosen rotation offset correction
        // flare generation (poof)
         // the following make the objects face outwards properly for an ellipse; using theta alone is only correct for a circle
         // the following make the objects face outwards properly for an ellipse; using theta alone is only correct for a circle
        // the scary formula calculates a unit vector TANGENTIAL to the ellipse, and llRotBetween is used to figure out how much the object needs to rotate to lie parallel to the tangent
         rot = llEuler2Rot(rotOffset * DEG_TO_RAD) *
         rot = rot * llRotBetween(<0.0,1.0,0.0>, <-1.0 * xRadius * llSin(theta) / ( llSqrt ( (yRadius*yRadius * llCos(theta) * llCos(theta)) + (xRadius*xRadius * llSin(theta) * llSin(theta))) ),yRadius * llCos(theta) / ( llSqrt ( (yRadius*yRadius * llCos(theta) * llCos(theta)) + (xRadius*xRadius * llSin(theta) * llSin(theta))) ),0.0>);
              llEuler2Rot(<0, -flareAngle * DEG_TO_RAD, 0>) *  
        if ( n== (numObjects/2) )        // LSL's implementation of llRotBetween at theta = pi radians is reversed at 180 degrees, so this manually corrects it
              llRotBetween(<1.0,0.0,0.0>, <yRadius * cos, xRadius * sin, 0.0>);
            rot = rot * llEuler2Rot( <0,PI,0> );


         llRezObject(objectName, pos, ZERO_VECTOR, rot, 0);
         llRezObject(objectName, pos, ZERO_VECTOR, rot, n);
     }
     }
   
      
      
     // My dresses always use a root prim at the center of the circle/ellipse.
     // My dresses always use a root prim at the center of the circle/ellipse.
Line 98: Line 99:
         }
         }
     }
     }
}
}</lsl>
 
</pre>
</div>
</div>
</div>
</div>

Revision as of 07:39, 3 February 2008

LoopRez v0.6 Lum Mods

This is a posting of Ged Larsen's LoopRez v0.6 script. I have modified it slightly so that it automatically rezzes a root prim of the correct orientation. <lsl>//////////////////////////////////////////////////////////////////////////////// // LoopRez v0.6, by Ged Larsen, 20 December 2006 // Strife Onizuka was here in 2008 // // - rez a number of objects in an ellipse, whose size is determined by xRadius and yRadius // - all facing "outwards", along a tangent to the ellipse // - can set how much the objects flare outwards // - properly handles object rotation corrections (for example, X-axis 180 degree rotation helps for flexi-prim skirts) // - can also get a 'saddle' bend, to generate a bend that might help for necklaces (from Ariane Brodie) // // To use: // 1) create a prim that will contain this script and the object to use // 2) put the script into the prim // 3) create an object that will be used, and name it "Object" // 4) put "Object" into the prim containing the script, by dragging it from your inventory // 5) get out of Edit Mode, and touch the prim // // Random note: // - this version does NOT insure equal spacing of objects along the perimeter of the ellipse // - i.e., objects "bunch up" at the long ends of an ellipse; the effect should be acceptable for non-extreme ellipses // - even spacing of objects can be accomplished, but requires simulation of integral calculus, which slows down the script // // References: // - tangent formulas from: http://mathworld.wolfram.com/Ellipse.html


//////////////////////////////////////////////////////////////////////////////// // CONFIGURATION PARAMETERS, change these to your liking

string objectName = "My Skirt Prim"; // object to use; will need to be in the inventory of the prim containing this script string rootPrimName = "Root Prim (Rename Me)"; // root prim that will appear at center of dress integer numObjects = 16 ; // how many objects float xRadius = .72; // ellipse x-axis radius in meters float yRadius = .72; // ellipse y-axis radius in meters float flareAngle = 70.0; // how many DEGREES the bottom of object will flare outwards, the "poof" factor float bendCoefficient = 0.0; // makes a "saddle shape", bends DOWN this number of meters at extremes of X-axis vector rotOffset = <0.0, 180.0, 0.0>; // rotation offset in DEGREES -- fixes the rotation of ALL objects; for flexi prims, often you will want <180.0, 0.0, 0.0> vector posOffset = <0.0, 0.0, 1.0>; // position offset


//////////////////////////////////////////////////////////////////////////////// // No need to mess with anything below here

makeLoop() {

   integer n = 0;                      // which object is being placed
   float cos;                          // cosine of the angle
   float sin;                          // sine of the angle
   vector pos;                         // position
   rotation rot;                       // rotation in quaternion format
   vector rezzerPos = llGetPos();
   vector rootPrimPos = rezzerPos + posOffset + <0.0, 0.0, 0.5>;
   float s = TWO_PI / numObjects;
   for(; n < numObjects; ++n) {
       cos = llCos(s * n);
       sin = llSin(s * n);
       //x = ellipse: 2x xRadius meters wide
       //y = ellipse: 2x yRadius meters wide
       //z = saddle shape, bending downwards on X-axis
       pos = <xRadius * cos, yRadius * sin, -bendCoefficient * cos * cos> + 
             rezzerPos + 
             posOffset; 
       // user-chosen rotation offset correction
       // flare generation (poof)
       // the following make the objects face outwards properly for an ellipse; using theta alone is only correct for a circle
       rot = llEuler2Rot(rotOffset * DEG_TO_RAD) * 
             llEuler2Rot(<0, -flareAngle * DEG_TO_RAD, 0>) * 
             llRotBetween(<1.0,0.0,0.0>, <yRadius * cos, xRadius * sin, 0.0>);
       llRezObject(objectName, pos, ZERO_VECTOR, rot, n);
   }
   
   // My dresses always use a root prim at the center of the circle/ellipse.
   // Rather than copying the rezzer, deleting objects and scripts inside and renaming it, I
   // am going to rez a root prim specifically designed for this purpose, at or around the corect
   // height, centered in the skirt.  
   llRezObject(rootPrimName, rootPrimPos, ZERO_VECTOR, ZERO_ROTATION, 0);

}

default {

   touch_start(integer total_number)
   {
       if (llDetectedOwner(0) == llGetOwner())
       {
           makeLoop();
       }
   }

}</lsl>

Lum Pfohl 20:23, 13 December 2007 (PST)

Lum's Quick Links
LumSelfPortrait.jpg
Click to Enlarge


Related topics

edit