Jump to content
  • 0

Circling Camera - vectors don't add up


kari1sl
 Share

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

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

Question

I'm trying to get the camera to circle my avatar but, clearly I've got vector trouble.
I've tried
float x = llCos(radians); float y = llSin(radians); vector here = llGetPos();
vector xyz = here + <x, y, 0>;

circle1_cam()
{
    llOwnerSay("Circle1"); // say function name for debugging
    llClearCameraParams(); // reset camera to defaul
        float radians; float x =1; float y =0;
        for(radians = 0.0; radians < 60; radians+=1)
        {
             vector here = llGetPos();
         vector xyz = here + <x, y, 0>;
            llOwnerSay("it moves to" + (string)xyz);
llSetCameraParams([
    CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
    CAMERA_BEHINDNESS_ANGLE,00.0, // (0 to 180) degrees
    CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
    CAMERA_DISTANCE, 1, // ( 0.5 to 10) meters
    CAMERA_FOCUS, here, // region relative position
    CAMERA_FOCUS_LAG, 0.1, // (0 to 3) seconds
    CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
    CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
    CAMERA_PITCH, 0.0, // (-45 to 80) degrees
    CAMERA_POSITION, xyz, // region relative position
    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, <0.0, 0.0, 0.0> // <-10,-10,-10> to <10,10,10> meters
            ]);
    // get x/y position of circumference
            float x = llCos(radians);
            float y = llSin(radians);
            llOwnerSay("It's at" + (string)here);
            llOwnerSay("but when I add" + (string)<x, y, 0>);
           
        }
}

 


which I now think is wrong after reading
http://lslwiki.net/lslwiki/wakka.php?wakka=vector
but
vector there = llGetPos();  there.x += llCos(i);    there.y += llSin(i);
doesn't work either.

circle1_cam()
{
    llOwnerSay("Circle1"); // say function name for debugging
    llClearCameraParams(); // reset camera to defaul
        float i;
        for(i = 0.0; i< 6; i+=1)
        {  
vector xyz = < llCos(i), llSin(i), 0.0>;
vector here = llGetPos();
vector there = llGetPos();  there.x += llCos(i);    there.y += llSin(i);
     llOwnerSay("when I add" + (string) xyz);  
     llOwnerSay("camera moves to" + (string)there);
llSetCameraParams([
    CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
    CAMERA_BEHINDNESS_ANGLE,00.0, // (0 to 180) degrees
    CAMERA_BEHINDNESS_LAG, 180.0, // (0 to 3) seconds
    CAMERA_DISTANCE, 1, // ( 0.5 to 10) meters
    CAMERA_FOCUS,here, // region relative position
    CAMERA_FOCUS_LAG, 0.1, // (0 to 3) seconds
    CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
    CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
    CAMERA_PITCH, 0.0, // (-45 to 80) degrees
    CAMERA_POSITION, there, //REVOLVE!!
    CAMERA_POSITION_LAG, 0.1, // (0 to 3) seconds
    CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE)
    CAMERA_POSITION_THRESHOLD, 1.0, // (0 to 4) meters
    CAMERA_FOCUS_OFFSET, <0.0, 0.0, 0.0> // <-10,-10,-10> to <10,10,10> meters
            ]);
     llOwnerSay("So, now it's at" +  (string)there);
        }
} 
        

 



Please, how do I get these coordinates to add up?!

Thanks,

_______FOLLOW  UP _________15Jan_____________

Thanks MartinRJ,
(Rolig - I'll post in LSL Scripting forum next time. Just thought I'd continue the thread here.)

Your I picked apart your example and got mine working - thanks to your posting.
But, as you see, I'm keen on sin and cos, so I hope you aren't offended. :-)

But now I'm stuck. I'd like to circle at face level but my code - FaceCircle() -

    integer CHANNEL; // dialog channel
list MENU_MAIN = ["Me", "Waist", "WaistCircle", "BodyCircle", "FaceCircle", "More...", "Cam ON", "Cam OFF"]; // the main menu
list MENU_2 = ["More...", "...Back"]; // menu 2
integer on = FALSE;
integer trap = 0;

take_camera_control(key agent)
{
    llOwnerSay("take_camera_control"); // say function name for debugging
    llOwnerSay( (string)agent);
    llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
    llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
    on = TRUE;
}

release_camera_control(key agent)
{
    llOwnerSay("release_camera_control"); // say function name for debugging
    llSetCameraParams([CAMERA_ACTIVE, 0]); // 1 is active, 0 is inactive
    llReleaseCamera(agent);
    on = FALSE;
}
me000()
{
    llOwnerSay("ME_0,0,0"); // say function name for debugging
      llClearCameraParams(); // reset camera to default
    vector here = llGetPos();
    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, here, // 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_PITCH, 0.0, // (-45 to 80) degrees
        CAMERA_POSITION, here + <0,0,0>, //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 // <X0,X0,X0> to <10,10,10> meters
    ]);
 llSleep(0.002);
}

me010()
{
    llOwnerSay("Waist"); // say function name for debugging
      llClearCameraParams(); // reset camera to default
    vector here = llGetPos();
    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, here, // 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_PITCH, 0.0, // (-45 to 80) degrees
        CAMERA_POSITION, here + <0,1,0>, //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 // <X0,X0,X0> to <10,10,10> meters
    ]);
 llSleep(0.002);
}


WaistCircle()
{
llOwnerSay("WaistCircle"); // say function name for debugging
llClearCameraParams(); // reset camera to default
float i; 
for (i = 0; i < TWO_PI; i+=0.01)
{
vector xyz = 1.0*< llCos(i), llSin(i), 0>;
vector here = llGetPos();
vector there = llGetPos() + xyz;
llSetCameraParams([
CAMERA_ACTIVE, 1,
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_FOCUS, here,
CAMERA_POSITION, there,  
CAMERA_POSITION_LAG, 3.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE
]);
}
 llSleep(0.002);
}

BodyCircle()
{
llOwnerSay("BodyCircle"); // say function name for debugging
llClearCameraParams(); // reset camera to default
float i; 
for (i = 0; i < TWO_PI; i+=0.01)
{
vector xyz = 3*< llCos(i), llSin(i), 0>;
vector here = llGetPos();
vector there = llGetPos() + xyz;
llSetCameraParams([
CAMERA_ACTIVE, 1,
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_FOCUS, here,
CAMERA_POSITION, there,  
CAMERA_POSITION_LAG, 3.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE
]);
}
 llSleep(0.002);
}

FaceCircle()
{
llOwnerSay("FaceCircle"); // say function name for debugging
llClearCameraParams(); // reset camera to default
float i; 
for (i = 0; i < TWO_PI; i+=0.01)
{
vector xyz = < llCos(i), llSin(i), 0>;//orbit equation
vector here = llGetPos() + <0,0,1>;//stare at top of head (+1)
vector there =llGetPos() + xyz + <0,0,1>;//as camera follows this orbit
llSetCameraParams([
CAMERA_ACTIVE, 1,
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_FOCUS, here,
CAMERA_POSITION, there , //REGION RELATIVE POSITION
CAMERA_POSITION_LAG, 3.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE
]);
}
 llSleep(0.002);
}
 
setup_listen()
{
    llListenRemove(1);
    CHANNEL = llRound(llFrand(1) * 100000);
    integer x = llListen(CHANNEL, "", "", ""); // listen for dialog answers
}

default
{
    state_entry()
    {
        setup_listen();
        llSetTimerEvent(2);
    }
   
    touch_start(integer total_number)
    {
integer perm = llGetPermissions();
if (perm & PERMISSION_DEBIT)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_DEBIT perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TAKE_CONTROLS)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TAKE_CONTROLS perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TRIGGER_ANIMATION)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TRIGGER_ANIMATION perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_ATTACH)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_ATTACH perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_CHANGE_LINKS)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_CHANGE_LINKS perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TRACK_CAMERA)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TRACK_CAMERA perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_CONTROL_CAMERA)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_CONTROL_CAMERA perms for "+(string)llGetPermissionsKey()); }
if (perm == 0)
{ llOwnerSay(llGetScriptName() + " has NO perms for "+(string)llGetPermissionsKey()); }

        llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
    }
   
    listen(integer channel, string name, key id, string message)
    {
        if (llListFindList(MENU_MAIN + MENU_2, [message]) != -1)  // verify dialog choice
//        if (llListFindList(MENU_MAIN, [message]) != X)  // verify dialog choice
        {
//            llOwnerSay(name + " picked the option '" + message + "'."); // output the answer
            if (message == "More...")
                llDialog(id, "Pick an option!", MENU_2, CHANNEL); // present submenu on request
            else if (message == "...Back")
                llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back

    else if (message == "Cam ON")
    {
        take_camera_control(id);
    }

    else if (message == "Cam OFF")
    {
        release_camera_control(id);
    }
        else if (message == "Me")
    {
        me000();
    }
    else if (message == "Waist")
    {
        me010();
    }
    else if (message == "WaistCircle")
    {
        WaistCircle();
    }
    else if (message == "BodyCircle")
    {
        BodyCircle();
    }
    else if (message == "FaceCircle")
    {
        FaceCircle();
    }

    else if (message == "Trap Toggle")
    {
        trap = !trap;
        if (trap == 1) {
            llOwnerSay("trap is on");
        }
        else {
            llOwnerSay("trap is off");
        }       
    }

        } else
            llOwnerSay(name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
    }

    run_time_permissions(integer perm) {
        if ((perm & PERMISSION_CONTROL_CAMERA) == PERMISSION_CONTROL_CAMERA) {
            llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
            llOwnerSay("Camera permissions have been taken");
        }
    }
   
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key agent = llAvatarOnSitTarget();
            if (agent)
            {
                setup_listen();
                llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
            }
        }
    }
   
    attach(key agent)
    {
        if (agent != NULL_KEY)
        {
            setup_listen();
            llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
        }
    }
   
    timer()
    {
        if (trap == 1)
        {
            me000();
        }       
    }
   
}    

 

makes the cameraa follow a tilted orbit - as if the center isn't centred.
Any suggestion why it doesn't work up the z-axis? Or how to fix it?

Thanks

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello,

I scripted an example for you.

Just put it into a new prim, then sit on the prim (press the Escape key if you don't see any change immediately, if the camera is still locked):

 

rotate_cam(){    integer iDegree;    for (iDegree = 0; iDegree < 360; iDegree++)    {                rotation vRotArc       = llEuler2Rot( <0.0, 0.0, iDegree> * DEG_TO_RAD ); //-- creates a rotation constant, n degrees around the X axis         vector   vPosOffset     = <0.0, 1.0, 0.0>; //-- creates an offset one meter in the positive Y direction         vector   vPosRotOffset  = vPosOffset * vRotArc; //-- rotates the offset to get the motion caused by the rotation         llSetCameraParams([            CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive            CAMERA_FOCUS, llGetPos(), // region relative position            CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)            CAMERA_POSITION, llGetPos() + (vPosOffset * vRotArc), // region relative position            CAMERA_POSITION_LOCKED, TRUE // (TRUE or FALSE)        ]);        llSleep(0.002);    }    llClearCameraParams();    llUnSit(llAvatarOnSitTarget());}default{    state_entry()    {        llSitTarget(<0.0,0.0,0.5>,ZERO_ROTATION);    }    changed(integer change)    {        if (change & CHANGED_LINK && llAvatarOnSitTarget() != NULL_KEY)        {            llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_CONTROL_CAMERA);        }    }    run_time_permissions(integer perm)    {        if (perm & PERMISSION_CONTROL_CAMERA)        {            rotate_cam();        }    }}

 You can IM me with questions in-world.

 

ETA

I used the code from here:

https://wiki.secondlife.com/wiki/Rotation

https://wiki.secondlife.com/wiki/LlSetCameraParams

  • Like 2
Link to comment
Share on other sites

  • 0

Just so you know, the best place to post a question like this is the LSL Scripting forum.  That's what it's there for.  Martin and I can answer scripting questions here, but there are many more scripters over there.  They will not only give you a broader selection of answers, they can learn from your challenge too.  Scripters are a puzzle-solving community.  :smileyvery-happy:

Link to comment
Share on other sites

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