Jump to content

Need help adding a rotation to a swing script LSL


Pixels Sideways
 Share

You are about to reply to a thread that has been inactive for 2154 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hiya folks --

I have a large pendulum and am using the Dora Gustafson, Studio Dora swing script (below) from the outworlds script library.

The text prims are set up and linked as such: pendulum (cube prim, tapered at the bottom), then a cylinder stretched out on z that acts like a rod and at the top, a small cube that is the root and contains the swing script.  

it works okay, i had to adjust the angle and the steps in the swing script to decrease the swing angle and slow it down -- well, it works mostly okay, it can be kinda jerky every now and then but I can live with that for now.    

What I'd like to do next is to rotate the root cube so the pendulum continues to swing but via the root, will also slowly rotate within a circular space on the ground so that if you attached a pencil to the pendulum end, it would act like a kind of spirograph.   Not sure how to incorporate the rotation of the root prim into the swing script.  I plopped in a target omega line of code but it didn't do anything - I'm guessing because I have no clue what I"m doing and that I read somewhere and can't find it there is a specific target omega for physical objects. (?)

in an absolutely perfect world, the swing script would also randomly change the angle so that would alter the length of the path / lines.  

Appreciate any help.  

Thank you!

 

This is the swing script:

 

// :SHOW:
// :CATEGORY:Pendulum
// :NAME:Pendulum
// :AUTHOR:Dora Gustafson, Studio Dora 
// :KEYWORDS:
// :CREATED:2015-11-24 20:38:39
// :EDITED:2015-11-24  19:38:39
// :ID:1094
// :NUM:1870
// :REV:1
// :WORLD:Second Life
// :DESCRIPTION:
// Will swing a prim like a simple pendulum pivoting at an axis parallel to the prim's Y-axis
// :CODE:
// Pendulum motion by Dora Gustafson, Studio Dora 2012
// Will swing a prim like a simple pendulum pivoting at an axis parallel to the prim's Y-axis
// The pivot axis will be at the top of a prim with the Z-axis pointing up
// Quote from http://en.wikipedia.org/wiki/Pendulum_(mathematics)
// • A simple pendulum is an idealization of a real pendulum using the following assumptions:
// • The rod or cord on which the bob swings is massless, inextensible and always remains taut;
// • Motion occurs only in two dimensions, i.e. the bob does not trace an ellipse but an arc.
// • The motion does not lose energy to friction or air resistance.
// The periode time increase with the Z dimension (the pendulum length)...
// If it is too small the motion will not be well because of the time limitation with Key Framed Motions
// The parameters set in the script works nice with a 3m long pendulum
// If the pendulum is moved, rotated or resized the script must be reset to update the motion
 
float angle=1.0; // max swing from resting (radians)  //I CHANGED THIS TO 0.35
float steps=12.0; // number of Key Frames             //I CHANGED THIS TO 48.0
float step=0.0;
list KFMlist=[];
vector U; 
vector V;
float angleU=0.0; 
float angleV;
integer swing=TRUE;
vector basePos;
rotation baseRot;
 
default
{
    state_entry()
    {
        llSetMemoryLimit( llGetUsedMemory()+0x1000);
        llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
        basePos = llGetPos();
        baseRot = llGetRot();
        vector v1 = llGetScale();
        float periode = TWO_PI*llSqrt( v1.z/9.81);
        float dT = periode/steps;
        dT = llRound(45.0*dT)/45.0;
        if ( dT < 0.11111111 ) dT = 0.11111111;
        v1.x = 0.0;
        v1.y = 0.0;
        v1 = -0.5*v1*llGetRot();
        U = v1;
        while ( step < steps )
        {
            step += 1.0;
            angleV = angle*llCos( TWO_PI*step/steps + PI_BY_TWO);
            V = v1*llAxisAngle2Rot(llRot2Fwd(llGetRot()), angleV);
            KFMlist += [V-U, llEuler2Rot(< angleV-angleU, 0.0, 0.0>), dT];
            angleU = angleV;
            U = V;
        }
    }
    touch_start( integer n)
    {
        llSetKeyframedMotion( [], []);
        llSleep(0.2);
        llSetPrimitiveParams([PRIM_POSITION, basePos, PRIM_ROTATION, baseRot]);
        if ( swing ) llSetKeyframedMotion( KFMlist, [ KFM_MODE, KFM_LOOP]);
        swing = !swing;
    }
    on_rez( integer n) { llResetScript(); }
}

 

Link to comment
Share on other sites

Dora wrote this nice script as a demo of one imaginative way to use KFM. The reason you can't combine it with a llTargetOmega rotation is that KFM and llTargetOmega run as client-side animations.  You can't run them simultaneously. To create a Foucault pendulum, you would need to add an extra rotation around the pendulum's Z axis at each step of the KFM formulation itself. That's not an easy one to figure out, so I'm not tempted to try it right now myself. I suggest contacting Dora to see whether she would be willing to do it (probably for a price). She has one of the most adept mathematical minds among SL scripters that I know.

Edited by Rolig Loon
  • Like 1
Link to comment
Share on other sites

Thanks for taking a look.  Foucault's pendulum is exactly what I'm trying to accomplish / emulate.  I can somewhat grasp how the rot would have to be incorporated into the math formula, but it's totes over my head.  I was wondering if there is a way to add a few degrees to

baseRot = llGetRot();

after a certain amount of swings or time so that it would add say 10 more degrees to the previous get rot pos and after 36 times - a full 360 degree rotation, would be reset back to the 0 degrees.  

Also was wondering what this would be like if it were made physical and how much that would drive the physics lag on a sim.   I recall there is/was a group of folks in SL who experiment in making physical objects do "RL" things instead of  the smoke and mirrors of client side animations.  Still would have to be scripted.  I once tried to make a giant physical perpetual motion thing -- with the five pendulum balls and it sort of worked until the physics blew it apart.

Anyway, here's the math that explains the Foucault pendulum in the wikipedia here: https://en.wikipedia.org/wiki/Foucault_pendulum

My workaround idea is to fake the Foucault motion by making a couple dozen of the pendulums, setting them up so each is set rot a few degrees from the previous one and sequentially making them visible/invisible -- would have to auto on/off each one in the sequence and timed to alpha/on off precisely at the resting point.  Also would have to on/off the swing or have all 24-36 running the swing script which I would imagine would be lagalicious and they would all probably wind up swinging out of sync.

Thanks again.  I'll try to contact Dora.  

Link to comment
Share on other sites

You could certainly try scripting a physical pendulum, but not with Dora's approach. KFM only works on non-physical objects. The problem I forsee with a phyical pendulum is maintaining any sort of control. The movement will be smooth but I'm afraid it will quickly become chaotic. A KFM solution really is likely to be most satisfying, if you can get the math to work. If I were home at my own computer and if I had time, I might be tempted to try it, but I still think Dora is your best bet.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2154 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...