- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是问题的图片:
这是线框图:
正如您从上面的图片中看到的,我遇到了一些奇怪的图形问题并且不确定如何解决,我认为代码有问题,尽管没有其他人遇到过代码问题。
代码:
unsigned int rings = 12, sectors = 24;
float const R = 1./(float)(rings-1);
float const S = 1./(float)(sectors-1);
int r, s;
vertices.resize(rings * sectors * 3);
normals.resize(rings * sectors * 3);
texcoords.resize(rings * sectors * 2);
std::vector<GLfloat>::iterator v = vertices.begin();
std::vector<GLfloat>::iterator n = normals.begin();
std::vector<GLfloat>::iterator t = texcoords.begin();
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
float const y = sin( -M_PI_2 + M_PI * r * R );
float const x = cos(2*M_PI * s * S) * sin( M_PI * r * R );
float const z = sin(2*M_PI * s * S) * sin( M_PI * r * R );
*t++ = s*S;
*t++ = r*R;
*v++ = x * getR();
*v++ = y * getR();
*v++ = z * getR();
*n++ = x;
*n++ = y;
*n++ = z;
}
indices.resize(rings * sectors * 4);
std:vector<GLushort>::iterator i = indices.begin();
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
*i++ = r * sectors + s;
*i++ = r * sectors + (s+1);
*i++ = (r+1) * sectors + (s+1);
*i++ = (r+1) * sectors + s;
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices.data());
glNormalPointer(GL_FLOAT, 0, normals.data());
glTexCoordPointer(2, GL_FLOAT, 0, texcoords.data());
glDrawElements(GL_QUADS, indices.size(), GL_UNSIGNED_SHORT, indices.data());
最佳答案
索引将以顶点之外的索引结束。索引中的最后四个值将是:
*i++ = 11 * 24 + 23 = 287;
*i++ = 11 * 24 + (23 + 1) = 288;
*i++ = (11 + 1) * 24 + (23 + 1) = 312;
*i++ = (11 + 1) * 24 + 23 = 311;
但顶点只包含 288 个顶点。我假设它对其他人有效的原因是 glDrawElements 可能会在某些实现中包装索引。
关于c++ - OpenGL Vertex Array Sphere C 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15934637/
我在使用 dijkstra 时遇到了这个错误:TypeError:不可排序的类型:Vertex() dijkstra(g, g.get_vertex('a')) File "C:/Use
我对为自定义类实现迭代器感到困惑。我正在尝试为 std::set 实现一个迭代器,其中我的 Vertex 类声明为: class Vertex{
我正在尝试学习和实现有向图,但在执行程序时遇到了一些困难。 // ADD Function public boolean addVertex(Vertex v) { boolean added
我是 OpenGL 的初学者,我试图每 5 秒将大量“对象”从一个位置移动到另一个位置。如果我在顶点着色器中计算位置,fps 急剧下降,难道不应该在 GPU 上完成这些类型的计算吗? 这是顶点着色器代
我正在学习使用 Boost 图形库。我已经按照此处的说明定义了一个自定义结构来存储有关顶点的信息:Modifying vertex properties in a Boost::Graph . str
我正在尝试使用 boost::adjacency list 和捆绑属性创建一个 TreeMap 来存储每个顶点的父级,我想以一种它们不会失效的方式存储顶点描述符以防万一我删除了一个顶点,所以我使用了
要定义一个从 int 到 struct vertex 的映射,我应该定义 map[int]vertex 还是 map[int]*vertex?首选哪一个? 我扩展了 Chickencha 的代码: p
我创建了一个 VBO(顶点缓冲区对象)和 VAO(顶点数组对象)并执行了以下操作: glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo)
我用 HBase 设置了 Titan。 我删除图中的所有顶点 全部删除后显示为空。 gremlin> g.V.count() ==>0 但是如果我重新登录泰坦,那么图中会有一堆空顶点 gremlin>
我正在探索使用计算着色器将骨骼变形应用于网格顶点,而不是使用流输出的顶点着色器。我发现计算着色器的执行速度比顶点着色器慢得多,但在我把它写下来之前,我想确定我没有做错什么。 使用我的 100,000
这里我有一个有向图G,我需要判断是否存在一组顶点不相交的循环,以便每个顶点都属于一个循环。 我不确定这是否可以在多项式时间内完成或者它是否是 NP-Complete?谁能至少指出我正确的方向? 最佳答
要检测一个点是否在多边形中,您可以从该点到无穷远投影一条线,然后查看它与多少个多边形顶点相交......足够简单。我的问题是,如果射线在其中一个点上与多边形相交,则将其视为与两个线段相交,并被视为在多
我在 VehicleHistoryGraph 数据库中创建了一个 Message 类型的顶点,并向其中加载了 50,000 个该类型的顶点。 当我尝试使用此 SQL 语句一次删除所有顶点时 - DEL
所以我正在尝试将 Graph 类作为另一个项目的一部分。顶点存储在由 unordered_map 定义的邻接表中。我正在尝试创建一个散列函数以允许我的 Vertex 类存储在此 map 中,但我不知道
我正在尝试使用 Parma Polyhedra 库 [1]枚举(凸)多面体的顶点,例如,我有一个由四个约束指定的矩形: Constraint_System cs; cs.insert(x >= 0);
我开始了解 Visual Studio 2017 中的 OpenGL。按照 www.learnopengl.com 教程并通过了纹理检查点,转换是目前的主要问题。 我使用预先获取的统一位置 ID 将我
有一个预定的笔记本,它使用 BigQuery 客户端和具有所有者权限的服务帐户。当我手动运行单元格时,它会更新 BQ 表。 BQ 和 Vertex AI 都有一个项目。 我发现了一个类似的问题,但是
我在 R 中使用 Igraph 包,当我通过 V(graph) 访问顶点名称列表时,我得到以下结果: Vertex sequence: [1] "d66cp96igcdnt25brjeics9d11
我有一个 U-SQL 脚本,它在数据湖中存储的多个 JSON 文件上运行,当我针对单个文件运行该脚本时,一切正常,但是打开它以针对我的所有文件运行每次都会出现以下错误,并且作业永远不会超过“准备”阶段
我正在尝试实现 phong 阴影,但无济于事。我正在一点一点地构建着色器(这本身可能是一个问题),但这就是我目前所处的位置。我希望它将我的结果(犹他茶壶)输出为黑色背景上的白色图像。当我从顶点着色器中
我是一名优秀的程序员,十分优秀!