Friday, February 26, 2010

Pyramid Script

The pyramids of ancient Egypt have fascinated mankind for millenia, and quite often find themselves replicated in some manner in Second Life.  However, most people who create them don't give their pyramid geometrically accurate dimensions.  An Egyptian pyramid's slopes run at a 52 degree angle, whereas most would make it at a 45 degree angle.  However, using this small script, you can turn any prim into a geometrically-accurate pyramid:

//Converts any prim into a geometrically-correct pyramid with slopes at a 52 degree angle, the same as the pyramids of egypt.
//Written by Zauber Exonar
//Special thanks to Aamira Aeon for helping with the geometry

default {
    state_entry() {
        vector scale = llGetScale();
        //Making sure the base is square
        if(scale.x != scale.y) {
            if(scale.x > scale.y) scale.y = scale.x;
            if(scale.x < scale.y) scale.x = scale.y;
        //calculating the height of the pyramid
        scale.z = llTan(DEG_TO_RAD * 52) * (scale.x / 2);
        //calculating the position so that the pyramid's bottom stays at the same elevation
        vector pos = llGetPos();
        pos.z = pos.z + (scale.z / 2.0);
        //setting primitive parameters for turning the prim into a tapered cube
        list params = [PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <0.0, 0.0, 0.0>, <0.0, 0.0, 0.0>];
        //Applying changes to the prim
        llSetPrimitiveParams(params + [PRIM_SIZE, scale, PRIM_POSITION, pos]);
        //Removing the script from inventory

You can view the script better here:

1 comment:

  1. wow, what a neat script! just even thinking of making such a script shows serious thinking outside the box (pyramid in this case)

    i, for one, will try out this script and appreciate the coding exercise you guys did to create this! (yes,i am nerdy) =)