Jump to content

Zoom Script Question


Jonhg1978
 Share

You are about to reply to a thread that has been inactive for 967 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

If you are using the Firestorm viewer, you can do that (more or less) by opening your MiniMap to see the colored dots for everyone on the region.  Then right click on one of them and select the CAM option.  Your camera position will zoom to that spot.  Assuming that the person is not on land where the owner has turned off the ability to see avatars on the land, you'll be able to see him/her.  That's kind of hard if you're on a crowded region, of course.

Theoretically, you should be able to write a script that does the same sort of thing in a HUD or something that you sit on. Assuming that you can get the position of the person or object you are interested in focusing on (with llGetObjectDetails( UUID, [OBJECT_POS]), for example) , you should be able to use llSetCameraEyeAtOffset to set its camera position nearby.

Link to comment
Share on other sites

19 minutes ago, Jonhg1978 said:

Any guess on why it's asking for coordinates twice?

Yup.  One of them is asking "Where is your camera?" ; the other one is asking "Where is your camera looking at?" See the full description of llSetCameraParams at http://wiki.secondlife.com/wiki/LlSetCameraParams. That's also the difference between llSetCameraEyeAtOffset and  llSetCameraAtOffset .

Edited by Rolig Loon
Additional information
  • Thanks 1
Link to comment
Share on other sites

Thanks I think I am getting closer, this is second script I make in SL so some things that should be simple are a little hard for me to understand.

 

This will return a list I think llGetObjectDetails( UUID, [OBJECT_POS]

but I need to isolate and pass as vector

CAMERA_POSITION 13 vector position n/a n/a

Sets camera position in region coordinates.

 

 

 

I know in most scripting languages you can pick a number in  a list or array something like listvariablename[1]

Maybe I can put something in a loop that prints out all the list contents so I can figure out what position is the vector numbers I need?

 

Link to comment
Share on other sites

// snippet, note it is equivalent to llDumpList2String(listName, ","); but does at least illustrate stepping through lists

inspectList(list aList)
{
	integer ii;
	integer iiMax = llGetListLength(aList);
	string output = "";

	for( ii = 0; ii < iiMax; ii++) // list elements start from 0 to listLength - 1
    {
		if( ii > 0) output += ",";
            output += llList2String(aList, ii);
      }
      llOwnerSay(output);
}

Sorry about the crappy forrmatting, I wish there was a code highlighter as part of the <> option to indent by tabs at the vry least.

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

The list created by llGetObjectDetails will be very simple, because you are only asking for one piece of information.  There's no need to step through multiple values:

list myList = llGetObjectDetails(kAvUUID, [OBJECT_POS]);

vector AvPos = llList2Vector(myList, 0);   // That is, the first element in myList (lists are numbered from zero)

So, that's where you want your camera to focus.  Set the camera position a few meters away from that.  Which direction?  Ask for OBJECT_ROT as well as OBJECT_POS and then set 

vector CamPos = AvPos + < 5.0,0.0,0.0> * AvRot;

That will put the camera 5 m in front of the target avatar. Then rotate the camera to face the av:

rotation CamRot =  llEuler2Rot(<0.0,0.0,PI_BY_TWO>) * AvRot; 

 

Edited by Rolig Loon
Link to comment
Share on other sites

9 hours ago, Profaitchikenz Haiku said:

Sorry about the crappy forrmatting, I wish there was a code highlighter as part of the <> option to indent by tabs at the vry least.

in the forums code editor, change the dropdown from html to 'C languages' to get basic highlighting and auto indent (which doesn't work amazingly but it's ok.)

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

So I tried to test with my two avatars (my main one JohnG and this test avatar). Unfortunately after a long time of fighting with it I discovered that llsetfunction would not work in firestorm (nothing happened) but it did change the camera in the classic viewer. By then I had switched to manual coordinates so I'll test more tomorrow with the actual script. Thanks for the help so far everyone.

Edited by kevinshero77
Link to comment
Share on other sites

I tried for a couple more hours but I can't get the function to work. Very occasionally it will work in the SL official viewer I think I got it to work twice. I'm manually typing in coordinates of a box across the room so I can't seem to figure out why the function won't work.

 

default
{
    state_entry()
    {
  
        llRequestPermissions(AviKey, PERMISSION_CONTROL_CAMERA); 
        llClearCameraParams();
        llSetCameraParams([
            CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
            CAMERA_FOCUS, <0,0,5>, // region relative position
            CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
            CAMERA_POSITION, <190.119, 255.204,95.770> , // region relative position
            CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
            ]);
        llSleep (15);
    }

Link to comment
Share on other sites

That's not how it works.  You requested PERMISSION_CONTROL_CAMERA but you didn't even check to determine whether it was granted.  llRequestPermissions triggers a run_time_permissions event.  That's where you need to do any actions that depend on permissions actually being granted. (PERMISSION_CONTROL_CAMERA is granted automatically and silently when requested by a script in an attachment or something that you are sitting on, but you still have to request it. )

run_time_permissions (integer perm)
{
     if ( perm & PERMISSION_CONTROL_CAMERA)
     {
          llClearCameraParams();
          llSetCameraParams([
            CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
            CAMERA_FOCUS, <0,0,5>, // region relative position
            CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
            CAMERA_POSITION, <190.119, 255.204,95.770> , // region relative position
            CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
            ]);
     }
}

When you write your actual script, you will be wanting to execute that llSetCameraParams  command several times, each time your target changes position.  You won't need to request permissions each time.  Once is enough, but you'll still want to check each time to verify that permission has been granted. So, for example, if you are triggering the camera function in a touch_start event, you will want to include

if (llGetPermissions() & PERMISSION_CONTROL_CAMERA)
{
     llClearCameraParams();
     llSetCameraParams([
       CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
       CAMERA_FOCUS, <0,0,5>, // region relative position
       CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
       CAMERA_POSITION, <190.119, 255.204,95.770> , // region relative position
       CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
       ]);
}

Substituting the new CAMERA_POSITION vector each time, of course.

I notice, by the way, that you are setting the camera focus position to a spot 5 m above yourself.  If you refer back to my earlier post, you'll see that you really want to specify it as the target avatar's position.

Final note: I assume you have read the wiki description of llSetCameraParams and have noticed that "Camera control currently only supported for attachments and objects on which you are sitting. An attempt otherwise will result in an error being shouted on DEBUG_CHANNEL."

         

Edited by Rolig Loon
Additional information
Link to comment
Share on other sites

HI yes this is in a cube I am sitting on. I tried the target avatars position first but since it didn't do anything I started manually typing in coordinates in an attempt to get the function to work at the most basic level. If I am not sitting on the cube I do get a debug warning. If sitting on the cube I don't get the permissions error but nothing happens except every one in  a great while it will work maybe 1 out of 20 times. When it works the camera stays locked in place, so I log off and log back in and try again once it worked twice in a row but then never worked again in tries after that. I try with the above function and report back if anything changes.

Edited by kevinshero77
Link to comment
Share on other sites

Just

9 hours ago, Rolig Loon said:
CAMERA_FOCUS, <0,0,5>, //

I don't know if the LSL portal is wrong, but you are supplying what look to me to be relative coordinates here, but the wiki page aays

http://wiki.secondlife.com/wiki/LlSetCameraParams#:~:text=Sets camera focus (target position) in region coordinates.

 

The last example on that wiki page gives a suitable vehicle follower function, perhaps you could adapt that for your purpose?

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

I have validated the permissions are granted because when I click the cube it does stay touched but unfortunately the camera remains unchanged even if I click it many times, stand up, sit back down etc

 

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
        llRequestPermissions(AviKey, PERMISSION_CONTROL_CAMERA); 
    }

    touch_start(integer total_number)
    {
    llRequestPermissions(AviKey, PERMISSION_CONTROL_CAMERA); 
    if (llGetPermissions() & PERMISSION_CONTROL_CAMERA)
    {
        llClearCameraParams();
        llSetCameraParams([
        CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
        CAMERA_FOCUS, <1,0,0>, // region relative position
        CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
        CAMERA_POSITION, <190.119, 255.204,95.770> ,
       CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
       ]);
        llSay(0, "Touched.");
    }

    }
}

 

 

I tried to put the hard coded coordinates in Camera Focus too just to see if it did anything but I also saw no change in camera there. I tried TRUE and FALSE for the locked. The function seems to be very difficult to get to activate the camera for some reason.
        

Edited by kevinshero77
Link to comment
Share on other sites

10 minutes ago, Profaitchikenz Haiku said:

What about the Wiki statement that camera focus is also in region coordinates? Is it wrong, or is it clever enough to work out from the given vector that it must be a relative position?

Yup

10 hours ago, Rolig Loon said:

I notice, by the way, that you are setting the camera focus position to a spot 5 m above yourself.  If you refer back to my earlier post, you'll see that you really want to specify it as the target avatar's position.

 

Link to comment
Share on other sites

I usually handle this by extracting the target position and rotation and use the position (plus maybe a little upwards when the target is an avatar so the target becomes its face rather than its crotch) as the focus and then use the target position plus your viewing offset adjusted for the target's rotation as the camera position.

vector camera_offset = <1.0, 0.0, 0.0>; //1m may be a bit close: you can make the offset larger or smaller, and you can use the y and z values to move the viewing position up or down, or off to one side. Also, you may want to make the z value the same as what you use for adjusting the target position so the view is straight and level

key target_key = however you're identifying your target;
vector target_position = llGetObjectDetails (target_key, [OBJECT_POS]);
rotation target_rotation = llGetObjectDetails (target_key, [OBJECT_ROT]);

llSetCameraParams 
([
        CAMERA_ACTIVE, TRUE, // TRUE == 1 is active, FALSE == 0 is inactive
        CAMERA_FOCUS, target_position + <0.0, 0.0, 0.5>, // region relative position and 0.5m higher
        CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
        CAMERA_POSITION, target_position + (camera_offset * target_rotation), // the offset adjusted to take into account the direction the target is facing
        CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
]);

Edited by KT Kingsley
  • Thanks 1
Link to comment
Share on other sites

O finally it is beginning to work, I'll clean this up later but it is now consistently changing the camera position


key AviKey="MY UUID GOES HERE";
key target_key;
default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
        llRequestPermissions(AviKey, PERMISSION_CONTROL_CAMERA); 
    }

    touch_start(integer total_number)
    {
    llRequestPermissions(AviKey, PERMISSION_CONTROL_CAMERA); 
    if (llGetPermissions() & PERMISSION_CONTROL_CAMERA)
    {
       vector camera_offset = <1.0, 0.0, 0.0>; 
       target_key = "TARGET UUID GOES HERE";
       
       list tempvar1 = llGetObjectDetails (target_key, [OBJECT_POS]); // type mismatch so I had to alter this
       vector target_position = llList2Vector(tempvar1, 0);
       tempvar1 = llGetObjectDetails (target_key, [OBJECT_ROT]); // type mismatch so altered
       rotation target_rotation = llList2Rot (tempvar1, 0);
       

llSetCameraParams 
([
        CAMERA_ACTIVE, TRUE, // TRUE == 1 is active, FALSE == 0 is inactive
        CAMERA_FOCUS, target_position + <0.0, 0.0, 0.5>, // region relative position and 0.5m higher
        CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
        CAMERA_POSITION, target_position + (camera_offset * target_rotation), // the offset adjusted to take into account the direction the target is facing
        CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)
]);
        llSay(0, "Touched.");
    }
        
    }
}

Edited by kevinshero77
typo
  • Like 1
Link to comment
Share on other sites

Oops! Yeah, the return from llGetObjectDetails is a list, so you have to extract the value from the list using one of the llList2* functions. Sorry, my bad.

Compacting things (so only one call to llGetObjectDetails):

list details = llGetObjectDetails (target_key, [OBJECT_POS, OBJECT_ROT]);
vector target_position = llList2Vector (details, 0);
rotation target_rotation = llList2Rot (details, 1);

Link to comment
Share on other sites

Thanks! This thing is a real pain. It has worked for a couple of avatars I selected but not for the majority. I can use the viewer zoom in on all (I pick them from nearby). I'm stumped, all I can think of is maybe it thinks the coordinates are not valid for some reason. Maybe the viewers are using a custom function they wrote themselves rather than this one?

Link to comment
Share on other sites

My first guess is that the method you're using to get an avatar key into the script isn't working properly.

This is where llOwnerSay debugging is needed.

When you get stuff like the avatar key put in an llOwnerSay debug, along the lines of llOwnerSay ("Avatar: " (string) avatar_key + ", " + llGetDisplayName (avatar_key)),  and similarly for its position llOwnerSay ("Position: " + (string) avatar_position);.

Scripts and viewer code are completely different things. The server sends data, such as avatar positions, to the viewer so the viewer knows where to draw an avatar, or position the camera to look at that avatar. That same data is made available to scripts through the LSL functions. Scripts run entirely on the simulator, and their effects are notified to whatever viewers might be affected by them.

Link to comment
Share on other sites

I had a significant breakthrough today. I realized the function is working much of the time but only if the camera is facing forward. If the camera is facing backward or sideways it looks like no change happened at all. In forward view I think it is trying to zoom on all avatars however sometimes it just looks at the side of a hill or something even if they are in range of nearby chat, but at least I can see some progress! Thank you to everyone who has been helping me try to figure this out.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 967 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...