Jump to content

Getting region based Camera Co-ordinates


Loki Eliot
 Share

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

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

Recommended Posts

im trying to set up a series of cameras that focus on specific objects in relation to the region rather than the avatar but im having trouble figuring out how to get hold of region specific coordinates from my camera position in the region to use in my script.

Link to comment
Share on other sites

Ok i worked something out and it did not need llGetCameraPos just needed to llGetPos.

used two small spheres, each gets their region position. Red one gets camera position, green one gets camera focus point (where the camera should be looking at). And that was all i needed to do :-P

Thanx for the help though :)

Link to comment
Share on other sites

llGetCameraPos() returns your camera position in region coordinates
llGetCameraRot() returns the global rotation

To set the camera you need the camera position and a point for the camera to focus on
You already have the position.
The focus point can be found as: vector cameraFocus = llGetCameraPos() + llRot2Fwd(llGetCameraRot());

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

  • 1 year later...

i have an additional question: I want to set Camera to a special region based Camara Co-ordinates and then rotation turn to ground (use with a hud, not connected to a prim). I tried it with this one:

overhead_cam()
{
    llOwnerSay("overhead_cam_new"); // say function name for debugging
    default_cam();
    vector xyz = llGetPos();

// change to postition <234.5, 34.0, 26>   

        llOwnerSay("positionx " + (string) xyz.x);  // old positions
        llOwnerSay("positiony " + (string) xyz.y);
        llOwnerSay("positionz " + (string) xyz.z);
        
        if (xyz.x < 234.5)
        {
            xyz.x = 234.5 - xyz.x ;   // x + diff = newPos
            }
            else
            {
                xyz.x = (xyz.x - 234.5) * -1;  // x + (minusDiff) = newPos
        }
        if (xyz.y < 34.0)
        {
            xyz.y = 34.0 - xyz.y ;   // y + diff = newPos
            }
            else
            {
                xyz.y = (xyz.y - 34.0) * -1;  // y + (minusDiff) = newPos
        }
        if (xyz.z < 26)
        {
            xyz.z = 26 - xyz.z ;   // z + diff = newPos
            }
            else
            {
                xyz.z = (xyz.z - 26) * -1;  // z + (minusDiff) = newPos
        }
        
        xyz = llGetPos() + xyz ;
        llOwnerSay("positionx " + (string) xyz.x);   // new positions
        llOwnerSay("positiony " + (string) xyz.y);
        llOwnerSay("positionz " + (string) xyz.z);
 
    llSetCameraParams([
        CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
        CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
        CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
        CAMERA_DISTANCE, 3.0, // ( 0.5 to 10) meters
        //CAMERA_FOCUS, <0,0,5>, // region relative position
        CAMERA_FOCUS, xyz, // 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, 0.0, // (0 to 4) meters
        CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
    ]);
}

It sets the cam to the position i wish, but has following problems:

-1- screen is black after use button
-2- Rotation is still turned to avatar, not to ground
-3- camera_focus and  _position are same here, but i could not find other settings, that worked...

What can i do better?

Link to comment
Share on other sites

Camera focus and camera position are both set to the same value, xyz

This way the rotation is not determined and I understand you have no control of it

The camera should be in one position and focus on a different position

I may find other things if I give it more time

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

  • 2 weeks later...

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.

 

Link to comment
Share on other sites

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