Ok I fixed it, here is the full script as simple on/off-Button-HUD:
//based on Linden Labs
//Dan Linden
integer on = FALSE;
key agent = "xxxxxxxxxxxxxxxxxxxxx"; // avatar key
// colors see http://wiki.secondlife.com/wiki/Category:LSL_Color
vector red = <1.000, 0.255, 0.212>;
vector blue = <0.000, 0.455, 0.851>;
overhead_cam()
{
llOwnerSay("overhead_cam_new"); // say function name for debugging
vector xyz = llGetPos();
float xx = 234.0;
float yy = 36.0;
float zz = 30.5;
float zz2 = 8.0;
if (xyz.x < xx)
{
xyz.x = xx - xyz.x ; // x + diff = newPos
}
else
{
xyz.x = (xyz.x - xx) * -1; // x + (minusDiff) = newPos
}
if (xyz.y < yy)
{
xyz.y = yy - xyz.y ; // y + diff = newPos
}
else
{
xyz.y = (xyz.y - yy) * -1; // y + (minusDiff) = newPos
}
if (xyz.z < zz)
{
xyz.z = zz - xyz.z ; // z + diff = newPos
}
else
{
xyz.z = (xyz.z - zz) * -1; // z + (minusDiff) = newPos
}
vector xyz2 = xyz;
xyz2.z = xyz.z - zz2;
xyz = llGetPos() + xyz ;
xyz2 = llGetPos() + xyz2 ;
rotation camRot = llGetCameraRot();
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 20.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, <0,0,5>, // region relative position
CAMERA_FOCUS, xyz2 + <0.0, 0.0, -180.0> * camRot, // region relative position
CAMERA_FOCUS_LAG, 0.05 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
// CAMERA_PITCH, 80.0, // (-45 to 80) degrees
CAMERA_POSITION, xyz , // region relative position
CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 4.0 // (0 to 4) meters
// CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
}
default
{
state_entry()
{
llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA );
llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
integer perm = llGetPermissions();
if ((perm & PERMISSION_CONTROL_CAMERA) == PERMISSION_CONTROL_CAMERA) {
llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
llOwnerSay("Camera permissions have been taken");
llSetColor(blue, ALL_SIDES);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, blue, 1, 10, 2]);
}
}
touch_start(integer total_number)
{
if (on == FALSE) // overhead an
{
llOwnerSay("take_camera_control, press ESC after first time touched to change view to object");
llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA);
llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
overhead_cam();
llSetColor(red, ALL_SIDES);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, red, 1, 10, 2]);
on = TRUE;
}
else if (on == TRUE) // overhead aus
{
llOwnerSay("release_camera_control"); // say function name for debugging
llSetCameraParams([CAMERA_ACTIVE, 0]); // 1 is active, 0 is inactive
llReleaseCamera(agent);
llSetColor(blue, ALL_SIDES);
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, blue, 1, 10, 2]);
on = FALSE;
}
}
}
only last thing is, the new view differs a bit depending on position, avatar stands when pressed button, but this is ok for first. And pressing ESC when first time used to change to new view is still needed.