Answer the question
In order to leave comments, you need to log in
What is the logic behind rotating an object (vbo) with OpenGL using GLSL?
Hello,
I'm using OpenGL 4.x, shaders along the way, drawing Patrick from spongebob to make it more fun =)
Here it is, get acquainted:
There is obviously a mistake in the rotation implementation . Although the turn itself occurs, but sometimes with jerks, at different speeds.
A bit of theory
It is clear that rotation relative to the origin is achieved by multiplying the Rotation Matrix (MT)
by the coordinate vector
|x|
|y|
|z|
Now to the question of the implementation of the
Vertex Shader:
#version 400\n
layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec3 vertex_colour;
layout(location = 2) in vec3 modifier_pos;
layout(location = 3) in int angle;
in vec3 vp;
smooth out vec3 colour;
void main () {
colour = vertex_colour;
vec3 rot1 = vec3(cos(radians(angle)), sin(radians(angle)), 0);
vec3 rot2 = vec3(-sin(radians(angle)), cos(radians(angle)), 0);
vec3 rot3 = vec3(0, 0, 1);
mat3 rot = mat3(rot1, rot2, rot3);
gl_Position = vec4 ( ((vertex_position + modifier_pos) * rot), 1.0);
} ;
if (glfwGetKey(window, GLFW_KEY_R)) {
std::cout << "detected R btn" << std::endl;
for (int i = 0; i < modelLoader.vertexs_counter; i++) {
if (rotArray[i] == 360) {
rotArray[i] = 0;
}
rotArray[i] += 1;
}
glBindBuffer(GL_ARRAY_BUFFER, uiVBO[4]);
glBufferData(GL_ARRAY_BUFFER, modelLoader.vertexs_counter * sizeof(float), &rotArray[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, 0, 0);
}
Answer the question
In order to leave comments, you need to log in
VBO is made for that, to load it into the GPU once and not touch it again.
The fact that you are actually modifying the vertices to rotate is absolutely not true.
To transfer the transformation matrix to the shader, you need to use Uniforms.
Here is a simple lesson with a rotating cube and using VBO.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question