Jump to content

Camera woes


Fritigern Gothly
 Share

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

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

Recommended Posts

I am anything but a newbie scripter, but I have a very hard time wrapping my mind around calculating a position in 3 dimensions.

What I want to do is have the camera focus on a certain prim in-world. Regardless of where this prim will be in-world, the camera will always position itself at the exact same distance and angle, relative to this prim and "looking" at the prim. The prim will be static, so I do not need to follow it. When the prim gets rotated, the camera rotates with it as it was linked to it, if that makes sense.

I don't want or need a whole script, but I definitely could use a boost in the right direction in the form of a snippet or so.
So... please? :)
 

NOTE: I have a mild version of a learning disability called dyscalculia, I can do some super basic math, but algebra and trig other than the super basic kind is usually beyond my capabilities. The reason why I say this is because well-intended advice like "just extrapolate the xyz vector of the epibrated falamarig" would most likely go over my head.

 

Edited by Fritigern Gothly
... stupid typos...
Link to comment
Share on other sites

Maybe this will help, if nothing else as a way of identifying what I didn't understand about the goal:

// cannot track an object smoothly, even just as it rotates
// only attachments and sat-upon objects can get cam-control permission

vector CAM_OFFSET = <2.0, 0.0, 0.5>;    // in object-local coordinates
key tgtKey;
vector tgtPos;  // static
rotation tgtRot = ZERO_ROTATION;    // compare to see if changed


default
{
    state_entry()
    {
        llSensor("Cam Me", "", PASSIVE, 10.0, PI);
    }
    sensor(integer num_detected)
    {
        tgtKey = llDetectedKey(0);
        llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA);
    }
    run_time_permissions(integer perms)
    {
        if (PERMISSION_CONTROL_CAMERA & perms)
        {
            list tgtData = llGetObjectDetails(tgtKey, [OBJECT_POS, OBJECT_ROT]);
            tgtPos = llList2Vector(tgtData, 0);
            tgtRot = llList2Rot(tgtData, 1);
            vector camPos = tgtPos + (CAM_OFFSET * tgtRot);
            llOwnerSay("setting cam focus to "+(string)tgtPos+", pos = "+(string)camPos);
            llSetCameraParams(
                [ CAMERA_ACTIVE, TRUE
                , CAMERA_FOCUS, tgtPos
                , CAMERA_FOCUS_LOCKED, TRUE
                , CAMERA_POSITION, camPos
                , CAMERA_POSITION_LOCKED, TRUE
                ]);
            llSetTimerEvent(0.2);
        }
    }
    timer()
    {
        rotation newRot = llList2Rot(llGetObjectDetails(tgtKey, [OBJECT_ROT]), 0);
        if (tgtRot != newRot)   // Don't push new cam setting unless a change
            if (PERMISSION_CONTROL_CAMERA & llGetPermissions())  // didn't get detached or anything
                llSetCameraParams(
                    [ CAMERA_ACTIVE, TRUE
                    , CAMERA_FOCUS, tgtPos
                    , CAMERA_FOCUS_LOCKED, TRUE
                    , CAMERA_POSITION, tgtPos + (CAM_OFFSET * (tgtRot = newRot))
                    , CAMERA_POSITION_LOCKED, TRUE
                    ]);
    }   
}

I made a couple comments up top to make sure expectations are realistic. (Of course you'd want the timer interval to be as long as tolerable.)

Edited by Qie Niangao
"cannot an object track" -- what language is that?
  • Like 1
Link to comment
Share on other sites

28 minutes ago, KT Kingsley said:

Might it make sense to have the target message whatever's controlling the user's camera whenever it rotates, rather than use a timer?

Certainly, if one has control of the rotating object. There's more script up there than I probably should have posted just to show the asked-for rotation formula, resulting in unwanted specificity like an interval timer instead of inter-object messaging, so yeah. Also, the _LAG parameter is an interesting suggestion; I've only ever used that with avatar-tracking cams (as opposed to _POSITION_LOCKED) but it sounds worth a try at least.

(Now that you mention it, isn't there a Star Wars character that would say something like "cannot an object track"? Yoda? Is that a thing?)

Edited by Qie Niangao
Link to comment
Share on other sites

8 hours ago, Fritigern Gothly said:

What I want to do is have the camera focus on a certain prim in-world. Regardless of where this prim will be in-world, the camera will always position itself at the exact same distance and angle, relative to this prim and "looking" at the prim.

I have this script. If what is provided above doesn't suit you, then IM me in world and I'll pass a copy to you.

It's simple: Drop the script into the object (prim, scultpy, mesh, anything) - Set camera angle, accept permission to track your camera, done (in that order) - remove script (I think it deletes itself) - that object will now, forever, have that camera angle applied to it whenever anyone sits on it, even if a poser/AVsitter/other script in put into it. The camera properties are now a part of the object itself and does not require any scripting to maintain it. You can even do it with a simple cube prim. And the camera angle will go into effect for all sitters on the object (if multiple sitters are able.)

There also is a "Remove Camera Angle" script to scrub it clean if you change your mind later.

These are open-source, full permissions script, by the way.

If you IM me - mention "Camera Positioner Script" in your IM or I'll be confused about why you IM me. LOL

Edit to add: Once the camera angle is set, it does NOT ask permission from sitters to "track" their camera, because there is no camera tracking - it simply readjust the camera based on object coordinates then leaves it there (it is not an active tracking.) It is an *amazingly* graceful camera-angle-changer for furniture, etc.

Edited by Alyona Su
Link to comment
Share on other sites

Everyone, I'm sorry for not replying to this sooner, but I wanted to take this in-world before I can say anything useful about any of your replies.

@Qie Niangao I have just played with that script for a few seconds, and although I don't really manage to understand the math (or the variables used), it does seem to do what I want, at least in part. I am not certain yet (i have not studied the script as closely as I will eventually) but from a first glance it may be doing more than I need it to. Will prolly come back to this later, but it looks like a good basis to build my own thing with 🙂

@Alyona Su I think that the more options, the better. I will poke you online as soon as my RL lets me 😉

 

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1540 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...