c++ - 三角形纹理水平旋转和翻转
问题描述
为课堂编写光线追踪器,我遇到了一个奇怪的问题,我似乎无法确定其来源。我有我的纹理,出于某种原因,它顺时针旋转 90,然后水平翻转。我正在使用重心坐标来导航我的 uv 空间坐标。
我已经尝试过如何生成 u,v,w。但它似乎导致了同样的问题。
//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];
解决方案
发现了这个问题,它与opengl如何解释坐标以及它从哪个角开始显示数组中的像素有关。解决方案是在加载图像后反转图像。
推荐阅读
- javascript - 通过变量引用 DOM 元素
- phpstorm - PhpStorm 每 20 分钟崩溃一次
- bash - 如何从 Bash Mac 查找中排除包文件(目录)?
- kubernetes - 新 GKE 集群上的 DNS 可能会出现问题
- userdefaults - 如何在 userdefault 中保存已检查的 tableview 行?
- python - pyowm 调用在自己的程序中有效,但在从其他程序调用时无效
- openoffice.org - 公式编辑器:sum 字符太小
- r - 基于 R 中的两个嵌套 id 变量,二进制变量的编码状态随时间变化
- html - 如何使我的图像在内部移动并在 HTML5 画布上更改图形?
- c# - 尽管我处理了 FormatException,但当我给出字母而不是数字时,此代码会输出未处理的 FormatException?