I created a basic sphere, and I have an image with roughly a 2:1 aspect ratio that I'm using as a texture. The actual image is a client's logo, so the PNG of the UK flag is a stand in. Using the basic sphere demo code and applying the (scaled) image as a texture:
#include "colors.inc"
camera {
sky <0,0,1>
direction <-1,0,0>
right <-4/3,0,0>
location <30,10,1.5>
look_at <0,0,0>
angle 15
}
global_settings { ambient_light White }
light_source {
<10,-20,10>
color White*2
}
background { color White }
plane { <0,0,1>, 0 pigment {White} }
sphere {
<0, 0, 1>,
1 texture {
pigment {
image_map { png "flag.png" map_type 1 }
scale <0.1, 0.1, 0.1>
}
}
}
yields a sphere with the image distorted and, to my eye, off center:
I'm having trouble describing exactly what I expected, but I guess I expected the center of the Saint George's Cross to be dead center on the front of the sphere, directly facing the camera.
First, move the sphere back to the origin so that it could be safely rotated. Second, use the VAngleD()
function from math.inc
to compute the angle between the camera's position and the direction that the pattern is applied in. Finally, rotate the sphere by this angle and translate it back to the original location. Now, the pattern's central point will always be facing the camera regardless of the latter's position within the XY plane. You can add similar calculations to mitigate the camera's translation along the Z axis as well.
#include "colors.inc"
#include "math.inc"
#declare SPHERE_LOCATION = <0, 0, 1>;
#declare CAMERA_POSITION = <30, 10, 1.5>;
#declare PATTERN_DIRECTION = x;
camera {
sky <0,0,1>
direction <-1,0,0>
right <-4/3,0,0>
location CAMERA_POSITION
look_at SPHERE_LOCATION
angle 15
}
global_settings { ambient_light White }
light_source {
<10,-20,10>
color White*2
}
background { color White }
plane { <0,0,1>, 0 pigment {White} }
sphere {
0,
1 texture {
pigment {
image_map { png "flag.png" map_type 1}
}
}
rotate z * (180 + VAngleD(CAMERA_POSITION, PATTERN_DIRECTION))
translate SPHERE_LOCATION
}