// Wiggle Stereoscopy HUD // (Parallel Version) // by // Moriash Moreau, 5/26/07 // // You may this script for whatever purpose you like, provided it's legal // and doesn't violate the SL TOS. Be excellent to each other. Party on. // This script will attempt to create an on-the-fly "wiggle stereoscopy" 3D effect. // This effect can often give the illusion of 3D images. See the following links for more info: // http://3dculture.com/occ/Panoram_time4space_wiggle.htm // http://en.wikipedia.org/wiki/Stereoscopy#Wiggle_stereoscopy // (Note that I have nothing to do with this website.) // INSTRUCTIONS // Put this script in a HUD object. // Position your client camera as desired. Touch the HUD to toggle the // camera swapping/wobbling on and off. Use the Strafe keys to adjust offset between images. float Offset = 0.3; // The starting offset between left eye and right eye view, in meters. // Not that there's an easy way to determine distances by looking, but // a good rule of thumb is 1 meter for every 30 meters to the target // object. float Step = 0.025; // The step size for each offset adjustment, in meters. Also the minimum offset. float Delay = 0.15; // Pause between left and right eye image. 0.15 to 0.2 seconds seems about right. // INTERNAL VARIABLES vector OffPos = <0,0.5,0>; // Offset the camera left and right by half the offset distance. Don't change. integer Toggle; // Is the wiggle cam on or off? vector CamPos; // The position of the camera when we start wiggling. We will move 1/2 offset to each side. rotation CamRot; // The rotation of the camera at start. Used to calculate offset positions. vector CamFoc; // A point along the line between camera and camera focus. We can use this to reproduce // The camera's orientation- basically defines two points on the line between camera // and focus. We have to do this, because there's no way to get the location of // the actual camera focus. integer Controls; // The controls we want to monitor. vector CurrOffset; // The current offset distance, calc'd on the fly. // Ask for permission to take controls. Go into standby. Init() { Toggle = FALSE; llSetColor(<1,0,0>,ALL_SIDES); llSetAlpha(1.0,ALL_SIDES); llSetTimerEvent(0); llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA | PERMISSION_TAKE_CONTROLS); } // Toggle the camera wiggle on and off. CamToggle() { // If it's on, turn it off. Change color and alpha of HUD, release the camera, stop // monitoring the controls. Go back into standby. if (Toggle) { llClearCameraParams(); llSetAlpha(1.0,ALL_SIDES); llSetColor(<1,0,0>,ALL_SIDES); llOwnerSay("Stopping wiggle camera."); Toggle = FALSE; llSetTimerEvent(0); llTakeControls(Controls, FALSE, TRUE); } // If it's off, turn it on. Change HUD color and make transparent. Get the current // camera position. Monitor our controls. Start the timer and move the camera into place. else { Toggle = TRUE; llSetAlpha(0.1,ALL_SIDES); llSetColor(<0,1,0>,ALL_SIDES); CamPos = llGetCameraPos(); CamRot = llGetCameraRot(); CamFoc = CamPos + llRot2Fwd(CamRot); llTakeControls(Controls, TRUE, FALSE); llOwnerSay("Starting wiggle camera. You may need to press \"ESC\" to release current camera view."); llSetTimerEvent(Delay); SetCam(); } } // This is called each tick. Flip the camera from right to left by offset distance. Keep its focal point // locked on the original position. Have to do some rotations work to determine "left" and "right" // relative to the starting camera position and rotation. SetCam() { OffPos = OffPos * -1; CurrOffset = Offset * (OffPos * CamRot); llSetCameraParams([ CAMERA_ACTIVE, TRUE, CAMERA_FOCUS, CamFoc + CurrOffset, CAMERA_FOCUS_LOCKED, TRUE, CAMERA_POSITION, CamPos + CurrOffset, CAMERA_POSITION_LOCKED, TRUE ]); } default { // Define which controls we want, initialize the camera controls. state_entry() { Controls = CONTROL_LEFT | CONTROL_RIGHT; Init(); } // Tick! Flip the camera. timer() { if (Toggle) { SetCam(); } } // Monitor the controls. If we Shift-Right, increase the Offset by Step. // If Shift-Left, decrease it. control(key id, integer level, integer edge) { if (edge & level & CONTROL_RIGHT) { Offset = Offset + Step; llOwnerSay("Increasing offset to " + (string)Offset + " meters."); } else if (edge & level & CONTROL_LEFT) { Offset = Offset - Step; if (Offset <= Step) // Keep mininum offset at Step. { Offset = Step; } llOwnerSay("Decreasing offset to " + (string)Offset + " meters."); } } attach(key id) { // If we're detaching, clear the camera, stop ticking. if (id == NULL_KEY) { llSetTimerEvent(0); if (llGetPermissions() & PERMISSION_CONTROL_CAMERA) { llClearCameraParams(); } } // If we're attaching, initialize the camera. else { Init(); } } // If we have permissions, which should be automatic on an attachment, give instructions. run_time_permissions(integer perm) { if (perm & PERMISSION_CONTROL_CAMERA | PERMISSION_TRACK_CAMERA | PERMISSION_TAKE_CONTROLS ) { llOwnerSay("Wiggle Camera enabled. Alt-click on the central subject, then touch the HUD to start/stop. Use Shift-Left and Shift-Right to adjust offset distance."); } } // Turn the wiggle camera on and off. touch_start(integer total_number) { CamToggle(); } }