【发布时间】:2015-07-07 15:39:20
【问题描述】:
我正在尝试使用矩阵根据时间移动三角形。但它做了一些奇怪的事情:
应该怎么做: 在 x 轴上移动
它的作用: 三角形的顶点是固定的,其他点似乎以圆周运动的方式围绕它移动,并在 x、z 轴上缩放(我仍然在 2d 中,所以我没有深度)。
我的 C++ 代码:
...
GLfloat timeValue = glfwGetTime();
GLfloat offset = (sin(timeValue * 4) / 2);
GLfloat matrix[16] = {
1, 0, 0, offset,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
GLuint uniform_m_transform = glGetUniformLocation(shader_program, "m_transform");
glUniformMatrix4fv(uniform_m_transform, 1, GL_FALSE, matrix);
...
我的顶点着色器:
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
out vec3 ourColor;
uniform mat4 m_transform;
void main()
{
ourColor = color;
gl_Position = m_transform * vec4(position, 1.0);
}
我不知道我做错了什么,根据教程,我设置为 offset 的矩阵属性应该改变 x 平移。
你知道我的错误是什么吗?
【问题讨论】:
标签: c++ opengl matrix vertex-shader