Object Follow Camera

integer channel = 0;

default {
    state_entry() {
        llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
    }
    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRACK_CAMERA) {
            state camera_captured;
        }
    }
}

state camera_captured {
    state_entry() {
        llListen(channel,"",llGetOwner(),"");
        llSetStatus(STATUS_PHYSICS,TRUE);
        llSetTimerEvent(0.1);
    }
    timer() {
        llMoveToTarget(llGetCameraPos()+<0.0,0.0,1.0>,0.1);
    }
    listen(integer channel, string name, key id, string message) {
        if (llToLower(message) == "hold") {
            state camera_captured_disabled;
        }
    }
}

state camera_captured_disabled {
    state_entry() {
        llListen(channel,"",llGetOwner(),"");
        llSetStatus(STATUS_PHYSICS,FALSE);
    }
    listen(integer channel, string name, key id, string message) {
        if (llToLower(message) == "follow") {
            state camera_captured;
        }
    }
}

 

Add a comment

CamHUD ( V1 )

Simple two function scripted camera controller. When turned on, the camera position locks in whatever place it was at the time of activation. To change the camera position, turn the HUD off...move the camera to the desired position...turn the HUD back on.

    https://d1yjxggot69855.cloudfront.net/skins/monobook/bullet.gif); ">
  • There are two buttons - One marked "Track" and another marked "Power".
      https://d1yjxggot69855.cloudfront.net/skins/monobook/bullet.gif); ">
    • "Power" (I think) has a fairly obvious function.
    • "Track" switches on and off, tracking of the owner. With tracking off the camera is locked solid. With tracking on the camera position is locked but it rotates to follow you around if you move.

The usefulness of this is up to you to decide.

 

Create the Object

 

To create the object use the following script. Just drop it onto/into a fresh prim. The resulting prim is quite small since it is designed to be a low impact HUD.

 

// V1 //
 
default
{
    state_entry()
    {
        llSetObjectName("CamHUD"); // You can change this after if you want.
        llSetPrimitiveParams([7, <0.01, 0.05, 0.025>,
                              8, <1 .0, 0.0, 0.0, 0.0>,
                              9, 0, 0, <0.125, 0.625, 0.0>, 0.1, <0.0, 0.0, 0.0>, <1 .0, 1.0, 0.0>, <0.0, 0.0, 0.0>,
                              17, -1, "5748decc-f629-461c-9a36-a35a221fe21f", <1 .0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0]);
        llRemoveInventory(llGetScriptName()); // Done its job so self deletes.
    }
}

 

 

CamHUD Script

 

Drop this script into the prim you just created. Wear the object as a HUD. If you do not see two distinct buttons separated by a black line, it is probably back to front or something.

 

// V1 //
 
integer perms;
 
integer track;
 
integer on;
 
vector red = <1 .0,0.0,0.0>;
 
vector green = <0.0,1.0,0.0>;
 
SetCameraParams(integer o, integer t)
{
    list focus = [];
    llClearCameraParams();
    if(t)
    focus = [CAMERA_FOCUS, llGetPos()];
    else
    focus = [CAMERA_FOCUS_LOCKED, TRUE];
    llSetCameraParams([CAMERA_ACTIVE, o, CAMERA_POSITION_LOCKED, TRUE] + focus);
}
 
default
{
    on_rez(integer param)
    {
        llResetScript();
    }
    state_entry()
    {
        if(llGetAttached())
        llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA);
    }
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_CONTROL_CAMERA)
        {
            perms = TRUE;
            llSetText("   Track | Power", <1 .0,1.0,1.0>, 1.0);
            llSetLinkPrimitiveParamsFast(-1, [PRIM_COLOR, -1, <0.0,0.0,0.0>, 1.0,
                                              PRIM_COLOR, 6, red, 1.0,
                                              PRIM_COLOR, 7, red, 1.0]);
        }
    }
    touch_start(integer nd)
    {
        if(perms)
        {
            integer face;
            vector color;
            if((face = llDetectedTouchFace(0)) == 6)
            {
                SetCameraParams((on = (!on)), track);
                if(on)
                color = green;
                else
                color = red;
            }
            else if(face == 7)
            {
                SetCameraParams(on, (track = (!track)));
                if(track)
                color = green;
                else
                color = red;
            }
            llSetLinkPrimitiveParamsFast(-1, [PRIM_COLOR, face, color, 1.0]);
        }
    }
}

 

Add a comment

Camera Sync

Camera sync allows for multiple users to synchronize their cameras, for use by builders in joint projects or in tutorials and demonstrations.



Camera Tween - Smoothly adjusts the position and rotation of the camera over a given number of steps (eight works well):

 

camTween(rotation camRot_origin, vector camPos_origin, rotation camRot_target, vector camPos_target, float steps)
{
    //Keep steps a float, but make sure its rounded of to the nearest 1.0
    steps = (float)llRound(steps);
    
    //Calculate camera position increments
    vector posStep = (camPos_target - camPos_origin) / steps;
    
    //Calculate camera rotation increments
    rotation rotStep = (camRot_target - camRot_origin);
    rotStep = ;
    
    
    float cStep; //Loop through motion for cStep = current step, while cStep <= Total steps
    for(cStep = 0.0; cStep <= steps; cStep++)
    {
        //Set next position in tween
        vector camPos_next = camPos_origin + (posStep * cStep);
        rotation camRot_next = camRot_origin + ;
        
        //Set camera parameters
        llSetCameraParams([
            CAMERA_ACTIVE, 1, //1 is active, 0 is inactive
            CAMERA_BEHINDNESS_ANGLE, 0.0, //(0 to 180) degrees
            CAMERA_BEHINDNESS_LAG, 0.0, //(0 to 3) seconds
            CAMERA_DISTANCE, 0.0, //(0.5 to 10) meters
            CAMERA_FOCUS, camPos_next + llRot2Fwd(camRot_next), //Region-relative position
            CAMERA_FOCUS_LAG, 0.0 , //(0 to 3) seconds
            CAMERA_FOCUS_LOCKED, TRUE, //(TRUE or FALSE)
            CAMERA_FOCUS_THRESHOLD, 0.0, //(0 to 4) meters
            CAMERA_POSITION, camPos_next, //Region-relative position
            CAMERA_POSITION_LAG, 0.0, //(0 to 3) seconds
            CAMERA_POSITION_LOCKED, TRUE, //(TRUE or FALSE)
            CAMERA_POSITION_THRESHOLD, 0.0, //(0 to 4) meters
            CAMERA_FOCUS_OFFSET, ZERO_VECTOR //<-10,-10,-10> to <10 ,10,10> meters
        ]);
    }
}

 

 

Camera Default - Sets the camera parameters back to their defaults:

 

 

camDefault()
{
    llSetCameraParams([
        CAMERA_ACTIVE, FALSE, //1 is active, 0 is inactive
        CAMERA_BEHINDNESS_ANGLE, 10.0, //(0 to 180) degrees
        CAMERA_BEHINDNESS_LAG, 0.0, //(0 to 3) seconds
        CAMERA_DISTANCE, 3.0, //(0.5 to 10) meters
        CAMERA_FOCUS_LAG, 0.1 , //(0 to 3) seconds
        CAMERA_FOCUS_LOCKED, FALSE, //(TRUE or FALSE)
        CAMERA_FOCUS_THRESHOLD, 1.0, //(0 to 4) meters
        CAMERA_PITCH, 0.0, //(-45 to 80) degrees
        CAMERA_POSITION_LAG, 0.1, //(0 to 3) seconds
        CAMERA_POSITION_LOCKED, FALSE, //(TRUE or FALSE)
        CAMERA_POSITION_THRESHOLD, 1.0, //(0 to 4) meters
        CAMERA_FOCUS_OFFSET, ZERO_VECTOR //<-10,-10,-10> to <10 ,10,10> meters
    ]);
}

 

 

Camera Match - Sets a prim's position and rotation to that of the user's (the one we have permissions for) camera:

 

 

warpPos(vector destpos)
{
    integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
    list rules = [PRIM_POSITION, destpos];
    integer count = 1;
    while (( count = count << 1 ) < jumps)
    {
        rules = (rules=[]) + rules + rules;
    }
    llSetPrimitiveParams(rules + llList2List(rules, (count - jumps) << 1, count));
}
camMatch()
{
    warpPos(llGetCameraPos());
    llSetRot(llGetCameraRot());
}

 

 

 

 

 

 

Add a comment

Camera Follower

Originally created by ArkLehane who edited the version posted here and credited to him on this Wiki out of existance.
Re-created and rebuilt by WolfWings Majestic because the script idea is useful, but the original version could be improved on.

Moves an object to the position of your camera.

 

 

integer channel = 0;

default {
    state_entry() {
        llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
    }
    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRACK_CAMERA) {
            state camera_captured;
        }
    }
}

state camera_captured {
    state_entry() {
        llListen(channel,"",llGetOwner(),"");
        llSetStatus(STATUS_PHYSICS,TRUE);
        llSetTimerEvent(0.1);
    }
    timer() {
        llMoveToTarget(llGetCameraPos()+<0.0,0.0,1.0>,0.1);
    }
    listen(integer channel, string name, key id, string message) {
        if (llToLower(message) == "hold") {
            state camera_captured_disabled;
        }
    }
}

state camera_captured_disabled {
    state_entry() {
        llListen(channel,"",llGetOwner(),"");
        llSetStatus(STATUS_PHYSICS,FALSE);
    }
    listen(integer channel, string name, key id, string message) {
        if (llToLower(message) == "follow") {
            state camera_captured;
        }
    }
}

 

 

 

Add a comment

Camera Follower

//  Camera Follower
//  Created by Water Rogers for IBM/Opensource
 
//  Purpose
//  --------------------------------------------------------------
//  This script shows you how you can make an object physical, and
//  have it follow your camera around.
 
//  Requirements
//  --------------------------------------------------------------
//  A single prim is all that is necessary for this example.
 
//  Usage
//  --------------------------------------------------------------
//  Permissions to track your camera are required for it to work
//  correctly.  Type "follow" to track the camera.  Type "stop" to
//  stop tracking the camera.  Touching the object will also start
//  tracking the camera.
 
//  GLOBALS
//  --------------------------------------------------------------
integer     g_ListenChannel = 0;        //  This is the listen channel
float       g_Timer         = 0.10;     //  This is the timer call rate
 
//  FUNCTIONS
//  --------------------------------------------------------------
permissions()
{
    //  Since this block of code is used more then once in the main
    //  loop, it's a good idea to make it a function.
 
    //  Get the permissions
    if(llGetPermissions() & PERMISSION_TRACK_CAMERA)
    {
        //  Permissions were passed, so we make the object physical
        //  and start the timer
        llSetStatus(STATUS_PHYSICS, TRUE);
        llSetTimerEvent(g_Timer);
    }
    else
    {
        //  Permissions were not passed, so we make the object static,
        //  set the timer to 0, and Request permissions.
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetTimerEvent(FALSE);
        llRequestPermissions(llGetOwner(), PERMISSION_TRACK_CAMERA);
    }
}
 
//  EVENTS
//  --------------------------------------------------------------
default
{
    state_entry()
    {
        //  Collision Sounds and Sprites can be replaced.  We make them
        //  empty strings so there are no sounds or sprites if the camera
        //  happens to knock up against a wall.
        llCollisionSound("", 0);
        llCollisionSprite("");
 
        //  Make a listener to listen for commands the owner may use.
        llListen(g_ListenChannel, "", llGetOwner(), "");
 
        //  Call the permissions() function block
        permissions();
    }
 
    on_rez(integer start_param)
    {
        //  The object was just rezzed out of inventory, so call up the
        //  permissions() function block
        permissions();
    }
 
    touch_start(integer num_detected)
    {
        //  The object was touched, so first we make sure that the owner
        //  touched the object, and if so... call the permissions()
        //  function block
        if(llDetectedKey(0) == llGetOwner()) permissions();
    }
 
    listen(integer channel, string name, key id, string message)
    {
        //  Turn all commands into lowercase using llToLower()
        message = llToLower(message);
        if(message == "stop")
        {
            //  The owner said "stop", so we'll turn off the object by
            //  making the object static, and setting the timer to 0
            llSetStatus(STATUS_PHYSICS, FALSE);
            llSetTimerEvent(FALSE);
        }
        else if(message == "follow")
        {
            //  The owner said "follow", so we call up the permissions()
            //  function block
            permissions();
        }
    }
 
    run_time_permissions(integer perm)
    {
        //  Permissions were requested through the permissions() function
        //  block.  Remember to use bitwise opperands when dealing with
        //  conditional statements for permissions.
        if(perm & PERMISSION_TRACK_CAMERA)
        {
            //  The owner granted permissions, so we set the object to
            //  physical, and fire up the timer.
            llSetStatus(STATUS_PHYSICS,TRUE);
            llSetTimerEvent(g_Timer);
        }
    }
 
    timer()
    {
        //  Here the timer uses llMoveToTarget() which simply moves the
        //  object to wherever the owner's camera is, and about 1 meter
        //  above (as to not obtruct the owner's view.  The owner will
        //  not be able to see the object under most circumstances, so if
        //  the owner wants to get rid of the object, they must first say
        //  "stop" in chat to make the object stop moving.  Then they can
        //  click on the object a lot easier to delete or take.
        llMoveToTarget(llGetCameraPos() + <0.0, 0.0, 1.0>, 0.20);
 
        //  Since the object looks a bit awkward only moving to position and
        //  not rotating properly, we call a simple sensor looking for the
        //  owner's current position.
        llSensor("", llGetOwner(), AGENT, 96, PI);
    }
 
    sensor(integer num_detected)
    {
        //  After we get the owner's position, we'll have the object just
        //  look at the owner using it's forward axis.  This gives a nice
        //  effect.  If you wanted to track the owners actual camera rotations
        //  then you would have to use llGetCameraRot() and make the correct
        //  calculations.  We do it this way for simplicity.
        llLookAt(llDetectedPos(0), 0.32, 0.32);
    }
}

 

Add a comment