javascript - 如何在webgl的x轴上移动一个正方形?
问题描述
我想创建一个正方形应该在 x 轴上移动的动画,但我不知道该怎么做。
// Tell WebGL how to pull out the positions from the position
// buffer into the vertexPosition attribute.
{
const numComponents = 2; // pull out 2 values per iteration
const type = gl.FLOAT; // the data in the buffer is 32bit floats
const normalize = false; // don't normalize
const stride = 0; // how many bytes to get from one set of values to the next
// 0 = use type and numComponents above
const offset = 0; // how many bytes inside the buffer to start from
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.position);
gl.vertexAttribPointer(
programInfo.attribLocations.vertexPosition,
numComponents,
type,
normalize,
stride,
offset);
gl.enableVertexAttribArray(
programInfo.attribLocations.vertexPosition);
}
// Tell WebGL to use our program when drawing
gl.useProgram(programInfo.program);
// Set the shader uniforms
gl.uniformMatrix4fv(
programInfo.uniformLocations.projectionMatrix,
false,
projectionMatrix);
gl.uniformMatrix4fv(
programInfo.uniformLocations.modelViewMatrix,
false,
modelViewMatrix);
{
const offset = 0;
const vertexCount = 4;
gl.drawArrays(gl.TRIANGLE_STRIP, offset, vertexCount);
}
我尝试使用 for 循环绘制场景,但它发生得如此之快,看起来不像动画,并且 setTimeout 也不起作用。
解决方案
推荐阅读
- java - 多表 - 缺失数据
- r - 遍历列序列(具有相同的作物相关数据)以在 R 中构建整洁的 rbind 数据集
- reactjs - 用于类型检查的 PropTypes
- c++ - SetConsoleWindowInfo 函数不断返回 false
- javascript - display:none 如果兄弟姐妹子 div 为空,则显示一个 div
- python - 如何模拟没有为 Python 单元测试设置类属性的参数的函数?
- vuejs2 - 带 img 的绝对 b-navbar-brand
- oracle - Quarkus 设置默认数据库
- discord.js - Discord bot 认为我在 VC 中,即使我不是
- java-8 - 读取 URL 数据时出现 307 临时重定向错误