- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
void GeometryGenerator::Subdivide(MeshData& meshData)
{
// Save a copy of the input geometry.
MeshData inputCopy = meshData;
meshData.Vertices.resize(0);
meshData.Indices.resize(0);
// v1
// *
// / \
// / \
// m0*-----*m1
// / \ / \
// / \ / \
// *-----*-----*
// v0 m2 v2
UINT numTris = inputCopy.Indices.size()/3;
for(UINT i = 0; i < numTris; ++i)
{
Vertex v0 = inputCopy.Vertices[ inputCopy.Indices[i*3+0] ];
Vertex v1 = inputCopy.Vertices[ inputCopy.Indices[i*3+1] ];
Vertex v2 = inputCopy.Vertices[ inputCopy.Indices[i*3+2] ];
//
// Generate the midpoints.
//
Vertex m0, m1, m2;
// For subdivision, we just care about the position component. We
// derive the other
// vertex components in CreateGeosphere.
m0.Position = XMFLOAT3(
0.5f*(v0.Position.x + v1.Position.x),
0.5f*(v0.Position.y + v1.Position.y),
0.5f*(v0.Position.z + v1.Position.z));
m1.Position = XMFLOAT3(
0.5f*(v1.Position.x + v2.Position.x),
0.5f*(v1.Position.y + v2.Position.y),
0.5f*(v1.Position.z + v2.Position.z));
m2.Position = XMFLOAT3(
0.5f*(v0.Position.x + v2.Position.x),
0.5f*(v0.Position.y + v2.Position.y),
0.5f*(v0.Position.z + v2.Position.z));
//
// Add new geometry.
//
meshData.Vertices.push_back(v0); // 0
meshData.Vertices.push_back(v1); // 1
meshData.Vertices.push_back(v2); // 2
meshData.Vertices.push_back(m0); // 3
meshData.Vertices.push_back(m1); // 4
meshData.Vertices.push_back(m2); // 5
meshData.Indices.push_back(i*6+0);
meshData.Indices.push_back(i*6+3);
meshData.Indices.push_back(i*6+5);
meshData.Indices.push_back(i*6+3);
meshData.Indices.push_back(i*6+4);
meshData.Indices.push_back(i*6+5);
meshData.Indices.push_back(i*6+5);
meshData.Indices.push_back(i*6+4);
meshData.Indices.push_back(i*6+2);
meshData.Indices.push_back(i*6+3);
meshData.Indices.push_back(i*6+1);
meshData.Indices.push_back(i*6+4);
}
}
此函数位于“GeometryGenerator.cpp”文件中,用于 segmentation 网格。在调用此函数之前,创建一个二十面体并将其作为参数 meshData 传输。 MeshData的成员Vertices和Indices是STL的 vector 。
在我看来,在这个函数调用了这一系列函数meshData.Vertices.push_back之后,在循环的下一次迭代中,一些顶点可能会被重复存储。
谁都能回答
感谢所有阅读我拙劣英语的人。
最佳答案
whether I am wrong
我很确定您是对的,尤其是关于重复的顶点!
why the author make the codes like this
除了作者本人,没有人能回答这个问题。我会猜测他/她只是监督了重复问题...
or whether there is more efficient way if my thought is right.
只要算法不正确,我就不会关心效率!
首先,我们需要避免顶点重复。我只是将现有的顶点保留原样(因此只清除
索引)并在末尾附加新的顶点。为此,我会将 edges 存储在临时 std::map 中,将一对索引(边缘)映射到新创建的索引(总是首先使用较小的索引以避免 出现问题(10,12)
与 (12,10)
,它们标识相同的边...)。
然后对于 v0、v1、v2,我将使用索引,而不是顶点本身。首先在 map 中查找 m0、m1、m2,如果找到,则使用,否则创建一个新顶点,将其添加到顶点 vector 中,并在我们的 map 中添加一个条目。
UINT v0 = copiedIndices[i*3+0];
// ...
UINT m0;
auto key = std::make_pair(v0, v1); // TODO: order indices!!!
auto entry = myMap.find(key);
if(entry != myMap.end())
{
m0 = entry->second;
}
else
{
meshData.Vertices.push_back(newVertex);
m0 = meshData.Vertices.size() - 1;
myMap.insert(key, m0);
}
然后您将添加新的三角形,只需按原样使用索引即可:
meshdata.indices.pushback(v0); // one of the original indices
meshdata.indices.pushback(m0); // one of the new ones
meshdata.indices.pushback(m2);
// ...
关于c++ - 在书中的示例代码 "introduction to 3d game programming with directx 11",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45231807/
我的英语很差,抱歉 这是我的结构: bookstore ---author(app1) ---book(app2) 或者在代码中: from django.db import models from
我对antlr 的理解停留在非常基础的层面。浏览 Parr 博士的“权威 ANTLR 4 引用”。在第 4.2 节“使用访问者构建计算器”中列出了以下语法: grammar LabeledExpr;
我对antlr 的理解停留在非常基础的层面。浏览 Parr 博士的“权威 ANTLR 4 引用”。在第 4.2 节“使用访问者构建计算器”中列出了以下语法: grammar LabeledExpr;
我正在学习 1.1.0 的 rust book 教程,但尝试运行他们的代码时出现错误。 我有以下内容: extern crate rand; use std::io; use std::cmp::Or
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 10年前关闭。 Improve this qu
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我的帖子是书的代码。 void qsort(void *lineptr[], int left, int right, int (*comp)(void *, void *)); /*Why it
考虑到 Fluent NHibernate 已经有一段时间了,我想应该会有一本书可以买到,所以我在亚马逊和谷歌中搜索,但没有关于 fluent nhiberanet 的书籍。我是对的还是这本书已经存在
考虑到 DocBook 格式的书可以以“模块化”的方式完成,我希望我可以用 AsciiDoc 做类似的事情,并将章节和第一级部分拆分到单独的文件中。不幸的是,文档没有提及这一点。到目前为止,我看到的唯
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我目前正在使用 Jquery 使用 turn.js 制作一本书,进展顺利,但我需要一点帮助。你看,我正在尝试制作一本精装期刊类型的书,就像此处显示的示例一样 http://www.turnjs.com
我正在阅读 Bjarne S 的 C++ 编程语言。 在第 77 页,第 4.8 节中,我发现了这一点: "枚举器可以用常量表达式初始化(§C.5) 的整数类型 (§4.1.1)。这枚举的范围包含向上
为什么当我输入由空格分隔的字符串(在 while 循环之外)并且我尝试在屏幕上打印它们时,只有我输入的第一个出现,而在这个 while 循环中(见代码)它打印所有这些一个? //this one pr
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在读这本书并被困在这里: public static class EventArgExtensions { public static void Raise(this TEventArgs
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在尝试使用 xlwt 创建具有多个选项卡的输出文件(.xlsx 格式)。我的Python版本号是2.7,IDE是Aptana Studio 3。 我以前使用过 xlwt 包,在相同的环境下执行相同
如何使用 Xcode 或 macOS 打开 Swift Playground Book?当我打开它时,我得到了这个: 最佳答案 在 Xcode 上,转到 Navigate > Reveal in Pr
嗨,我对 php 很陌生,我正在阅读 Murach PHP 书。我在单击类别部分中的链接时遇到问题,因为当它单击该链接时,它会广告 ?category_id=3 但问题是它在 add_product.
我是一名优秀的程序员,十分优秀!