- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 OpenGL 制作一款 3D 游戏,该游戏的世界基本上完全由 AABB 立方体构成。我创建这个是为了制作 24 个垂直立方体:
void CBox::UpdateDimensions( float w, float h, float d, Vertex3f c )
{
width = w;
height = h;
depth = d;
center = c;
Vertex3f verticies[24];
GLfloat vboverticies[72];
GLfloat vbonormals[18];
//Top face
verticies[0] = Vertex3f(-width / 2.0f,height / 2.0f, -depth / 2.0f);
verticies[1] = Vertex3f(-width / 2.0f,height / 2.0f, depth / 2.0f);
verticies[2] = Vertex3f(width / 2.0f,height / 2.0f, depth / 2.0f);
verticies[3] = Vertex3f(width / 2.0f,height / 2.0f, -depth / 2.0f);
//Bottom face
verticies[4] = Vertex3f(-width / 2.0f,-height / 2.0f, -depth / 2.0f);
verticies[5] = Vertex3f(width / 2.0f,-height / 2.0f, -depth / 2.0f);
verticies[6] = Vertex3f(width / 2.0f,-height / 2.0f, depth / 2.0f);
verticies[7] = Vertex3f(-width / 2.0f,-height / 2.0f, depth / 2.0f);
//Left face
verticies[8] = Vertex3f(-width / 2.0f,-height / 2.0f, -depth / 2.0f);
verticies[9] = Vertex3f(-width / 2.0f,-height / 2.0f, depth / 2.0f);
verticies[10] =Vertex3f(-width / 2.0f,height / 2.0f, depth / 2.0f);
verticies[11] =Vertex3f(-width / 2.0f,height / 2.0f, -depth / 2.0f);
//Right face
verticies[12] =Vertex3f(width / 2.0f,-height / 2.0f, -depth / 2.0f);
verticies[13] =Vertex3f(width / 2.0f,height / 2.0f, -depth / 2.0f);
verticies[14] =Vertex3f(width / 2.0f,height / 2.0f, depth / 2.0f);
verticies[15] =Vertex3f(width / 2.0f,-height / 2.0f, depth / 2.0f);
//Front face
verticies[16] =Vertex3f(-width / 2.0f,-height / 2.0f, depth / 2.0f);
verticies[17] =Vertex3f(width / 2.0f,-height / 2.0f, depth / 2.0f);
verticies[18] =Vertex3f(width / 2.0f,height / 2.0f, depth / 2.0f);
verticies[19] =Vertex3f(-width / 2.0f,height / 2.0f, depth / 2.0f);
//Back face
verticies[20] =Vertex3f(-width / 2.0f,-height / 2.0f, -depth / 2.0f);
verticies[21] =Vertex3f(-width / 2.0f,height / 2.0f, -depth / 2.0f);
verticies[22] =Vertex3f(width / 2.0f,height / 2.0f, -depth / 2.0f);
verticies[23] =Vertex3f(width / 2.0f,-height / 2.0f, -depth / 2.0f);
for(int i = 0; i < 24; i++)
{
verticies[i].x += center.x;
verticies[i].y += center.y;
verticies[i].z += center.z;
}
int count = 0;
for(int i = 0; i < 24; ++i)
{
vboverticies[count] = verticies[i].x;
count++;
vboverticies[count] = verticies[i].y;
count++;
vboverticies[count] = verticies[i].z;
count++;
}
//glNormal3f(0.0, 1.0f, 0.0f);
//glNormal3f(0.0, -1.0f, 0.0f);
//glNormal3f(-1.0, 0.0f, 0.0f);
//glNormal3f(1.0, 0.0f, 0.0f);
//glNormal3f(0.0, 0.0f, 1.0f);
//glNormal3f(0.0, 0.0f, -1.0f);
vbonormals[0] = (0.0);
vbonormals[1] = (1.0);
vbonormals[2] = (0.0);
vbonormals[3] = (0.0);
vbonormals[4] = (-1.0);
vbonormals[5] = (0.0);
vbonormals[6] = (-1.0);
vbonormals[7] = (0.0);
vbonormals[8] = (0.0);
vbonormals[9] = (1.0);
vbonormals[10]= (0.0);
vbonormals[11]= (0.0);
vbonormals[12]= (0.0);
vbonormals[13]= (0.0);
vbonormals[14]= (1.0);
vbonormals[15]= (0.0);
vbonormals[16]= (0.0);
vbonormals[17]= (-1.0);
RecalculateMinAndMax();
//Create the VBO
glDeleteBuffers(1, &vboID);
glGenBuffersARB(1, &vboID);
glBindBufferARB(GL_ARRAY_BUFFER, vboID);
glBufferDataARB(GL_ARRAY_BUFFER, (72 * sizeof(GLfloat)) +
(18 * sizeof(GLfloat)) , NULL, GL_STATIC_DRAW);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, 72 * sizeof(GLfloat), vboverticies);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 72 * sizeof(GLfloat),
18 * sizeof(GLfloat), vbonormals);
}
我想知道是否有一种方法可以通过只将 8 个顶点而不是 24 个顶点上传到显卡来做到这一点?
渲染这些内容的最快方法是什么?
谢谢
最佳答案
What I'm wondering is if there is a way to do this by only uploaading 8 verticies to the graphics card instead of 24?
看看 glDrawElements。我看到你使用 VBO,EBO 也很有用。如果您的大部分元素具有相同的几何形状(并且看起来它们具有相同的几何形状),您可以使用 glDrawElementsInstanced。
关于c++ - 尽可能快地渲染立方体? (OpenGL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3646967/
我有 3 个具有相同结构但数据不同的数据库,因为它们来自不同的客户端。 现在,我有一个现有的 SSAS 项目。其数据源 View 、多维数据集和维度只能使用或访问一个数据库。 我想要的是能够使用具有相
所以我的目标是将这些立方体放在一个网格上,并让它们排成一行,可以拖动和捕捉。我根据 this example 使立方体运行良好,但我没有完全理解某些机制,因此遇到了一些问题。 立方体开始时比旋转后大。
我正在解决一个问题,我需要使用 C# 处理内存中的多维数据。我的要求类似于 OLAP 多维数据集,但没有那么复杂。例如,我不需要计算或聚合或类似的东西。我基本上想使用多维键来引用数据。例如: var
我在 Cubical agda 工作,并试图为以后的证明建立一些通用的实用程序。其中之一是,对于任何类型 A,它与 Σ A (\_ -> Top) 类型“相同”,其中 Top是具有一个元素的类型。问题
我有这个在 WPF Viewport3D 中绘制立方体的代码:
以下代码是我目前写的使用三个js尝试移动或翻译 使用 WASD 键上下左右旋转立方体对象,并使用空格键重置到原始位置(屏幕中间)。我对三个 js 很陌生,我不知道如何让运动发挥作用。任何帮助将不胜感激
我想通过使用 opengl 来绘制体素,但它似乎不受支持。我制作了一个立方体绘制函数,它有 24 个顶点(每个面 4 个顶点),但是当你绘制 2500 个立方体时它会降低帧速率。我希望有更好的方法。理
我正在努力为盒子基元创建线框。尝试了颜色、不透明度和透明属性,但似乎都不起作用。这是代码 - 需要渲染这样的东西 - 最佳答案 您需要查看THREE.Material docs对于这个,有一点需要注
我有一个 opengl 立方体,我想对所有 6 个面进行纹理处理。 我需要多个纹理吗? 这是当前立方体的屏幕截图: 基本上我不知道如何将纹理包裹在整个立方体周围...... 这是我的 cube.h 头
我正在为《我的世界》编写一个模组,并遇到了一个令人困惑的数学问题。我想找到中心 block 周围所有 block 的 ID。为此,我想循环遍历 3x3 的方 block 并返回哪些是我想要的方 blo
这是我的问题:我一直在尝试让这个 CSS 立方体打开滚动。我做到了!这是它的工作原理:https://codepen.io/vaninoo/pen/BmyYQd 我很高兴。但是和 friend 测试过
我正在尝试创建 3 个具有相同视角的 3d 立方体,这些立方体将在悬停时旋转 90 度。它几乎适用于 chrome,但如果你仔细观察左侧立方体的底部边框,你会看到 1 条蓝色像素线。当您将鼠标悬停在右
我正在编写一个立方体,但无法使其正确旋转,有人可以帮我吗?我已经尝试了一切。我的代码链接如下: Codepen Link @keyframes spin { from { transform: r
我想创建一个 CSS 立方体,它有 4 个面(正面、背面、顶部、底部),并且它仅在 X 轴上不断向上(或向下)旋转。但出于某种原因,我无法对齐所有 4 个边,所以它看起来像一个立方体。这是我的标记:
啊哈!看来我的问题是我给 gluPerspective 的 zNear 值必须大于 0,而且我必须启用深度缓冲区才能使其工作。我更新了下面的代码以使其正常工作。 我尝试过很多次这样做,并且一直认为我以
我正在为学校开发一个使用 HTML5 和 CSS3 的元素。该元素的目标是教幼儿如何计算简单的方程式。学习这一点的第一步是教他们识别不同形状的数字。 第一个练习是:显示一个随机数并让 child 选择
我用 html 和 css 制作了一个旋转立方体。 当我按向右和向左箭头键时,立方体会按预期围绕其中心旋转。但是,当我按下向上和向下箭头键时,它会在更大的空间内旋转。 在这种情况下,我也希望它围绕其中
我正在努力让立方体在 opengl 中呈现。当我将已经计算出的 MVP 传递给顶点着色器时,它工作正常,但是当我传递模型、 View 和投影然后在顶点着色器中进行计算时,它不显示立方体。当我将顶点着色
大家好,我是 opengl 世界的新手,所以这就像一个星期我试图了解 opengl 是如何工作的。所以我放下我的代码使用不同的例子,我编译它没有问题。但是立方体没有出现,我不知道为什么。谁能向我解释我
我有一个应该绘制立方体的类。 它在主体中很好地绘制了我的立方体,但我使用默认的 x、y、z 值创建它,以便默认情况下将其置于屏幕中央。在通过调用 build 绘制立方体后,我想平移和缩放立方体,但我显
我是一名优秀的程序员,十分优秀!