// ZoomIn Include File // April 25, 2002 - May 11, 2002 // Created by John Haggerty. // http://www.slimeland.com/ // zoomin.inc allows you to take the command line string created when // shift-clicking and dragging on the display window in the Windows // interface, and pass it to a macro, causing the camera to actually // zoom in on that part of the image at the same resolution currently // being used. This makes it easier to check details in parts of a render // with a higher resolution. // You can only use zoomin.inc with the perspective camera. (Currently.) // When using zoomin.inc, be sure not to actually include the extra // command-line parameters that POV-Ray generates. Cut them out of the // command-line box and paste them into a string parameter to these macros // as shown below. // When using zoomin.inc, if you have more than two objects in your scene, // YOU MUST INCLUDE "-UV" IN YOUR COMMAND LINE or "Vista_Buffer=off" in an ini // file in order to avoid an error about vista buffering with // non-perpendicular camera vectors. This will slightly slow down the render, // but it is your only choice if you want to use this include file. // You will comply. // --------------------------------------------------------------------------- // Available macros: // Set_Zoom_Area(CameraLocation, CameraLookAt, CommandLineParameters) // This begins the zooming. CommandLineParameters should be cut and pasted // from the command line after shift-clicking and dragging an area on the // display window. // Set_Zoom_Area_ScreenInc(CommandLineParameters) // This is the same as Set_Zoom_Area, except that if you're using // "screen.inc", distributed with POV-Ray 3.5, it makes use of the camera // that you've already set up, and you don't have to give it the camera's // location or look_at point. // Zoom_Again(CommandLineParameters) // If you've already zoomed, and you want to shift-click and drag another // area on the display window, you can use this to zoom in again to the new // area. // Magnify_Zoom(Magnification) // This magnifies the zoom by the specified amount. Magnifying by one has // no effect. Magnifying by zero is illegal. Theoretically, magnifying by // a negative amount should invert the view, although this has not been // thoroughly tested. // Move_Zoom(XAmount, YAmount) // This lets you change the area of your original scene that you're looking // at. Setting XAmount to one, for instance, will create an image that will // fit just to the right of the image that you had before calling this macro. // Positive values move to the right and up, negative values to the left // and down. // Update_Camera_Zoom() // Once you're finished setting the zoom, call this, and the camera will // actually zoom. If you don't call this function, nothing about your scene // will actually change. // IMPORTANT: If you're using screen.inc, make sure all these functions // occur *AFTER* the screen.inc functions. I reccommend you place these // functions at the very end of your scene file. // --------------------------------------------------------------------------- // Available settings: // (All are optional. set these with #declare before calling Set_Zoom_Area or // Set_Zoom_Area_ScreenInc) // ZoomIn_AssumedImageWidth, ZoomIn_AssumedImageHeight // If you specify the command line arguments manually in *integers*, as // is explained in the POV-Ray documentation under // "5.2.2.1.2 Partial Output Options", and you're rendering the zoomed // image at a different resolution than you selected the integer values at, // then be sure to set these variables to the resolution at which you // specified the integer values. // ZoomIn_AssumedCameraAspectRatio, ZoomIn_AssumedCameraAngle, // ZoomIn_AssumedCameraSky // If you're not using screen.inc, then use these three variables to set // extra information about your camera that isn't passed to Set_Zoom_Area. // If you want easier control over your camera, you will have to use // screen.inc, although these three variables plus the two arguments to // Set_Zoom_Area really do give you complete control over the camera. // ZoomIn_MaintainAspectRatioWhenZooming // If you shift-click and drag an area that doesn't match the aspect ratio // of your scene, (for instance, you select a tall rectangular area in a 4:3 // aspect ratio scene), normally the area you selected will be expanded // in such a way that you can see everything you zoomed to, and it will look // the same as though you just looked close up at your original 4:3 image. // If you want to allow your zooming to distort the aspect ratio, set this // variable to no (zero). // --------------------------------------------------------------------------- // Sample usage: // #declare camera_location = -z*10; // #declare camera_look_at = <0,0,0>; // Set_Zoom_Area(camera_location, camera_look_at, "+sc0.385519 +sr0.302872 +ec0.600783 +er0.600522") // this must be first // Magnify_Zoom(2) // zoom in by 2x // Move_Zoom(.5,.1) // move to the right by half the current zoom area, move up by 1/10 the current zoom area // Magnify_Zoom(1/3) // zoom out by 3x // Zoom_Again("+sc0.1 +sr0.3 +ec0.6 +er0.7") // zoom into this section of the current zoom area // Update_Camera_Zoom() // this finalizes the zooming and actually changes the camera declaration. // --------------------------------------------------------------------------- #ifndef(ZoomIn_Inc_Temp) // if include file has already been included, do nothing #declare ZoomIn_Inc_Temp = version; #ifdef(View_POV_Include_Stack) #debug "including zoomin.inc\n" #end #version 3.5; // the following two variables are used when one of the command-line // arguments are greater than one, meaning they're in pixel values // rather than percentages: #declare ZoomIn_AssumedImageWidth = image_width; #declare ZoomIn_AssumedImageHeight = image_height; #declare ZoomIn_AssumedCameraAspectRatio = 4/3; #declare ZoomIn_AssumedCameraAngle = atan(2/3)/pi*180*2; #declare ZoomIn_AssumedCameraSky = y; #declare ZoomIn_MaintainAspectRatioWhenZooming = yes; // example string for ComLineParams: "+sc0.385519 +sr0.302872 +ec0.600783 +er0.600522" #macro Set_Zoom_Area(Location, LookAt, ComLineParams) #local Location = Location*<1,1,1>; #local LookAt = LookAt*<1,1,1>; #declare ZoomIn_AssumedCameraSky = ZoomIn_AssumedCameraSky*<1,1,1>; ZoomIn_ParseComLineParams(ComLineParams) #if (ZoomIn_CheckZooms()) #local camerazoom = ZoomIn_AssumedCameraAspectRatio/tan(radians(ZoomIn_AssumedCameraAngle/2)); #local cdirection = vnormalize(LookAt-Location)*camerazoom; #local cright = vnormalize(vcross(ZoomIn_AssumedCameraSky, cdirection))*ZoomIn_AssumedCameraAspectRatio; #local cup = vnormalize(vcross(cdirection, cright)); #declare ZoomIn_CameraExtraTransform = transform { // transform to correct position matrix < cright.x, cright.y, cright.z, cup.x, cup.y, cup.z, cdirection.x, cdirection.y, cdirection.z, Location.x, Location.y, Location.z > } #declare ZoomIn_ZoomStarted = yes; #end #end #macro Set_Zoom_Area_ScreenInc(ComLineParams) #ifndef(Screen_Inc_Temp) #error "You cannot use Set_Zoom_Area_ScreenInc because screen.inc has not been included. Use Set_Zoom_Area instead." #end #declare ZoomIn_AssumedCameraSky = ZoomIn_AssumedCameraSky*<1,1,1>; ZoomIn_ParseComLineParams(ComLineParams) #if (ZoomIn_CheckZooms()) #ifndef(Camera_Transform) Update_Camera() #end #declare ZoomIn_CameraExtraTransform = transform { scale transform Camera_Transform } #declare ZoomIn_ZoomStarted = yes; #end #end #macro ZoomIn_ParseComLineParams(ComLineParams) #declare ZoomIn_ZoomLeft = -1; #declare ZoomIn_ZoomRight = 1; #declare ZoomIn_ZoomTop = 1; #declare ZoomIn_ZoomBtm = -1; #local ComLineParams = strlwr(ComLineParams); #if (strcmp(ComLineParams, "fullview") != 0 & strcmp(ComLineParams, "full view") != 0) #local strpos = 1; #local endat = strlen(ComLineParams); #while(strpos <= endat - 2) #local ministr = substr(ComLineParams, strpos, 2); #if (strcmp(ministr,"sc") = 0 | strcmp(ministr,"ec") = 0 | strcmp(ministr,"sr") = 0 | strcmp(ministr,"er") = 0) #local strpos = strpos + 2; #local numstr = ""; #local docontinue = yes; #while (strpos <= endat & docontinue) #if (strcmp(substr(ComLineParams, strpos, 1), " ") != 0) #local numstr = concat(numstr, substr(ComLineParams, strpos, 1)); #local strpos = strpos + 1; #else #local docontinue = no; // break #end #end // numstr is now the number corresponding to this command #local amnt = val(numstr); #if (amnt > 1) #if (strcmp(ministr,"sc") = 0 | strcmp(ministr,"ec") = 0) // horizontal #local amnt = amnt/ZoomIn_AssumedImageWidth; #else #local amnt = amnt/ZoomIn_AssumedImageHeight; #end #end #if (strcmp(ministr,"sc") = 0) #declare ZoomIn_ZoomLeft = amnt*2-1; #else #if (strcmp(ministr,"ec") = 0) #declare ZoomIn_ZoomRight = amnt*2-1; #else #if (strcmp(ministr,"sr") = 0) #declare ZoomIn_ZoomTop = 1-amnt*2; #else #if (strcmp(ministr,"er") = 0) #declare ZoomIn_ZoomBtm = 1-amnt*2; #end #end #end #end #end #local strpos = strpos + 1; #end #end #end #macro ZoomIn_CheckZooms() #local toreturn = 1; #if (ZoomIn_ZoomRight = ZoomIn_ZoomLeft | ZoomIn_ZoomTop = ZoomIn_ZoomBtm) #warning "Cannot zoom to the area specified -" #debug " either the left and right sides of the zoom area are equal, or the top and bottom sides are equal.\n" #local toreturn = 0; #else #if (ZoomIn_MaintainAspectRatioWhenZooming) #local curwidth = abs(ZoomIn_ZoomRight-ZoomIn_ZoomLeft); #local curheight = abs(ZoomIn_ZoomTop-ZoomIn_ZoomBtm); #local zoomaspectratio = curwidth/curheight; #if (zoomaspectratio > 1) #local amnt = (curheight/(ZoomIn_ZoomTop-ZoomIn_ZoomBtm)) * (curwidth - curheight)/2; #declare ZoomIn_ZoomTop = ZoomIn_ZoomTop + amnt; #declare ZoomIn_ZoomBtm = ZoomIn_ZoomBtm - amnt; #local amnt = amnt/(ZoomIn_ZoomTop-ZoomIn_ZoomBtm); // this warning is too difficult to implement with the possibility of the user running Zoom_Again(). /*#warning "Since ZoomIn_MaintainAspectRatioWhenZooming is set to 'yes', more than just the area you selected will be shown." #debug " In order to view just the area you selected, either set ZoomIn_MaintainAspectRatioWhenZooming to false before\n" #debug " running Set_Zoom_Area, or use the command line settings\n" #debug concat(" \"+sc0 +sr", str(amnt,-7,5), " +ec0 +er", str(1-amnt,-7,5) , "\" for this render.\n") #debug " (Note: actually use them in the command-line, not in the Set_Zoom_Area macro.\n"*/ #else #if (zoomaspectratio < 1) #local amnt = (curwidth/(ZoomIn_ZoomRight-ZoomIn_ZoomLeft)) * (curheight - curwidth)/2; #declare ZoomIn_ZoomLeft = ZoomIn_ZoomLeft - amnt; #declare ZoomIn_ZoomRight = ZoomIn_ZoomRight + amnt; #local amnt = amnt/(ZoomIn_ZoomRight-ZoomIn_ZoomLeft); /*#warning "Since ZoomIn_MaintainAspectRatioWhenZooming is set to 'yes', more than just the area you selected will be shown." #debug " In order to view just the area you selected, either set ZoomIn_MaintainAspectRatioWhenZooming to false before\n" #debug " running Set_Zoom_Area, or use the command line settings\n" #debug concat(" \"+sc", str(amnt,-7,5), " +sr0 +ec", str(1-amnt,-7,5) , " +er0\" for this render.\n") #debug " (Note: actually use them in the command-line, not in the Set_Zoom_Area macro.)\n"*/ #end #end #end #end toreturn #end #macro ZoomIn_GetCameraTransform() matrix < (ZoomIn_ZoomRight-ZoomIn_ZoomLeft)/2,0,0, 0,(ZoomIn_ZoomTop-ZoomIn_ZoomBtm)/2,0, (ZoomIn_ZoomLeft+ZoomIn_ZoomRight)/2,(ZoomIn_ZoomTop+ZoomIn_ZoomBtm)/2,1, 0,0,0 > transform ZoomIn_CameraExtraTransform #end #macro Magnify_Zoom(magamnt) #ifndef(ZoomIn_ZoomStarted) #warning "Cannot magnify the zoom before Set_Zoom_Area or Set_Zoom_Area_ScreenInc has been called sucessfully. Zoom has not been magnified." #else #if (magamnt = 0) #warning "Cannot magnify the zoom by zero. Zoom has not been magnified." #else #if (magamnt != 1) #local centerpoint = <(ZoomIn_ZoomLeft+ZoomIn_ZoomRight)/2,(ZoomIn_ZoomTop+ZoomIn_ZoomBtm)/2,0>; #declare ZoomIn_ZoomLeft = centerpoint.x + (ZoomIn_ZoomLeft-centerpoint.x)/magamnt; #declare ZoomIn_ZoomRight = centerpoint.x + (ZoomIn_ZoomRight-centerpoint.x)/magamnt; #declare ZoomIn_ZoomTop = centerpoint.y + (ZoomIn_ZoomTop-centerpoint.y)/magamnt; #declare ZoomIn_ZoomBtm = centerpoint.y + (ZoomIn_ZoomBtm-centerpoint.y)/magamnt; #end #end #end #end #macro Move_Zoom(xamnt, yamnt) #ifndef(ZoomIn_ZoomStarted) #warning "Cannot move the zoom before Set_Zoom_Area or Set_Zoom_Area_ScreenInc has been called sucessfully. Zoom has not been moved." #else #if (xamnt != 0 & yamnt != 0) #local xdiff = ZoomIn_ZoomRight-ZoomIn_ZoomLeft; #local ydiff = ZoomIn_ZoomTop-ZoomIn_ZoomBtm; #declare ZoomIn_ZoomLeft = ZoomIn_ZoomLeft + xdiff*xamnt; #declare ZoomIn_ZoomRight = ZoomIn_ZoomRight + xdiff*xamnt; #declare ZoomIn_ZoomTop = ZoomIn_ZoomTop + ydiff*yamnt; #declare ZoomIn_ZoomBtm = ZoomIn_ZoomBtm + ydiff*yamnt; #end #end #end #macro Zoom_Again(ComLineParams) #local zoomleft = ZoomIn_ZoomLeft; #local zoomright = ZoomIn_ZoomRight; #local zoomtop = ZoomIn_ZoomTop; #local zoombtm = ZoomIn_ZoomBtm; ZoomIn_ParseComLineParams(ComLineParams) #if (ZoomIn_CheckZooms()) #local centerpoint = <(zoomleft+zoomright)/2,(zoomtop+zoombtm)/2,0>; #local span = <(zoomright-zoomleft)/2,(zoomtop-zoombtm)/2,0>; #declare ZoomIn_ZoomLeft = centerpoint.x + span.x*ZoomIn_ZoomLeft; #declare ZoomIn_ZoomRight = centerpoint.x + span.x*ZoomIn_ZoomRight; #declare ZoomIn_ZoomTop = centerpoint.y + span.y*ZoomIn_ZoomTop; #declare ZoomIn_ZoomBtm = centerpoint.y + span.y*ZoomIn_ZoomBtm; #end #end #macro Update_Camera_Zoom() #ifndef(ZoomIn_ZoomStarted) #error "Cannot update the camera before Set_Zoom_Area or Set_Zoom_Area_ScreenInc has been called sucessfully." #else camera { location 0 sky y up y right x direction z/2 ZoomIn_GetCameraTransform() } #end #end #version ZoomIn_Inc_Temp; #end