gpt4 book ai didi

c++ - 每个顶点加权法线请记住OpenGL C++中的折角

转载 作者:行者123 更新时间:2023-12-03 07:26:06 24 4
gpt4 key购买 nike

我正在尝试考虑折痕 Angular 来计算每个顶点的加权法线。
但是,由于我的游戏中有许多(> 12)网格物体,因此代码永远无法运行。
在考虑折痕 Angular 情况下,还有更好的方法来计算每个顶点的加权法线吗?

以下是显示该代码的代码:

if (cosCreaseAngle == 0) { // ignore crease angle, just average all the nermoals keeping area in mind
float area = 0;
for (long pos = 0; pos < m->face_index_vertex.size(); pos++) {
int firstVertex = pos - pos % 3;
area = calcTriangleArea(m->dot_vertex[m->face_index_vertex[firstVertex]], m->dot_vertex[m->face_index_vertex[firstVertex + 1]], m->dot_vertex[m->face_index_vertex[firstVertex + 2]]);
m->dot_normalPerVertexWeighted[m->face_index_vertex[pos]] +=
area*(m->dot_normalPerFace[m->face_index_normalPerFace[pos]]); // multiply by the area
}
}
else { //average the normals only when the angle between normals is less than the crease angle
float area = 0;
for (long pos = 0; pos < m->face_index_vertex.size(); pos++) {
m->dot_normalPerVertexWeighted[m->face_index_vertex[pos]] = m->dot_normalPerFace[m->face_index_normalPerFace[pos]];
for (long adjacentFace = pos + 3; adjacentFace < m->face_index_vertex.size(); adjacentFace++) {
if (m->face_index_vertex[pos] == m->face_index_vertex[adjacentFace]) {
if (cosCreaseAngle < calcAngleBetweenNormals(m->dot_normalPerFace[m->face_index_normalPerFace[pos]], m->dot_normalPerFace[m->face_index_normalPerFace[adjacentFace]])) {
int firstVertex = adjacentFace - adjacentFace % 3;
area = calcTriangleArea(m->dot_vertex[m->face_index_vertex[firstVertex]], m->dot_vertex[m->face_index_vertex[firstVertex + 1]], m->dot_vertex[m->face_index_vertex[firstVertex + 2]]);
m->dot_normalPerVertexWeighted[m->face_index_vertex[pos]] +=
area*(m->dot_normalPerFace[m->face_index_normalPerFace[adjacentFace]]);
}
}
}
}
}

最佳答案

您的代码具有嵌套循环,可导致二次运行时间。您应该改为构建邻接图-为每个顶点将相邻的面添加到列表中,然后遍历该图。这样可以将运行时间缩短为线性。

关于c++ - 每个顶点加权法线请记住OpenGL C++中的折角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40955357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com