Difference between revisions of "Camera Sync"

From Second Life Wiki
Jump to navigation Jump to search
m
(updated lsl tags to source lsl2 tags)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header|ml=*}}


Camera sync allows for two users to synchronize their cameras, for use by builders in joint projects or in tutorials and demonstrations.  
Camera sync allows for two users to synchronize their cameras, for use by builders in joint projects or in tutorials and demonstrations.  
Line 5: Line 5:
----
----
'''Camera Tween''' - Smoothly adjusts the position and rotation of the camera over a given number of steps:
'''Camera Tween''' - Smoothly adjusts the position and rotation of the camera over a given number of steps:
<lsl>camTween(rotation camRot_origin, vector camPos_origin, rotation camRot_target, vector camPos_target, float steps)
<source lang="lsl2">camTween(rotation camRot_origin, vector camPos_origin, rotation camRot_target, vector camPos_target, float steps)
{
{
     //Keep steps a float, but make sure its rounded off to the nearest 1.0
     //Keep steps a float, but make sure its rounded off to the nearest 1.0
Line 14: Line 14:
      
      
     //Calculate camera rotation increments
     //Calculate camera rotation increments
     rotation rotStep = (camRot_target - camRot_origin);
     //rotation rotStep = (camRot_target - camRot_origin);
     rotStep = <rotStep.x / steps, rotStep.y / steps, rotStep.z / steps, rotStep.s / steps>;
     //rotStep = <rotStep.x / steps, rotStep.y / steps, rotStep.z / steps, rotStep.s / steps>;
      
      
      
      
     float cStep; //Loop through motion for cStep = current step, while cStep <= Total steps
     float cStep = 0.0; //Loop through motion for cStep = current step, while cStep <= Total steps
     for(cStep = 0.0; cStep <= steps; cStep++)
     for(; cStep <= steps; ++cStep)
     {
     {
         //Set next position in tween
         //Set next position in tween
         vector camPos_next = camPos_origin + (posStep * cStep);
         vector camPos_next = camPos_origin + (posStep * cStep);
         rotation camRot_next = camRot_origin + <rotStep.x * cStep, rotStep.y * cStep, rotStep.z * cStep, rotStep.s * cStep>;
         rotation camRot_next = slerp( camRot_origin, camRot_target, cStep / steps);
          
          
         //Set camera parameters
         //Set camera parameters
Line 42: Line 42:
         ]);
         ]);
     }
     }
}</lsl>
}
 
rotation slerp( rotation a, rotation b, float f ) {
    float angleBetween = llAngleBetween(a, b);
    if ( angleBetween > PI )
        angleBetween = angleBetween - TWO_PI;
    return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
}//Written by Francis Chung, Taken from http://forums-archive.secondlife.com/54/3b/50692/1.html</source>


'''Camera Default''' - Sets the camera parameters back to their defaults:
'''Camera Default''' - Sets the camera parameters back to their defaults:
<lsl>camDefault()
<source lang="lsl2">camDefault()
{
{
     llSetCameraParams([
     llSetCameraParams([
Line 61: Line 68:
         CAMERA_FOCUS_OFFSET, ZERO_VECTOR //<-10,-10,-10> to <10,10,10> meters
         CAMERA_FOCUS_OFFSET, ZERO_VECTOR //<-10,-10,-10> to <10,10,10> meters
     ]);
     ]);
}</lsl>
}</source>


'''Camera Match''' - Sets a prim's position and rotation to that of the user's camera (the one we have permissions for):
'''Camera Match''' - Sets a prim's position and rotation to that of the user's camera (the one we have permissions for):
<lsl>warpPos(vector destpos)
<source lang="lsl2">warpPos(vector destpos)
{
{
     integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
     integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
Line 79: Line 86:
     warpPos(llGetCameraPos());
     warpPos(llGetCameraPos());
     llSetRot(llGetCameraRot());
     llSetRot(llGetCameraRot());
}</lsl>
}</source>
Note: '''Camera Match''' utilizes [[WarpPos]] to enable the camera tracking prim to jump great distances in an efficient manner.
Note: '''Camera Match''' utilizes [[WarpPos]] to enable the camera tracking prim to jump great distances in an efficient manner.


{{LSLC|Library}}
{{LSLC|Library}}

Latest revision as of 17:29, 23 January 2015

Camera sync allows for two 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:

camTween(rotation camRot_origin, vector camPos_origin, rotation camRot_target, vector camPos_target, float steps)
{
    //Keep steps a float, but make sure its rounded off 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 = <rotStep.x / steps, rotStep.y / steps, rotStep.z / steps, rotStep.s / steps>;
    
    
    float cStep = 0.0; //Loop through motion for cStep = current step, while cStep <= Total steps
    for(; cStep <= steps; ++cStep)
    {
        //Set next position in tween
        vector camPos_next = camPos_origin + (posStep * cStep);
        rotation camRot_next = slerp( camRot_origin, camRot_target, cStep / steps);
        
        //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
        ]);
    }
}

rotation slerp( rotation a, rotation b, float f ) {
    float angleBetween = llAngleBetween(a, b);
    if ( angleBetween > PI )
        angleBetween = angleBetween - TWO_PI;
    return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
}//Written by Francis Chung, Taken from http://forums-archive.secondlife.com/54/3b/50692/1.html

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 camera (the one we have permissions for):

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());
}

Note: Camera Match utilizes WarpPos to enable the camera tracking prim to jump great distances in an efficient manner.