Camera Sync: Difference between revisions
Clang Bailey (talk | contribs) No edit summary |
mNo edit summary |
||
| 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) | ||
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 43: | Line 42: | ||
]); | ]); | ||
} | } | ||
} | }</lsl> | ||
</ | |||
'''Camera Default''' - Sets the camera parameters back to their defaults: | '''Camera Default''' - Sets the camera parameters back to their defaults: | ||
< | <lsl>camDefault() | ||
camDefault() | |||
{ | { | ||
llSetCameraParams([ | llSetCameraParams([ | ||
| Line 64: | Line 61: | ||
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> | ||
</ | |||
'''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) | ||
warpPos(vector destpos) | |||
{ | { | ||
integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1; | integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1; | ||
| Line 84: | Line 79: | ||
warpPos(llGetCameraPos()); | warpPos(llGetCameraPos()); | ||
llSetRot(llGetCameraRot()); | llSetRot(llGetCameraRot()); | ||
} | }</lsl> | ||
</ | |||
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}} | ||
Revision as of 14:50, 8 February 2008
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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: <lsl>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; //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 + <rotStep.x * cStep, rotStep.y * cStep, rotStep.z * cStep, rotStep.s * cStep>;
//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
]);
}
}</lsl>
Camera Default - Sets the camera parameters back to their defaults: <lsl>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
]);
}</lsl>
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) {
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());
}</lsl> Note: Camera Match utilizes WarpPos to enable the camera tracking prim to jump great distances in an efficient manner.