Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer max_sub_branch = 3;     //How many sub branches?
  2. float max_sub_angle = 135.0;    //Highest allowed angle
  3. integer max_size = 3;           //Steps
  4. float branch_length = .5;      //Longest length (base)
  5.  
  6. makeBranch(vector start, float length, vector rot, integer size)
  7. {
  8.     if (size > 0) //The key controller, size diminishes and so this will eventually stop our insane recursive function calling.
  9.     {
  10.         vector top = <0,0,(length / 2)> * llEuler2Rot(rot * DEG_TO_RAD); //Where is the top going to be?
  11.         vector pos = start + top; //The actual position of the branch.
  12.         //Multiply by 1000000 as to convert to integer without loss of precision.
  13.         llRezObject("branch", pos, ZERO_VECTOR, llEuler2Rot(rot * DEG_TO_RAD), llRound((length * 1000000)));
  14.         float sub_branch = llFrand(max_sub_branch - 1) + 2; //Calculate how many sub branches there will be.
  15.         float branch_length_dimin = .5 + llFrand(.5); //Diminish randomly, but will always be diminished
  16.         integer i;
  17.         for(i = 0; i < sub_branch; ++i) //Create the sub branches based on how many there will be.
  18.         {
  19.             float newLength = length * branch_length_dimin; //Diminish the length
  20.             vector newRot; //Calculate rotations
  21.             newRot.x = rot.x + llFrand(max_sub_angle) - (max_sub_angle / 2);
  22.             newRot.y = rot.y + llFrand(max_sub_angle) - (max_sub_angle / 2);
  23.             newRot.z = rot.z + llFrand(max_sub_angle) - (max_sub_angle / 2);
  24.             integer newSize = size - 1; //Decrement size, we don't want this rezzing forever, do we?
  25.             makeBranch(pos + top, newLength, newRot, newSize); //Call this function again until finished
  26.            
  27. /            //Note: Recursive calling of a function is dangerous, but it seemed like a good idea at the time so...
  28.         }
  29.     }
  30.     else
  31.     {
  32.         vector top = <0,0,(length / 4)> * llEuler2Rot(rot * DEG_TO_RAD); //Where is the top going to be?
  33.         vector pos = start + top; //The actual position of the branch.
  34.         llRezObject("leaf", pos, ZERO_VECTOR, llEuler2Rot(rot * DEG_TO_RAD), llRound(((length / 1.25) * 1000000 )));
  35.     }
  36. }
  37.  
  38. default
  39. {
  40.     touch_start(integer num)
  41.     {
  42.         if(llDetectedKey(0) == llGetOwner())
  43.         {
  44.             makeBranch(llGetPos(), branch_length, <0,0,0>, max_size); //Start it up, we must be MAD!
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement