Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- integer max_sub_branch = 3; //How many sub branches?
- float max_sub_angle = 135.0; //Highest allowed angle
- integer max_size = 3; //Steps
- float branch_length = .5; //Longest length (base)
- makeBranch(vector start, float length, vector rot, integer size)
- {
- if (size > 0) //The key controller, size diminishes and so this will eventually stop our insane recursive function calling.
- {
- vector top = <0,0,(length / 2)> * llEuler2Rot(rot * DEG_TO_RAD); //Where is the top going to be?
- vector pos = start + top; //The actual position of the branch.
- //Multiply by 1000000 as to convert to integer without loss of precision.
- llRezObject("branch", pos, ZERO_VECTOR, llEuler2Rot(rot * DEG_TO_RAD), llRound((length * 1000000)));
- float sub_branch = llFrand(max_sub_branch - 1) + 2; //Calculate how many sub branches there will be.
- float branch_length_dimin = .5 + llFrand(.5); //Diminish randomly, but will always be diminished
- integer i;
- for(i = 0; i < sub_branch; ++i) //Create the sub branches based on how many there will be.
- {
- float newLength = length * branch_length_dimin; //Diminish the length
- vector newRot; //Calculate rotations
- newRot.x = rot.x + llFrand(max_sub_angle) - (max_sub_angle / 2);
- newRot.y = rot.y + llFrand(max_sub_angle) - (max_sub_angle / 2);
- newRot.z = rot.z + llFrand(max_sub_angle) - (max_sub_angle / 2);
- integer newSize = size - 1; //Decrement size, we don't want this rezzing forever, do we?
- makeBranch(pos + top, newLength, newRot, newSize); //Call this function again until finished
- / //Note: Recursive calling of a function is dangerous, but it seemed like a good idea at the time so...
- }
- }
- else
- {
- vector top = <0,0,(length / 4)> * llEuler2Rot(rot * DEG_TO_RAD); //Where is the top going to be?
- vector pos = start + top; //The actual position of the branch.
- llRezObject("leaf", pos, ZERO_VECTOR, llEuler2Rot(rot * DEG_TO_RAD), llRound(((length / 1.25) * 1000000 )));
- }
- }
- default
- {
- touch_start(integer num)
- {
- if(llDetectedKey(0) == llGetOwner())
- {
- makeBranch(llGetPos(), branch_length, <0,0,0>, max_size); //Start it up, we must be MAD!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement