inclinedplanescript

This script is the primary script for the Inclined Plane. It should be placed inside of the root prim, and it should be a simple box prim. The script will actually modify the prim's attributes for you, so you don't have to fuss with the taper and other settings to get the inclined plane.

Return to the main Inclined Plane page

code format="lsl2" //Written by Jeff Mao //Distributed under a Creative Commons Attribution 3.0 license [CC-BY](http://creativecommons.org/licenses/by/3.0/) //If you have questions about this, please feel free to contact me at jmao@mac.com. //Please share alterations, improvements, lesson plans related to this simulation, etc.

//v0.2 - first working prototype //v0.3 - cleaned out error captures and added some interface elements //v0.4 - added adjustments so that the control prims stay at the bottom near the end of the ramp //v0.4.1 - bug fixes - SL is stricter with syntax than OpenSim apparently :)

//setup variables string object = "Ball"; //name of object inside inclined plane prim to roll down the plane integer tracermax = 5; //max number of tracers to rez integer listen_handle;

drop {       //determine dimensions vector size = llGetScale; llSay(0, "My dimensions are: " + (string)size);

//determine location vector position = llGetPos;

float posx = position.x;       float posy = position.y;        float posz = position.z;        llSay(0, "The Inclined Plane's position is -- x: "+ (string)posx + " y: " + (string)posy + " z: " + (string)posz);

//determine start location float startx = posx - (size.x*0.5)+.05; llSay(0,"The Ball's starting x position: " + (string) startx); float startz = posz + (size.z*0.5)+0.25; llSay(0,"The Balls's starting z position (elevation): " + (string) startz); vector startpos = ; //rez ball at start location llRezAtRoot(object, startpos, <0,0,0>, llEuler2Rot(<0,0,0>),tracermax); llListenRemove(listen_handle); }

default {   state_entry {       llSay(0, "Inclined Plane Ready"); //reset rotation and shear llSetRot(llEuler2Rot(<0,0,0>)); llSetPrimitiveParams([PRIM_TYPE,                           PRIM_TYPE_BOX,                            PRIM_HOLE_DEFAULT,  // hole_shape                            <0.00, 1.0, 0.0>,   // cut                            0.0,                // hollow                            <0.0, 0.0, 0.0>,    // twist                            <0.0, 1.0, 0.0>,    // top_size                            <-0.5, 0.0, 0.0>     // top_Shear                            ]);

}

touch_start(integer count) {      //determine dimensions vector size = llGetScale; llSay(0, "My dimensions are: " + (string)size);

//determine location vector position = llGetPos;

float posx = position.x;       float posy = position.y;        float posz = position.z;        llSay(0, "The Inclined Plane's position is -- x: "+ (string)posx + " y: " + (string)posy + " z: " + (string)posz); llSay(0, "Use the control buttons to drop the ball or adjust the inclined plan");

}

link_message( integer sender_num, integer num, string str, key id) {       if (str == "X") {           listen_handle = llListen(1, "", llGetOwner, ""); vector size = llGetScale; llSay(0, "My dimensions are : " + (string)size); llSay(0,"Please chat length of base in meters on channel /1"); }

if (str == "Z") {           listen_handle = llListen(2, "", llGetOwner, ""); vector size = llGetScale; llSay(0, "My dimensions are : " + (string)size); llSay(0,"Please chat height in meters on channel /2"); }

if (str == "Angle") {           listen_handle = llListen(3, "", llGetOwner, ""); vector size = llGetScale; float theta = llAtan2(size.z,size.x)*RAD_TO_DEG; llSay(0, "My dimensions are : " + (string)size + " and the angle is: "+ (string)theta+" degrees."); llSay(0,"Please chat angle in degrees on channel /3"); }       if (str == "Drop") {           drop; }   }     listen( integer channel, string name, key id, string message ) {       if (channel==1) {               float xx = (float)message; vector size = llGetScale; float cc = llSqrt(llPow(size.z,2)+llPow(xx,2)); //calculate hypotenuse length

if (cc>=19) //make sure user entry won't make a triangle too big for rezatroot {                   xx = size.x;                    llSay(0,"Sorry, that won't work here. Hypotenuse length cannot exceed 20m"); }

//adjust position to keep the end of ramp in the same place vector position = llGetPos; float newxpos = position.x+(0.5*((float)size.x-xx)); llSetPos();

//center buttons back to base float adjXby = 0.5*((float)size.x-xx); llMessageLinked(LINK_ALL_CHILDREN, 1, (string)adjXby, NULL_KEY);

//set triangle with user's base length input llSetPrimitiveParams([PRIM_SIZE,]); llListenRemove(listen_handle);

}       if (channel==2) {               float zz = (float)message; vector size = llGetScale; float cc = llSqrt(llPow(size.x,2)+llPow(zz,2)); //calculate hypotenuse length

if (cc>=19) //make sure user entry won't make a triangle too big for rezatroot {                   zz = size.z;                    llSay(0,"Sorry, that's too big. Hypotenuse length cannot exceed 20m"); }

//adjust position to keep the end of ramp in the same place vector position = llGetPos; float newzpos = position.z-(0.5*((float)size.z-zz)); llSetPos();

//set triangle with user's height input llSetPrimitiveParams([PRIM_SIZE,<(float)size.x, 1, zz>]); llListenRemove(listen_handle);

//move buttons back to base float adjZby = 0.5*((float)size.z-zz); llMessageLinked(LINK_ALL_CHILDREN, 2, (string)adjZby, NULL_KEY); }       if (channel==3) {               //tan(angle)*x = z                float theta = (float)message * DEG_TO_RAD; //convert user entry into radians vector size = llGetScale; float zz = llTan(theta)*size.x; //calculate "side opposite" using current base length float cc = llSqrt(llPow(size.x,2)+llPow(zz,2));//calculate hypotenuse length

if (theta>=(PI/2) || theta<=0) //make sure user entry is between 0 and 90 {                   zz = llAtan2(size.y,size.x)*RAD_TO_DEG; llSay(0,"Sorry, please use a value between 0 and 90"); }               if (cc>=19) //make sure user entry doesn't create a triangle too large for the rezatroot command {                   zz = size.z;                    llSay(0,"Sorry, that's too big. Hypotenuse length cannot exceed 20m"); }

//adjust position to keep the end of the ramp in the same place vector position = llGetPos; float newypos = position.z-(0.5*((float)size.z-zz)); llSetPos();

//set triangle with the user's angle input llSetPrimitiveParams([PRIM_SIZE,<(float)size.x, 1, zz>]); llListenRemove(listen_handle);

//move buttons back to base float adjZby = 0.5*((float)size.z-zz); llMessageLinked(LINK_ALL_CHILDREN, 2, (string)adjZby, NULL_KEY); }       } } code