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
Camera ControlCam  

ControlCam

ControlCam.lsl

Category: Camera
By : Azurei Ash
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for ControlCam
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. ControlCam_1.lsl
1
2
3 // ControlCam script, by Azurei Ash, feel free to use and distribute
4 // To be used as a HUD attachment, touch to turn on, touch again to turn off
5 // HUD toggle by Ariane Brodie
6
7 // Initial camera position relative to avatar
8 // <1,0,.75> = 1 meter forward, 0 meters left, .75 meters up
9 vector CAMOFFSET=<1,0,.75>;
10
11 // camera is moved MOVERATE meters each control event for movement
12 // used by these controls: forward, back, left, right, up, down
13 // lower is slower/smoother, higher is faster/jumpier
14 float MOVERATE=0.5;
15
16 // camera is rotated SPINRATE degrees each control event for rotation
17 // used by these controls: rotate left, rotate right
18 // lower is slower/smoother, higher is faster/jumpier
19 // also a good idea to have this number divide 360 evenly
20 float SPINRATE=6.0;
21
22 // The above MOVERATE/SPINRATE will be multiplied by their corresponding
23 // LFACTOR while the left mouse button is held down
24 // LFACTORM corresponds to MOVERATE
25 // LFACTORS corresponds to SPINRATE
26 float LFACTORM=0.5;
27 float LFACTORS=0.5;
28
29 // maximum distance the camera can move away from the user, currently (SL1.9) this is 50m
30 float MAXDIST=50.0;
31
32 // ==================== SCRIPTERS ONLY BELOW THIS POINT! ;) ==================== //
33
34 integer permissions=FALSE;
35 key owner;
36
37 vector position;
38 rotation facing;
39
40
41 updateCamera()
42 {
43 vector focus=position+llRot2Fwd(facing);
44 // The camera was turned on earlier, the position and focus also locked
46 CAMERA_FOCUS, focus, // region relative position
47 CAMERA_POSITION, position // region relative position
48 ]);
49 }
50
51 default
52 {
54 {
56 PRIM_TEXTURE, ALL_SIDES, "05e736d6-fc50-cc61-ea97-51993ec47c24",
57 <0.4,0.1,0>, <0.2,0.41,0>, 0.0]);
58
59 if(permissions&PERMISSION_CONTROL_CAMERA)
62 }
63
65 {
66 state cam_on;
67 }
68 }
69
70 state cam_on
71 {
73 {
75 PRIM_TEXTURE, ALL_SIDES, "91a0e647-a69e-f13c-ed93-9bb84d7e790d",
76 <0.4,0.1,0>, <0.2,0.41,0>, 0.0]);
78 }
79
81 {
82 state default;
83 }
84
86 {
87 permissions=perm;
88 if(permissions)
89 {
91 // These camera parameters will be constant, so set them only once
93 CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
94 CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
95 CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
96 ]);
97
98 // level out their rotation
100 rot.x = rot.y = 0;
101 facing = llEuler2Rot(rot);
102
103 // offset and update the camera position
104 position = llGetPos()+CAMOFFSET*facing;
105 updateCamera();
107 }
108 }
109
110 control(key id, integer held, integer change)
111 {
112 // adjust the LFACTORs in response to changes in LBUTTON
113 if(change&CONTROL_LBUTTON)
114 {
115 if(held&CONTROL_LBUTTON) // LBUTTON pressed
116 {
117 MOVERATE *= LFACTORM;
118 SPINRATE *= LFACTORS;
119 }
120 else // LBUTTON released
121 {
122 MOVERATE /= LFACTORM;
123 SPINRATE /= LFACTORS;
124 }
125 }
126
127 // Only continue if some key is held, other than the left mouse button
128 // Mouselook will override the scripted camera, so don't move the camera if in mouselook
129 if((held&~CONTROL_LBUTTON) && !(llGetAgentInfo(owner)&AGENT_MOUSELOOK))
130 {
131 // Temporary position used, updated position may be out of range
132 vector pos=position;
133
134 // react to any held controls
136 {
137 facing *= llAxisAngle2Rot(<0,0,1>, SPINRATE*DEG_TO_RAD);
138 }
140 {
141 facing *= llAxisAngle2Rot(<0,0,1>, -SPINRATE*DEG_TO_RAD);
142 }
143 if(held&CONTROL_FWD)
144 {
145 pos += MOVERATE*llRot2Fwd(facing);
146 }
147 if(held&CONTROL_BACK)
148 {
149 pos -= MOVERATE*llRot2Fwd(facing);
150 }
151 if(held&CONTROL_UP)
152 {
153 pos += MOVERATE*llRot2Up(facing);
154 }
155 if(held&CONTROL_DOWN)
156 {
157 pos -= MOVERATE*llRot2Up(facing);
158 }
159 if(held&CONTROL_LEFT)
160 {
161 pos += MOVERATE*llRot2Left(facing);
162 }
163 if(held&CONTROL_RIGHT)
164 {
165 pos -= MOVERATE*llRot2Left(facing);
166 }
167
168 // only update position with the new one if it is in range
169 if(llVecDist(pos, llGetPos()) <= MAXDIST)
170 position = pos;
171
172 updateCamera();
173 }
174 }
175 } // end

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