User:Dora Gustafson/captureCameraView

From Second Life Wiki
Jump to navigation Jump to search

llSetLinkCamera() Example

Capture Camera View

<lsl> // camera capture/release test, script by Dora Gustafson, Studio Dora 2012 // v1.1 // save script in prim // sit on the prim // move camera // touch the prim to capture camera view or release capture

integer gag = FALSE;

default {

   state_entry()
   {
       llSitTarget( < 0.25, 0.0, 0.6 >, ZERO_ROTATION);
       llSetClickAction(CLICK_ACTION_SIT);
       llOwnerSay("To verify: stand up, press Esc, sit down and try to move the camera by the arrow keys");
   }
   touch_end(integer num)
   {
       gag = !gag;
       if (gag) llRequestPermissions( llGetOwner(), PERMISSION_TRACK_CAMERA);
       else
       {
           llSetLinkCamera( LINK_THIS, ZERO_VECTOR, ZERO_VECTOR);
           llOwnerSay("Capture released");
       }
   }
   run_time_permissions(integer perm)
   {
       if( perm & PERMISSION_TRACK_CAMERA)
       {
           rotation cam_rot=llGetCameraRot()/llGetRot(); // relative camera rotation
           vector cam_pos=(llGetCameraPos()-llGetPos())/llGetRot(); // relative camera position
           llSetLinkCamera( LINK_THIS, cam_pos, cam_pos + llRot2Fwd(cam_rot));
           llOwnerSay("Camera view captured");
       }
   }

} </lsl>