Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

ControlCam - Control your camera with your movement keys

Azurei Ash
The Sticky!
Join date: 12 Jan 2006
Posts: 38
03-27-2006 21:30
What's new in Version 1.2:

I have now removed the distance limit since you can disable your camera contraints from the Client debug menu. (Press Ctrl+Alt+d to enable debug menus at the top of your screen, then Client -> Disable Camera Constraints)

Note that you may be able to crash your client if you move your camera too far away from yourself too rapidly. I had my LFACTORM set to 10 (moving 10 times as fast as normal) when I did some testing. Once you get outside your draw limit, you will only see the terrain, but I was zooming so fast the terrain drawing couldn't keep up and I crashed.

So I would recommend not going beyond the terrain drawing. You can spill over into an adjacent sim fine and maybe even the next one, but probably not farther.

Importante New Update!

The UP and DOWN controls (E and C keys or Page Up and Page Down) will now tilt your camera up and down instead of moving up and down. I figured out that I was multiplying in the wrong order when I tried this before.

It will allow you to tilt past the point where you flip over, but your camera will not turn upside down, instead you will find yourself facing the other direction, only now your tilt controls will be reversed. So if you prefer inverted controls for this, just flip yourself over once. ;)

I have also added a camera resume command. By default you can use "/1camresume" and it will turn control of your camera on, resuming from your previous position. If you have not used the script before, this command will probably put you at the origin point of your sim (fun!).

Also, the CAMON command (use "/1camon" by default) will now take control of your camera at its current position (plus a small bump forward to show you it is on, but this doesn't always seem to work). The script now tracks your camera too so that it can do this. So if you move your camera somewhere normally, it will pick up there when you activate ControlCam. Also, while using ControlCam, you may Alt+Zoom just as you have in the past. Moving will cause the camera to shift back to where it was, but now you can prevent this if you would like by tapping the left mouse button. So now you can move around with ControlCam, then do some Alt+Zooming, then click, and continue using ControlCam from your Alt+Zoomed camera position!

I think that's about it for this (long overdo) update! Expect more updates soon!

------------

Version 1.1:

Added the ability to hold down the left mouse button to multiply the two rates by corresponding factors. For example, while holding down the left mouse button the amount the camera moves/rotates each control event is cut in half for finer movement (by default).

Two new variables for tweaking have been added at the top, LFACTORM and LFACTORS, corresponding to movement and spin rates. While the left mouse button is held down, the rates have been multiplied by their factors. When the left mouse button is released, they are divided by their factors to return to their original value. The default values for each are .5, meaning you move and spin at half the rate while holding down the left mouse button.

The next update will include the ability to let someone else follow your camera.

------------

Initial Release info:

The following script is to be placed in an attachment and will allow you to control your camera with your movement keys.

By default, the script will listen for the following listen triggers on channel 1:

camon: Will turn camera control on (if it isn't already being controlled) and will position the scripted camera about a meter in front of the avatar's head.
camoff: Will turn off the scripted camera and reset everything

Use these commands by saying "/1camon" or "/1camoff", you must be wearing an attachment with this script inside.

While on, movement keys will not affect your avatar, but will be used to move/rotate your camera. The controls are much as you would expect:

Forward (W or Up arrow): moves the camera forward
Back (S or Down arrow): moves the camera backward
Rotate Left (A or Left arrow): rotates the camera to the left
Rotate Right (D or Right arrow): rotates the camera to the right
Left (Shift+A or Shift+Left arrow): moves the camera left
Right (Shift+D or Shift+Right arrow): moves the camera right
Up (E or Page Up): moves the camera upward
Down (C or Page Down): moves the camera downward

At this time, I have not yet been able get the camera to tilt up or down (it almost works, but not really) or otherwise modify the pitch. There is also no way I know of to barrel roll. So as is, the camera is always levelled out.

Entering mouselook while using the scripted camera will return you to your avatar's mouselook view. Control inputs will not affect the scripted camera while in mouselook, so when you hit ESC to get back out of mouselook, you will return to the scripted camera position where you were. You can also Alt+Zoom from your scripted camera position, but pressing a control input will move you back to the scripted camera and move it from where it was before you Alt+Zoomed.

In addition, there are some variables defined at the top of the script that you can use to tweak the behavior, they are explained in the script.

Alt+Zoom impaired users, enjoy!

~Azurei Ash

CODE

// ControlCam script, by Azurei Ash, feel free to use and distribute
// To be used in an attachment, use the commands below to turn on/off camera control

// say these commands on the specified channel to turn the camera on or off
integer CHANNEL=1;
string CAMON="camon";
string CAMOFF="camoff";
string CAMRESUME="camresume";

// camera is moved MOVERATE meters each control event for movement
// used by these controls: forward, back, left, right, up, down
// lower is slower/smoother, higher is faster/jumpier
float MOVERATE=0.5;

// camera is rotated SPINRATE degrees each control event for rotation
// used by these controls: rotate left, rotate right
// lower is slower/smoother, higher is faster/jumpier
// also a good idea to have this number divide 360 evenly
float SPINRATE=6.0;

// The above MOVERATE/SPINRATE will be multiplied by their corresponding
// LFACTOR while the left mouse button is held down
// LFACTORM corresponds to MOVERATE
// LFACTORS corresponds to SPINRATE
float LFACTORM=0.5;
float LFACTORS=0.5;

// ==================== SCRIPTERS ONLY BELOW THIS POINT! ;) ==================== //
key owner;

vector position;
rotation facing;

updateCamera()
{
vector focus=position+llRot2Fwd(facing);
// The camera was turned on earlier, the position and focus already locked
llSetCameraParams([
CAMERA_FOCUS, focus, // region relative focus
CAMERA_POSITION, position // region relative position
]);
}

default
{
attach(key attachedAgent)
{
llResetScript();
}

state_entry()
{
position=ZERO_VECTOR;
facing=ZERO_ROTATION;
owner=llGetOwner();
llListen(CHANNEL, "", owner, CAMON);
llListen(CHANNEL, "", owner, CAMOFF);
llListen(CHANNEL, "", owner, CAMRESUME);
llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS|PERMISSION_CONTROL_CAMERA|PERMISSION_TRACK_CAMERA);
}

listen(integer channel, string name, key id, string message)
{
if(message == CAMON)
{
llClearCameraParams();
facing=llGetCameraRot();
position=llGetCameraPos()+MOVERATE*llRot2Fwd(facing);
message = CAMRESUME;
}
if(message == CAMRESUME)
{
// These camera parameters will be constant, so set them only once
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
]);

updateCamera();

llTakeControls(CONTROL_LBUTTON|CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT|CONTROL_UP|CONTROL_DOWN|CONTROL_LEFT|CONTROL_RIGHT, TRUE, FALSE);
}
else // message == CAMOFF, turn the camera off, release controls
{
llSetCameraParams([CAMERA_ACTIVE, FALSE]);
llReleaseControls();
// re-request permissions for next time
llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS|PERMISSION_CONTROL_CAMERA|PERMISSION_TRACK_CAMERA);
}
}

control(key id, integer held, integer change)
{
// adjust the LFACTORs in response to changes in LBUTTON
if(change&CONTROL_LBUTTON)
{
if(held&CONTROL_LBUTTON) // LBUTTON pressed
{
vector p=llGetCameraPos();
if(p!=position)
{
position=p;
facing=llGetCameraRot();
}
MOVERATE *= LFACTORM;
SPINRATE *= LFACTORS;
}
else // LBUTTON released
{
MOVERATE /= LFACTORM;
SPINRATE /= LFACTORS;
}
}

// Only continue if some key is held, other than the left mouse button
// Mouselook will override the scripted camera, so don't move the camera if in mouselook
if((held&~CONTROL_LBUTTON) && !(llGetAgentInfo(owner)&AGENT_MOUSELOOK))
{
// react to any held controls
if(held&CONTROL_ROT_LEFT)
{
facing *= llAxisAngle2Rot(<0,0,1>, SPINRATE*DEG_TO_RAD);
}
if(held&CONTROL_ROT_RIGHT)
{
facing *= llAxisAngle2Rot(<0,0,1>, -SPINRATE*DEG_TO_RAD);
}
if(held&CONTROL_UP)
{
facing = llAxisAngle2Rot(<0,1,0>, -SPINRATE*DEG_TO_RAD)*facing;
}
if(held&CONTROL_DOWN)
{
facing = llAxisAngle2Rot(<0,1,0>, SPINRATE*DEG_TO_RAD)*facing;
}
if(held&CONTROL_FWD)
{
position += MOVERATE*llRot2Fwd(facing);
}
if(held&CONTROL_BACK)
{
position -= MOVERATE*llRot2Fwd(facing);
}
if(held&CONTROL_LEFT)
{
position += MOVERATE*llRot2Left(facing);
}
if(held&CONTROL_RIGHT)
{
position -= MOVERATE*llRot2Left(facing);
}

updateCamera();
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
03-28-2006 20:00
/54/21/96790/1.html
_____________________
i've got nothing. ;)
Richard Cerveau
Registered User
Join date: 31 Jan 2006
Posts: 11
04-14-2006 08:28
cool, u got a camprim script that will allow me to view a picture dead on 90 degrees?

i need it to get photos from SL onto my pc, and i want to get them dead on straight, so i can edit the surroundings out and make it look like a actual picture.. if you get what i mean
Azurei Ash
The Sticky!
Join date: 12 Jan 2006
Posts: 38
11-17-2006 06:46
updated bump