Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector initPOS;
- rotation initROT;
- list positions=[];
- list rotations=[];
- list motionPath;
- integer iframe=0;
- menu(){
- llDialog(llGetOwner(),"Choose",["HELP","ADDFRAME","DELFRAME","RESTART","SCRIPT","PLAY","|<<",">>|","STOP","<",">" ],-1);
- }
- vector lastPOS()
- {
- vector pos=initPOS;
- integer i;
- for(i=0;i<iframe;i++) pos+=llList2Vector(positions,iframe-1);
- return pos;
- }
- rotation lastROT()
- {
- rotation rot=initROT;
- integer i;
- for(i=0;i<iframe;i++) rot*=llList2Rot(rotations,iframe-1);
- return rot;
- }
- goFrame()
- {
- integer l=llGetListLength(positions);
- llSay(0,"You are at frame #"+(string)iframe);
- if(iframe==0)
- {
- warpPosRot(initPOS,initROT);
- return;
- }
- warpPosRot(llList2Vector(positions,iframe-1), llList2Rot(rotations,iframe-1));
- }
- addFrame(vector pos, rotation rot)
- {
- iframe++;
- // removing frame at pos iframe
- if(iframe>llGetListLength(positions)){
- positions+=[pos];
- rotations+=[rot];
- return;
- }
- positions=llListReplaceList(positions,[pos],iframe-1,iframe-1);
- rotations=llListReplaceList(rotations,[rot],iframe-1,iframe-1);
- }
- removeFrame()
- {
- iframe--;
- integer l=llGetListLength(positions);
- if(iframe>=l)
- {
- if(l<=1){ positions=[]; rotations=[]; return;}
- // remove last position
- positions=llDeleteSubList(positions,-1,-1);
- rotations=llDeleteSubList(rotations,-1,-1);
- return;
- }
- // removing intermediate frame
- positions=llDeleteSubList(positions,iframe,iframe);
- }
- warpPosRot(vector pos, rotation rot)
- {
- llSay(0,"warping to "+(string)pos);
- // loop to move the prim at initial destination
- while(llVecDist(llGetPos(),pos)>0.01)
- llSetLinkPrimitiveParamsFast(1, [ PRIM_POSITION, pos, PRIM_ROTATION, rot ]);
- }
- getMotionPath()
- {
- motionPath=[];
- integer i; vector lastp=initPOS; rotation lastr=initROT;
- for(i=0;i<llGetListLength(positions);i++)
- {
- vector curp=llList2Vector(positions,i);
- rotation curr=llList2Rot(rotations,i);
- vector diffp=curp-lastp;
- rotation diffr=curr/lastr;
- float dist= llVecMag(diffp);
- // try to force length in seconds proportional to actual meters
- if (dist<1) dist=1;
- motionPath+=[ diffp, diffr, dist*0.1 ];
- lastp=curp;
- lastr=curr;
- }
- }
- default
- {
- changed(integer change)
- {
- if(change & CHANGED_OWNER) llResetScript();
- }
- state_entry()
- {
- // setting shape
- 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]);
- // set sit
- llSitTarget(<0.5,0,-.5>,llEuler2Rot(DEG_TO_RAD*<0,90,180>));
- // dialog
- llListen(-1,"",llGetOwner(),"");
- // save first position
- initPOS=llGetPos();
- initROT=llGetRot();
- menu();
- }
- touch_start(integer total_number)
- {
- menu();
- }
- listen(integer channel,string name, key id, string str)
- {
- if(str=="RESTART")
- {
- llSay(0,"Resetting script");
- llResetScript();
- return;
- }
- if(str=="ADDFRAME")
- {
- llSay(0,"Marking waypoint");
- addFrame(llGetPos(),llGetRot());
- }
- // remove last if only one just RESET
- if(str=="DELFRAME")
- {
- removeFrame();
- }
- if(str=="PLAY")
- {
- llSay(0,"Starting motion...");
- warpPosRot(initPOS,initROT);
- llSleep(.5);
- getMotionPath();
- llSetKeyframedMotion( motionPath, [ KFM_MODE, KFM_FORWARD ]);
- motionPath=[];
- }
- if(str=="STOP")
- {
- llSay(0,"Stopping motion...");
- llSetKeyframedMotion([],[]);
- }
- if(str=="SCRIPT")
- {
- getMotionPath();
- llSay(0,"default { state_entry() { while(llVecDist(llGetPos(),"+(string)initPOS+")>0.01)llSetLinkPrimitiveParamsFast(0, [ PRIM_POSITION, "+(string)initPOS+", PRIM_ROTATION, "+(string)initROT+"]); llSetKeyframedMotion([ ");
- string s=llList2CSV(motionPath);
- while(llStringLength(s)>255)
- {
- string first=llGetSubString(s,0,255);
- llSay(0,first);
- s=llGetSubString(s,256,-1);
- }
- llSay(0,s);
- llSay(0,"],[KFM_MODE,KFM_FORWARD]);}}");
- }
- if(str=="|<<")
- {
- iframe=0;
- goFrame();
- }
- if(str==">>|")
- {
- iframe=llGetListLength(positions);
- goFrame();
- }
- if(str==">")
- {
- iframe++;
- integer l=llGetListLength(positions);
- if(iframe>l)iframe=l;
- goFrame();
- }
- if(str=="<")
- {
- iframe--; if(iframe<0) iframe=0;
- goFrame();
- }
- if(str=="HELP")
- llGiveInventory(llGetOwner(),llGetInventoryName(INVENTORY_NOTECARD,0));
- menu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement