【问题标题】:Finding theta and phi for spherical texture mapping寻找球面纹理映射的 theta 和 phi
【发布时间】:2011-11-15 06:57:05
【问题描述】:

对于一个学校项目,我需要为球形纹理贴图找到 theta 和 phi。许多用于纹理的实际 OpenGL 已经完成(附带启动代码)。入门代码提供了下面的函数和 cmets。代码是我到目前为止所做的(除了给定的 x 和 z 的初始化):

Vec3f sphere::getTextureCoords(Vec3f eye, Vec3f dir)
{
    // find the normal (getNormal)
    Vec3f n = this->getNormal(eye, dir);

    // use these to find spherical coordinates
    Vec3f x(1, 0, 0);
    Vec3f z(0, 0, 1);

    // phi is the angle down from z
    // theta is the angle from x curving toward y

    // find phi using the normal and z
    float phi = acos(n.Dot3(z));

    // find the x-y projection of the normal
    Vec3f proj(n.x(), n.y(), 0);

    // find theta using the x-y projection and x
    float theta = acos(proj.Dot3(x));

    // if x-y projection is in quadrant 3 or 4, then theta = 2PI - theta
    if (proj.y() < 0)
        theta = TWOPI - theta;

    Vec3f coords;
    coords.set(theta / TWOPI, phi / PI, 0);
    return coords;
}

按照 cmets 中的“说明”,这就是我想出的。纹理贴图不起作用(没有错误,坐标只是错误的)。 getNormal 函数可能无法正常工作,但我认为问题在于我对球坐标缺乏了解。请让我知道您认为是什么问题,谢谢!

【问题讨论】:

标签: c++ textures texture-mapping


【解决方案1】:

由于proj 未标准化,您会得到theta 的错误结果。

顺便说一句,您对 theta 和 phi 的命名是非常规的(一开始我很困惑)。通常与 z 的夹角称为 theta,在 x-y 平面的夹角称为 phi。

【讨论】:

  • 我明白了,谢谢。对不起,我就是这么命名的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-05
  • 2013-07-03
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
  • 1970-01-01
相关资源
最近更新 更多