POV-Ray : Newsgroups : povray.general : Background Image : Re: Background Image Server Time
1 Aug 2024 02:22:55 EDT (-0400)
  Re: Background Image  
From: Norbert Kern
Date: 29 Apr 2006 18:15:00
Message: <web.4453e2ee5ecbd4a9ee88888c0@news.povray.org>
Hi, use this code for the usual camera type.
You have to adapt the first lines and the name of the background image
to your scene.
If you use z direction as up, you have to change cam_s to z too.


//____________________________________________________________________________
#declare cam_loc = <0,1.5,-8>; // camera location
#declare lookat = <0,0.5,0>;   // camera look_at
#declare cam_ang = 67;         // camera angle
#declare back_dist = 1000;     // how far away the background should be
#declare cam_mirror = 1;       // 1 for normal / -1 for mirror image

#include "transforms.inc"
#declare cam_z = 0.5*image_width/image_height/tan (radians (cam_ang*0.5));
#declare cam_ang_up = degrees (2*atan2(0.5/cam_z,1));
#declare cam_a = cam_mirror*image_width/image_height;
#declare cam_s = y;
#declare cam_d = vnormalize (lookat-cam_loc);
#declare cam_r = vnormalize (vcross (cam_s,cam_d));
#declare cam_up = vnormalize (vcross (cam_d,cam_r));
#declare cam_dir = cam_d*cam_z;
#declare cam_right = cam_r*cam_a;

#declare fz = vlength (cam_dir);
#declare fx = vlength (cam_right)/2;
#declare fy = vlength (cam_up)/2;

#macro OrientZ (p1,p2,cs)          // looks like Reorient_trans macro!
        #local nz = vnormalize (p2-p1);
        #local nx = vnormalize (vcross (cs,nz));
        #local ny = vcross (nz,nx);
        matrix <nx.x,nx.y,nx.z,ny.x,ny.y,ny.z,nz.x,nz.y,nz.z,p1.x,p1.y,p1.z>
#end

camera {
        location cam_loc
        up cam_up
        right cam_right
        direction cam_dir
}
/*
camera {                        // equivalent camera definition
        location cam_loc
        right cam_right
        look_at lookat
        angle cam_ang
}
*/
//_background________________________________________________________________

box {
        <0,0,0> <1,1,0.1>
        texture {
                pigment {
                        image_map {png "sky" once map_type 0 interpolate 2}
                }
                finish {ambient 1 diffuse 0}
        }
        translate <-0.5,-0.5,0>
        scale 2*<cam_mirror*fx,fy,0.5>
        translate fz*z
        scale back_dist
        OrientZ (cam_loc,lookat,cam_up)
}
//______________________________________________________________________________


Regards
Norbert Kern


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.