MrFoil

03-02-2015, 10:30 AM

Hi all,

I'm trying to rotate an object around an axis (cube around Y), and I actually did it, but the thing is that it is rotating around one of its edges.

Using simple rotation matrix:

1651

Angle is changing in cycle, then I am just sending updated matrix to the vertex shader and multiplying on each vertex.

Vertex shader:

#version 330 core

layout(location = 0) in vec3 VertexPosition;

in vec2 texcoord;

uniform vec4 Translation;

uniform mat4 MVP;

uniform mat3 Rotation;

out vec2 fragTexcoord;

void main(){

gl_Position = MVP * ( ( vec4( VertexPosition * Rotation, 1 ) + Translation ));

fragTexcoord = texcoord;

}

Screenshots:

1652 1653

Can someone explain me how to rotate my cube around an axis that comes through centers of oposite sides?

I'm trying to rotate an object around an axis (cube around Y), and I actually did it, but the thing is that it is rotating around one of its edges.

Using simple rotation matrix:

1651

Angle is changing in cycle, then I am just sending updated matrix to the vertex shader and multiplying on each vertex.

Vertex shader:

#version 330 core

layout(location = 0) in vec3 VertexPosition;

in vec2 texcoord;

uniform vec4 Translation;

uniform mat4 MVP;

uniform mat3 Rotation;

out vec2 fragTexcoord;

void main(){

gl_Position = MVP * ( ( vec4( VertexPosition * Rotation, 1 ) + Translation ));

fragTexcoord = texcoord;

}

Screenshots:

1652 1653

Can someone explain me how to rotate my cube around an axis that comes through centers of oposite sides?