【问题标题】:triangle texture is rotating and flipping horizontally三角形纹理水平旋转和翻转
【发布时间】:2019-04-19 04:51:59
【问题描述】:

为班级编写光线追踪器,但我遇到了一个奇怪的问题,我似乎无法确定其来源。我有我的纹理,出于某种原因它顺时针旋转 90,然后水平翻转。我正在使用重心坐标来导航我的 uv 空间坐标。

我已经尝试过如何生成 u,v,w。但它似乎会导致同样的问题。

In program issue visible my actual test texture

//how i'm generating my barycentric coordinates:
Ph = Pe + Npe*Th; //Ph is the point in space that is being tested, I'm generating u,v,w while testing inside/outside triangle (Pe = Point of eye, Npe = vector from eye to point on triangle, Th = time hit)

        A = glm::cross(P1 - P0, P2 - P0);
        //glm::vec3 A0 = glm::cross(Ph - P1, Ph - P2);
        //glm::vec3 A1 = glm::cross(Ph - P2, Ph - P0);
        //glm::vec3 A2 = glm::cross(Ph - P0, Ph - P1);
        glm::vec3 A0 = glm::cross(P1-Ph, P2-Ph);
        glm::vec3 A1 = glm::cross(P2-Ph, P0-Ph);
        glm::vec3 A2 = glm::cross(P0-Ph, P1-Ph);

        if (glm::dot(n0, glm::normalize(A0)) < 0 || glm::dot(n0, glm::normalize(A1)) < 0 || glm::dot(n0, glm::normalize(A2)) < 0)
        {
            //point is outside triangle
            return -1;
        }


        //normalize and chec k dot products to detrmine if they are facing the right way.

        u = glm::length(A0) / glm::length(A);
        v = glm::length(A1) / glm::length(A);
        w = 1 - u - v;

然后这里是使用它来计算纹理坐标的部分。

//portion of code calculating texture coordinates
//calculate new location of texture coordinate, assume z position is 0
        glm::vec3 textureCo = P0TexCo*this->u + P1TexCo*this->v + P2TexCo*this->w;
        u = textureCo[0];
        v = textureCo[1];

【问题讨论】:

    标签: c++ raytracing


    【解决方案1】:

    发现了这个问题,它与 opengl 如何解释坐标以及它从哪个角开始显示数组中的像素有关。解决方案是在加载后反转图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-07
      • 2015-07-10
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      相关资源
      最近更新 更多