/* * stereocam.inc - Stereo camera include file (written for POVRay-3.5). * Version: 1.0 * * Copyright (c) 04/2004 by Wolfgang WIESER (wwieser@gmx.de) * * This file may be used in any scenes provided that credit is given * where credit is due. *------------------------------------------------------------------------------ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * NOTE: * This applies espcially to the stereoscopic cameras. The author is not * liable for any damage caused by (improper) use or abuse of these cameras, * including, but not limited to, headache, eye strain, falling apart, * eye accomodation disorder, psychical instability, insomnia as well as * loss of color perception, depth feeling or orientation. * */ /*----------------------------------------------------------------------*\ Stereo camera usage info: Simply #include this file and set up a camera using e.g.: camera { // Primary camera: must be first. WWStereoCam( +1, 0.065, 45, 1.2, -1 ) // Add transformations if you like: rotate 45*y translate 100*x } But be warned: Setting up a good stereoscopic camera is not easy. \*----------------------------------------------------------------------*/ #ifndef(_WWIESER_STEREO_CAMERA_INC_) #declare _WWIESER_STEREO_CAMERA_INC_=1; // Compute virew angle from distance d and size s; result is in degrees. #macro GetViewAngle(d,s) ( 2*atan(s/(2*d)) *180/pi ) #end // Stereo camera with stereo window and compensation for non-perpendicular // viewing methods. // Paramerers: // side: Which side: -1 -> left; +1 -> right; 0 -> center (no stereo) // e_: Eye distance in POV units (0.065m) // alpha_: Viewing angle in degrees; can use GetViewAngle() // f_: Eye ray cross distance = stereo window distance; 0 for infinity // Location and direction: // The camera will be set up at location 0 with primary direction +z // and primary right and up being +x and +y, respectively. // Rotate and translate afterwards to fit your needs. But DO NOT SCALE IT // unless you know what you are doing. // NOTE: The camera will normally no longer have perpendicular vectors and // hence you need to pass -UV to POVRay to switch off the vista buffer. // When viewing at it, the eye needs to adopt convergence angle for // different depths. #macro WWStereoCam( side, e_, alpha_, f_ ) // prim_loc: location of the (non-stereoscopic) camera: #local prim_loc=<0,0,0>; // prim_dir, prim_right, prim_up: normalized vectors; // The following math should work for z,x,y (in this order); all // other settings are untested; note that changing the directions // (dir,right,up) from cyclic to anti-cyclic or changing their // sign will change the sideness of the camera. #local prim_dir=z; #local prim_right=x; #local prim_up=y; // Perform aspect correction: #local Aspect = image_height/image_width; #local prim_up = prim_up *pow(Aspect, .5 ); #local prim_right = prim_right/pow(Aspect, 1- .5 ); // Convert angle to radians: #local alpha_ = alpha_*pi/180; // Camera moves along right vector for different sides: #local cam_loc = prim_loc + side * 0.5*e_*vnormalize(prim_right); // Camera direction: right eye looks left and left eye right so that // the rays cross at the stereo window, i.e. at distance f_ from // the camera. #if(f_) #local cam_dir = (prim_dir - side * e_/(2*f_)*vnormalize(prim_right)); #else #local cam_dir = prim_dir; #end // Apply appropriate scaling: #local cam_dir = cam_dir / (2*tan(0.5*alpha_)); // At least the right and up vectors are easy... #local cam_right=prim_right; #local cam_up=prim_up; // Here comes the camera def: perspective location cam_loc direction cam_dir right cam_right up cam_up // Make look_at work properly: sky cam_up // actually a no-op since cam_up=prim_up=y = default sky #end #end /* _WWIESER_STEREO_CAMERA_INC_ */