summaryrefslogtreecommitdiff
path: root/scripts/testing/lsl/move_in_circle_using_llSetRegionPos.lsl
blob: cc5b899b6780e86eb0fc1d25e8fe56d14aac9a6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
integer listenHandle; 
integer verbose;
integer num_steps = 12;
float circle_time = 5.0;
integer circle_step;
vector circle_pos;
vector circle_center;
float circle_radius;

start_circle(vector center, float radius)
{
    vector currentPosition = llGetPos();
    circle_center = center;
    circle_radius = radius;
    circle_step = 0;
    llSetTimerEvent(circle_time/num_steps);
    llTargetOmega(<0.0, 0.0, 1.0>, TWO_PI/circle_time, 1.0);
}

stop_circle()
{
    llSetTimerEvent(0);
    llTargetOmega(<0.0, 0.0, 1.0>, TWO_PI/circle_time, 0.0);
    llSetRegionPos(circle_center);
}

next_circle()
{
    float rad = (circle_step * TWO_PI)/num_steps;
    float x = circle_center.x + llCos(rad)*circle_radius;
    float y = circle_center.y + llSin(rad)*circle_radius;
    float z = circle_center.z;
    llSetRegionPos(<x,y,z>);
    circle_step = (circle_step+1)%num_steps;
}

default
{
    state_entry()
    {
        //llSay(0, "Hello, Avatar!");
        listenHandle = llListen(-2001,"","","");  
        verbose = 0;
        circle_center = llGetPos();
    }

    listen(integer channel, string name, key id, string message)
    {
        //llOwnerSay("got message " + name + " " + (string) id + " " + message);
        list words = llParseString2List(message,[" "],[]);
        string command = llList2String(words,0);
        string option = llList2String(words,1);
        if (command=="anim")
        {
            if (option=="start")
            {
                start_circle(llGetPos(), 3.0);
            }
            else if (option=="stop")
            {
                stop_circle();
            }
        }
        if (command=="verbose")
        {
            if (option=="on")
            {
                verbose = 1;
            }
            else if (option=="off")
            {
                verbose = 0;
            }
        }
        if (command=="step")
        {
            llSetTimerEvent(0);
            next_circle();
        }
    }

    timer()
    {
        next_circle();
    }
}

// Local Variables:
// shadow-file-name: "$SW_HOME/axon/scripts/testing/lsl/move_in_circle_using_llSetRegionPos.lsl"
// End: