10-04-2007 11:50
I'm trying to write a scipt that takes the current camera postion and converts it to cameraEye and cameraAt vectors for an object. Sometimes it works, sometimes it doesn't. Sometimes it seems to record the reverse angle of what I want. I know I'm probably missing some rotation I'm supposed to apply or something but not sure which and where. Here is the code that does the conversion:

setCamera()
{
llRequestPermissions(gOwnerKey,PERMISSION_TRACK_CAMERA);
vector CAMERA_OFFSET = <2,0,0>; // Position camera eye 2m past object.
vector cameraPos = llGetCameraPos();
rotation cameraRot = llGetCameraRot();
vector objectPos = llGetPos();
if (cameraPos == <0,0,0> )
{
llSay(0,"permission denied";);
return;
}
gCameraEye = cameraPos - objectPos; //get local vector for camera pos.
gCameraAt = (cameraPos + CAMERA_OFFSET * cameraRot) - cameraPos;
llSay (0, (string) gCameraAt + (string) gCameraEye + (string) cameraPos + (string) cameraRot);
llSetCameraAtOffset(gCameraAt);
llSetCameraEyeOffset(gCameraEye);
}

Thanks in advance for your help