Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Pendulum Pendulum  

Pendulum

Will swing a prim like a simple pendulum pivoting at an axis parallel to the prim's Y-axis

Category: Pendulum
By : Dora Gustafson, Studio Dora
Created: 2015-11-24 Edited: 2015-11-24
Worlds: Second Life

the Zip file

Download all files for Pendulum
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Pendulum script.lsl
1 // Pendulum motion by Dora Gustafson, Studio Dora 2012
2 // Will swing a prim like a simple pendulum pivoting at an axis parallel to the prim's Y-axis
3 // The pivot axis will be at the top of a prim with the Z-axis pointing up
4 // Quote from http://en.wikipedia.org/wiki/Pendulum_(mathematics)
5 // • A simple pendulum is an idealization of a real pendulum using the following assumptions:
6 // • The rod or cord on which the bob swings is massless, inextensible and always remains taut;
7 // • Motion occurs only in two dimensions, i.e. the bob does not trace an ellipse but an arc.
8 // • The motion does not lose energy to friction or air resistance.
9 // The periode time increase with the Z dimension (the pendulum length)...
10 // If it is too small the motion will not be well because of the time limitation with Key Framed Motions
11 // The parameters set in the script works nice with a 3m long pendulum
12 // If the pendulum is moved, rotated or resized the script must be reset to update the motion
13
14 float angle=1.0; // max swing from resting (radians)
15 float steps=12.0; // number of Key Frames
16 float step=0.0;
17 list KFMlist=[];
18 vector U;
19 vector V;
20 float angleU=0.0;
21 float angleV;
22 integer swing=TRUE;
23 vector basePos;
24 rotation baseRot;
25
26 default
27 {
29 {
30 llSetMemoryLimit( llGetUsedMemory()+0x1000);
31 llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
32 basePos = llGetPos();
33 baseRot = llGetRot();
34 vector v1 = llGetScale();
35 float periode = TWO_PI*llSqrt( v1.z/9.81);
36 float dT = periode/steps;
37 dT = llRound(45.0*dT)/45.0;
38 if( dT < 0.11111111 ) dT = 0.11111111;
39 v1.x = 0.0;
40 v1.y = 0.0;
41 v1 = -0.5*v1*llGetRot();
42 U = v1;
43 while( step < steps )
44 {
45 step += 1.0;
46 angleV = angle*llCos( TWO_PI*step/steps + PI_BY_TWO);
47 V = v1*llAxisAngle2Rot(llRot2Fwd(llGetRot()), angleV);
48 KFMlist += [V-U, llEuler2Rot(< angleV-angleU, 0.0, 0.0>), dT];
49 angleU = angleV;
50 U = V;
51 }
52 }
54 {
55 llSetKeyframedMotion( [], []);
56 llSleep(0.2);
58 if( swing ) llSetKeyframedMotion( KFMlist, [ KFM_MODE, KFM_LOOP]);
59 swing = !swing;
60 }
62 }

Back to the Best Free Tools in Second Life and OpenSim.