我正在尝试为OpenGL项目创建一个Wavefront(.obj)文件加载器.我正在使用的方法是逐行进行并分离矢量(std :: vectors)中的顶点位置,纹理位置和正常位置,并且我将它们的索引(顶点,纹理和法线索引)存储在三个单独的中向量(来自文件的'f'行,每个面).
我无法根据纹理索引对完整的纹理坐标进行排序.我能够将顶点渲染到正确的位置,因为我的'loader'类需要索引,但我无法弄清楚如何以任何方式对纹理坐标进行排序,因此纹理在某些三角形上看起来像是一个偏移结果.
偏移纹理的多维数据集的图像:

纹理(.png)的图像,它应该如何在每张脸上:

编辑:这是.obj文件和.mtl文件的链接. Google云端硬盘.
这是我的OBJLoader.cpp文件:
rawObj.open(filePath); // Open file
while (!rawObj.eof()) {
getline(rawObj, line); // Read line
// Read values from each line
// starting with a 'v' for
// the vertex positions with
// a custom function (gets the word in a line
// at position i)
if (strWord(line, 1) == "v") {
for (int i = 2; i <= 4; i++) {
std::string temp;
temp = strWord(line, i);
vertexStrings.push_back(temp);
}
// Same for texture …Run Code Online (Sandbox Code Playgroud) 当前,在按住所需键时,输入会多次注册。有没有一种方法可以仅在按下键后处理第一个事件,而忽略随后的事件直到释放键?
我正在使用具有以下条件的processInput函数:
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) {
currentXPos--;
if (currentXPos < 0)
currentXPos = 0;
}
Run Code Online (Sandbox Code Playgroud)
currentXPos只是一个受左右箭头键影响的整数。我也有一个等效的currentYPos整数,该整数也受上/下箭头键的影响。我需要每次按键增加/减少currentXPos一次。我尝试添加一个初始设置为true的全局布尔值,并在执行时将其设置为false,如下所示:
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) {
if (canMove) {
canMove = false;
currentXPos--;
if (currentXPos < 0)
currentXPos = 0;
}
}
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_RELEASE) {
canMove = true;
}
Run Code Online (Sandbox Code Playgroud)
这确实适用于单个键,但是如果我也使用右箭头键实现此功能(用于增加相同的值),则以下函数在首次发布后会不断返回GLFW_RELEASE,将canMove bool设置为true并最终使多余的
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_RELEASE) {
canMove = true;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用glfwWaitEvents(),但是当帮助时间超过0.5秒左右时,它仍会处理多个输入(与在搜索栏/文本编辑器中按住键盘上的任何字符相同的效果)。