【问题标题】:Texturing a sphere with an image so that it faces the camera使用图像对球体进行纹理处理,使其面向相机
【发布时间】:2021-04-04 22:49:50
【问题描述】:

我创建了一个基本球体,我有一个宽高比约为 2:1 的图像用作纹理。实际图像是客户的徽标,因此PNG of the UK flag 是一个替代品。使用基本球体演示代码并将(缩放的)图像应用为纹理:

#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>
        }
    }
}

产生一个图像扭曲的球体,在我看来,偏离中心:

我无法准确描述我的预期,但我想我认为圣乔治十字的中心是球体正面的死点,正对着相机。

【问题讨论】:

    标签: povray


    【解决方案1】:

    首先,将球体移回原点,使其可以安全旋转。其次,使用math.inc 中的VAngleD() 函数计算相机位置与应用图案的方向之间的角度。最后,将球体旋转该角度并将其平移回原始位置。现在,无论后者在 XY 平面内的位置如何,图案的中心点将始终面向相机。您也可以添加类似的计算来减轻相机沿 Z 轴的平移。

    #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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-29
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多