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
Movement Harmonic_Oscillator_motion  

Harmonic_Oscillator_motion

Harmonic_Oscillator_motion

Category: Movement
By : Dora Gustafson
Created: 2012-03-14 Edited: 2012-03-14
Worlds: Second Life

the Zip file

Download all files for Harmonic_Oscillator_motion
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Harmonic_Oscillator_motion_1.lsl
1 // Harmonic oscillator motion by Dora Gustafson, Studio Dora 2012
2 // will oscillate a prim along a straight line in space
3 // only the first half periode is computed, the second is the first in reverse
4
5 float phase=PI;
6 vector amplitude=< 0.0, 0.0, 2.0>; // amplitude and direction for oscillation
7 float Hperiode=2.0; // half periode time S
8 float steps=12; // number of Key Frames for a half periode
9 float step=0.0;
10 list KFMlist=[];
11 vector U;
12 vector V;
13 integer osc=TRUE;
14 vector basePos;
15
16 default
17 {
19 {
20 llSetMemoryLimit( llGetUsedMemory()+0x1000);
21 llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
22 basePos = llGetPos();
23 float dT = Hperiode/steps;
24 dT = llRound(45.0*dT)/45.0;
25 if( dT < 0.11111111 ) dT = 0.11111111;
26 U = amplitude*llCos( phase);
27 while( step < steps )
28 {
29 step += 1.0;
30 V = amplitude*llCos( PI*step/steps + phase);
31 KFMlist += [V-U, dT];
32 U = V;
33 }
34 }
36 {
37 llSetKeyframedMotion( [], []);
38 llSleep(0.2);
39 llSetRegionPos( basePos);
40 llSetPos( basePos);
41 if( osc ) llSetKeyframedMotion( KFMlist, [KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_PONG]);
42 osc = !osc;
43 }
45 }

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