script by Moriash Moreau

// Simple Camera Lock
// by
// Moriash Moreau, 12/17/06
//
// You may this script for whatever purpose you like, provided it's legal 
// and doesn't violate the SL TOS.  Be excellent to each other.  Party on.

// Instructions:
// Insert this script in a small prim.  Attach the prim to any convenient HUD position.
// Maneuver your camera to the desired camera position (see F1 Help->Basic Help->Camera Controls).
// Say "/2 lock" to store the current camera position.  Then, to return your camera to that
// position, either touch the HUD prim or say "/2 camera".  Touch or say "/2 camera" again
// to release camera control.  Note that your avatar must be within approximately 50 meters
// of the stored camera position for the camera lock to function properly.

// INTERNAL VARIABLES

integer Toggle;
integer Listener;
vector CamPos;
rotation CamRot;
vector CamFoc;

// Ask for permissions.  Start up the Listen again (to deal with changes in ownership).

Init()
{
    llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA | PERMISSION_ATTACH | PERMISSION_TRACK_CAMERA );
    llListenRemove(Listener);
    Listener = llListen(2, "", llGetOwner() , "" );
    Toggle = FALSE;
    llSetColor(<1,0,0>,ALL_SIDES);
}

// Toggle the camera lock on and off.

CamToggle()
{
    if (Toggle)
    {
        llClearCameraParams();
        //llSetAlpha(1.0,ALL_SIDES); //Add this line if you are photographing with HUDs on.
        llSetColor(<1,0,0>,ALL_SIDES);
        llOwnerSay("Releasing camera control.");
        Toggle = FALSE;
    }
    else
    {
        Toggle = TRUE;
        //llSetAlpha(0.0,ALL_SIDES); //Add this line if you are photographing with HUDs on.
        llSetColor(<0,1,0>,ALL_SIDES);
        llOwnerSay("Returning to locked camera position.");
        llSetCameraParams([ 
        CAMERA_ACTIVE, TRUE,
        CAMERA_FOCUS, CamFoc,
        CAMERA_FOCUS_LOCKED, TRUE,
        CAMERA_POSITION, CamPos,
        CAMERA_POSITION_LOCKED, TRUE
        ]); 
    }
}

default 
{ 
    state_entry()
    {
        Init();
    }
    attach(key id) 
    { 
        // If we're detaching, clear the camera.
        if (id == NULL_KEY) 
        { 
            if (llGetPermissions() & PERMISSION_CONTROL_CAMERA)
            {
                llClearCameraParams();
            }
        }
        // If we're attaching, initialize the camera lock.
        else 
        { 
            Init();
        } 
    }
    // Sort through required permissions.
    run_time_permissions(integer perm) 
    { 
        if (perm & PERMISSION_CONTROL_CAMERA | PERMISSION_ATTACH | PERMISSION_TRACK_CAMERA ) 
        { 
            llOwnerSay("Camera control enabled.");
        }
        else
        {
            llOwnerSay("Camera control refused.  Detaching.");
            llDetachFromAvatar();
        }
    }
    // Turn the camera lock on and off.
    touch_start(integer total_number)
    {
        CamToggle();   
    }
    listen( integer channel, string name, key id, string message )
    {
        // Alternate method of turning the camera lock on and off.
        if (message == "camera")
        {
            CamToggle();
        }

        // Read and store the current camera position.

        else if (message == "lock")
        {
            llOwnerSay("Storing current camera position.");
            CamPos = llGetCameraPos();
            CamRot = llGetCameraRot();
            CamFoc = CamPos + llRot2Fwd(CamRot);
        }
    }
} 
camera_lock.txt · Last modified: 2016/02/15 21:12 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0