- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我已经想出了如何实现这一点。我的阵列看起来很困惑。这个问题很难解释,所以我提供一些图片和代码。
编辑:问题是 for 循环和 x1、y1、z1 变量由 float 控制
public void create() {
setup();
render();
}
private void makeCube() {
texture = glGenBuffers();
cube = glGenBuffers();
FloatBuffer cubeBuffer;
FloatBuffer textureBuffer;
ArrayList<Float> cubeList = new ArrayList<>();
ArrayList<Float> textureList = new ArrayList<>();
float[] cubeFloat;
float[] textureFloat;
for (float x1 = 0; x1 < tileSize * width; x1 += tileSize) {
for (float y1 = 0; y1 < tileSize * height; y1 += tileSize) {
for (float z1 = -tileSize * depth; z1 < 0; z1 += tileSize) {
float highX = x1 + tileSize;
float highY = y1 + tileSize;
float highZ = z1 + tileSize;
float[] cubeData = new float[]{
/*Front Face*/
x1, y1, z1,
highX, y1, z1,
highX, highY, z1,
x1, highY, z1,
/*Back Face*/
x1, y1, highZ,
highX, y1, highZ,
highX, highY, highZ,
x1, highY, highZ,
/*Left Face*/
x1, y1, z1,
x1, y1, highZ,
x1, highY, highZ,
x1, highY, z1,
/*Right Face*/
highX, y1, z1,
highX, y1, highZ,
highX, highY, highZ,
highX, highY, z1,
/*Bottom Face*/
x1, y1, z1,
x1, y1, highZ,
highX, y1, highZ,
highX, y1, z1,
/*Top Face*/
x1, highY, z1,
x1, highY, highZ,
highX, highY, highZ,
highX, highY, z1};
for (float f : cubeData) {
cubeList.add(f);
}
}
}
}
cubeFloat = compileFloat(cubeList);
for (int i = 0; i < (width * height * depth); i++) {
float[] textureData = new float[]{
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1};
for (Float f : textureData) {
textureList.add(f);
}
}
textureFloat = compileFloat(textureList);
textureBuffer = asFloatBuffer(textureFloat);
glBindBuffer(GL_ARRAY_BUFFER, texture);
glBufferData(GL_ARRAY_BUFFER, textureBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
cubeBuffer = asFloatBuffer(cubeFloat);
glBindBuffer(GL_ARRAY_BUFFER, cube);
glBufferData(GL_ARRAY_BUFFER, cubeBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
private float[] compileFloat(ArrayList<Float> list) {
float[] f = new float[list.size()];
for (int i = 0; i < list.size(); i++) {
f[i] = list.get(i);
}
return f;
}
private void renderCube() {
textures.get(0).bind();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, cube);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, texture);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, 24 * (width * height * depth));
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
private void render() {
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
camera();
renderCube();
Display.update();
Display.sync(30);
}
Display.destroy();
System.exit(0);
}
private void setup() {
try {
Display.setDisplayMode(new DisplayMode(frameWidth, frameHeight));
Display.setTitle("3D Project");
Display.setVSyncEnabled(vSync);
Display.create();
} catch (LWJGLException ex) {
Logger.getLogger(Camera.class.getName()).log(Level.SEVERE, null, ex);
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, (float) Display.getWidth() / (float) Display.getHeight(), zNear, zFar);
//glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glLoadIdentity();
loadTextures();
makeCube();
}
制作 3x3x1 数组会产生以下结果:
尽管制作 2x2x1 数组效果非常好。
所以我认为这是出了问题,我不知道如何解决它。 (这应该是 5x5x1.
最佳答案
感谢您解释 tileSize
使用的值。值 0.1 无法以任何精度的浮点表示,它退化为以 2 为基数的重复分数,就像每个人都熟悉以 10 为基数的 1/3 一样。现在,如果您继续将这个不完全是0.1的数字添加到某个东西上,最终结果将与您的预期明显不同。
一般来说,最好避免使用浮点表达式进行循环控制。您可能会认为,因为编译器很乐意接受诸如 0.1 这样的浮点常量,所以一切都很好,并且它可以准确地表示该数字,但如果您不了解 float 学的机制那么像这样奇怪的事情就会发生。
如果您好奇,可以找到我提到的问题的更详细解释 here .
关于java - 一个 VBO 中有多个 Cube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20986180/
我试图找到最有效的方法来检查 2 个任意大小的立方体是否相互碰撞。立方体的边长不一定都相等(一个盒子是可能的)。鉴于这些限制,我如何有效地检查它们是否发生碰撞? (每个盒子有24个顶点)谢谢 它们是轴
背景:我正在分析通话详细记录 (CDR) 数据,以便根据通话时长、通话时间(节假日通话或非节假日通话、商务通话)对客户进行分割或非商务电话)、用户年龄组和性别。数据来自两个表名cdr(包括card_n
我想要 status=2 或 status3`, // ${SECURITY_CONTEXT.status.unsafeValue()`, }); 一般来说,最好不要这样做;相反,我建议使用 seg
我正在开发一个olap Web应用程序,对于对象Cube我有2种类型的导入:org.olap4j.metadata.Cube或mondrian.olap.Cube。我应该使用什么? 最佳答案 您应该只
我要在Threejs中创建一个第三人称相机,它跟随一个立方体旋转,并在立方体旋转时旋转。这就是我所做的。它在下面的框中工作,但当框旋转时,它就不一样了。。所以请帮帮我。我试着自己创造它。我是这么做的
我有日期范围内的商品价格表。在 cube.js 中对此进行建模以允许时间维度查询(例如随时间变化的价格或商品的平均价格)的最佳方式是什么? 谢谢! 表格看起来像: CREATE pricing tes
我正在使用 TFS 多维数据集 as documented here并且我得到了“总行数”的奇怪结果。如果我查看 Visual Studio 中的一个文件,我会看到一个文件可能有 42 行长(总计、注
我正在尝试实现Korf's algorithm来解决3x3x3魔方。解决方案的一部分是创建模式数据库。 这是paper的引文,从字面上包含有关如何执行操作的全部信息: 用一个 从目标状态进行广度优先搜
我目前正在研究这个:我生成一个包含多个 .vtr 文件的 Paraview .vtm 文件。每个 .vtr 文件都包含值和坐标,如下所示,假设我正在处理 8 的维度:
Cube.js 是一个开源的分析平台,可以作为数据源和应用之间的中间层。 数据分析是一个时髦的领域,有许多解决方案可供选择。其中之一是 Cube.js,这是一个开源的分析平台。你可以
我有一个 postgres 数据库,其中包含一个包含 100 维词嵌入的文档表,并使用它来查找相似文档。 CREATE TABLE documents( id bigint, title
所以我对 BI 的概念基本上是全新的,并且我继承了一个现有的 ETL 过程,它是一个两步过程: 将数据加载到仅由多维数据集处理使用的数据库中 针对所述数据库启动 SSAS 多维数据集处理 它看起来很好
我正在使用 cube.js 通过将其绘制为折线图来比较数据随时间的变化。 第一步:成功生成 cube.js schema 后,数据如下所示: 第 2 步: 现在,当我尝试检查折线图时,它显示的线条如下
当我在创建数据源 View 后尝试处理维度时,出现错误: The project could not be deployed to the server because of the followin
我在连接到 AWS 无服务器上的 cube.js 后端并在前端仪表板中执行/cubejs-api/v1/load 请求时遇到了一些问题。我一直收到 {"error":"Continue wait"}
我对此很陌生,所以我可能犯了一个简单的错误。 我需要使用远程数据库制作一个 OLAP 多维数据集。 设置维度和度量并创建多维数据集后,我无法将多维数据集启动到本地服务器。 我不断收到错误, “由于以下
我们构建了一个 SSAS ROLAP 多维数据集,其中数据源是 memSQL。该多维数据集使用 Visual Studio 2019 构建,用于连接 memSQL 数据源的驱动程序为“MySQL .N
因此,我正在通过SICP进行工作,其中一个问题(1.8)是使用Newton-Raphson method实现类似于平方根过程的立方根过程。我编写了程序并尝试执行该程序,但出现了以下错误:*: numb
编译架构: {"version":"default_schema_version_78dca52738894dbb23e7069f2e88ae73"} Internal Server Error: {
编译架构: {"version":"default_schema_version_78dca52738894dbb23e7069f2e88ae73"} Internal Server Error: {
我是一名优秀的程序员,十分优秀!