Advertisement
Guest User

Untitled

a guest
Jan 5th, 2012
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vector initPOS;
  2. rotation initROT;
  3. list positions=[];
  4. list rotations=[];
  5. list motionPath;
  6. integer iframe=0;
  7.  
  8. menu(){
  9.     llDialog(llGetOwner(),"Choose",["HELP","ADDFRAME","DELFRAME","RESTART","SCRIPT","PLAY","|<<",">>|","STOP","<",">" ],-1);
  10. }
  11. vector lastPOS()
  12. {
  13.   vector pos=initPOS;
  14.   integer i;
  15.   for(i=0;i<iframe;i++) pos+=llList2Vector(positions,iframe-1);
  16.   return pos;
  17. }
  18. rotation lastROT()
  19. {
  20.     rotation rot=initROT;
  21.   integer i;
  22.   for(i=0;i<iframe;i++) rot*=llList2Rot(rotations,iframe-1);
  23.   return rot;
  24.  
  25. }
  26. goFrame()
  27. {
  28.     integer l=llGetListLength(positions);
  29.     llSay(0,"You are at frame #"+(string)iframe);
  30.     if(iframe==0)
  31.     {
  32.         warpPosRot(initPOS,initROT);
  33.         return;
  34.     }
  35.     warpPosRot(llList2Vector(positions,iframe-1), llList2Rot(rotations,iframe-1));
  36. }
  37. addFrame(vector pos, rotation rot)
  38. {
  39.     iframe++;
  40.     // removing frame at pos iframe
  41.     if(iframe>llGetListLength(positions)){
  42.         positions+=[pos];
  43.         rotations+=[rot];
  44.         return;
  45.     }
  46.     positions=llListReplaceList(positions,[pos],iframe-1,iframe-1);
  47.     rotations=llListReplaceList(rotations,[rot],iframe-1,iframe-1);
  48.    
  49. }
  50. removeFrame()
  51. {
  52.     iframe--;
  53.     integer l=llGetListLength(positions);
  54.     if(iframe>=l)
  55.     {
  56.        
  57.         if(l<=1){ positions=[]; rotations=[]; return;}
  58.        
  59.         // remove last position
  60.         positions=llDeleteSubList(positions,-1,-1);
  61.         rotations=llDeleteSubList(rotations,-1,-1);        
  62.         return;
  63.     }
  64.     // removing intermediate frame
  65.     positions=llDeleteSubList(positions,iframe,iframe);
  66.    
  67. }
  68. warpPosRot(vector pos, rotation rot)
  69. {
  70.     llSay(0,"warping to "+(string)pos);
  71.     // loop to move the prim at initial destination
  72.     while(llVecDist(llGetPos(),pos)>0.01)
  73.         llSetLinkPrimitiveParamsFast(1, [ PRIM_POSITION, pos, PRIM_ROTATION, rot ]);
  74.  
  75. }
  76. getMotionPath()
  77. {
  78.     motionPath=[];
  79.     integer i; vector lastp=initPOS; rotation lastr=initROT;
  80.     for(i=0;i<llGetListLength(positions);i++)
  81.     {
  82.         vector curp=llList2Vector(positions,i);
  83.         rotation curr=llList2Rot(rotations,i);
  84.         vector diffp=curp-lastp;
  85.         rotation diffr=curr/lastr;
  86.         float dist= llVecMag(diffp);
  87.         // try to force length in seconds proportional to actual meters
  88.         if (dist<1) dist=1;
  89.         motionPath+=[ diffp, diffr, dist*0.1 ];
  90.         lastp=curp;
  91.         lastr=curr;
  92.     }    
  93. }
  94.  
  95. default
  96. {
  97.     changed(integer change)
  98.     {
  99.         if(change & CHANGED_OWNER) llResetScript();
  100.     }
  101.     state_entry()
  102.     {
  103.         // setting shape
  104.         llSetLinkPrimitiveParamsFast(1, [ PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0, 1.0, 0.0>, 0.898000, ZERO_VECTOR, <0.250000, 0.250000, 0.0>, ZERO_VECTOR, PRIM_SIZE, <0.500000, 0.500000, 0.500000>, PRIM_ROTATION, <-0.49999, -0.50001, -0.50001, 0.49999>, PRIM_COLOR, 0, <1.0, 1.0, 1.0>, 1.0, PRIM_COLOR, 1, <0.0, 1.0, 0.0>, 1.0, PRIM_COLOR, 2, <0.0, 0.501961, 1.0>, 1.0, PRIM_COLOR, 3, <0.0, 1.0, 0.0>, 1.0, PRIM_COLOR, 4, <1.0, 1.0, 1.0>, 1.0, PRIM_COLOR, 5, <0.729412, 0.0, 0.121569>, 1.0, PRIM_COLOR, 6, <1.0, 1.0, 1.0>, 1.0, PRIM_TEXTURE, ALL_SIDES, "5748decc-f629-461c-9a36-a35a221fe21f", <1.0, 1.0, 0.0>, ZERO_VECTOR, 0.0, PRIM_FLEXIBLE, FALSE,0,0.000000,0.000000,0.000000,0.000000,ZERO_VECTOR]);
  105.         // set sit
  106.         llSitTarget(<0.5,0,-.5>,llEuler2Rot(DEG_TO_RAD*<0,90,180>));
  107.         // dialog
  108.         llListen(-1,"",llGetOwner(),"");
  109.         // save first position
  110.         initPOS=llGetPos();
  111.         initROT=llGetRot();
  112.         menu();
  113.     }
  114.  
  115.  
  116.     touch_start(integer total_number)
  117.     {
  118.         menu();
  119.     }
  120.     listen(integer channel,string name, key id, string str)
  121.     {
  122.         if(str=="RESTART")
  123.         {
  124.             llSay(0,"Resetting script");
  125.             llResetScript();
  126.             return;
  127.         }
  128.         if(str=="ADDFRAME")
  129.         {
  130.             llSay(0,"Marking waypoint");
  131.             addFrame(llGetPos(),llGetRot());
  132.                
  133.                     }
  134.         // remove last if only one just RESET
  135.         if(str=="DELFRAME")
  136.         {
  137.            removeFrame();
  138.            
  139.         }
  140.         if(str=="PLAY")
  141.         {
  142.             llSay(0,"Starting motion...");
  143.             warpPosRot(initPOS,initROT);
  144.             llSleep(.5);
  145.             getMotionPath();
  146.  
  147.             llSetKeyframedMotion( motionPath, [ KFM_MODE, KFM_FORWARD ]);
  148.             motionPath=[];
  149.                
  150.         }
  151.         if(str=="STOP")
  152.         {
  153.             llSay(0,"Stopping motion...");
  154.             llSetKeyframedMotion([],[]);
  155.         }
  156.         if(str=="SCRIPT")
  157.         {
  158.             getMotionPath();
  159.             llSay(0,"default { state_entry() { while(llVecDist(llGetPos(),"+(string)initPOS+")>0.01)llSetLinkPrimitiveParamsFast(0, [ PRIM_POSITION, "+(string)initPOS+", PRIM_ROTATION, "+(string)initROT+"]); llSetKeyframedMotion([ ");
  160.            
  161.             string s=llList2CSV(motionPath);
  162.             while(llStringLength(s)>255)
  163.             {
  164.                 string first=llGetSubString(s,0,255);
  165.                 llSay(0,first);
  166.                 s=llGetSubString(s,256,-1);
  167.             }
  168.             llSay(0,s);
  169.            
  170.             llSay(0,"],[KFM_MODE,KFM_FORWARD]);}}");      
  171.         }
  172.         if(str=="|<<")
  173.         {
  174.                 iframe=0;
  175.                 goFrame();
  176.         }
  177.         if(str==">>|")
  178.         {
  179.                 iframe=llGetListLength(positions);
  180.                 goFrame();
  181.         }
  182.         if(str==">")
  183.         {
  184.                 iframe++;
  185.                 integer l=llGetListLength(positions);
  186.                 if(iframe>l)iframe=l;
  187.                 goFrame();
  188.         }
  189.         if(str=="<")
  190.         {
  191.                 iframe--; if(iframe<0) iframe=0;
  192.                 goFrame();
  193.         }
  194.         if(str=="HELP")
  195.         llGiveInventory(llGetOwner(),llGetInventoryName(INVENTORY_NOTECARD,0));
  196.         menu();      
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement