# Rotation of an object by rotation matrix

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:
[ATTACH=CONFIG]921[/ATTACH]

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

``````
#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:
[ATTACH=CONFIG]922[/ATTACH] [ATTACH=CONFIG]923[/ATTACH]

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

The rotation-matrix is actually rotating around the models (or meshs) origin, so if your model has the origin at one edge, its rotating around this edge. What you should do is rearranging your mesh in your modeling-software. You could center it after loading but thats just a mess if you got more and more meshs with bad origins.

If thats a hardcoded cube with vertices between (0,0,0) and (1,1,1) then use vertices between (-.5, -.5, -.5) and (.5, .5, .5) to set its origin to the center.

If you want the cube to rotate about its centre, the cube’s origin should probably be its centre rather than a corner.

Having said that, you can rotate about an arbitrary point (cx,cy,cz) by translating by (-cx,-cy,-cz), rotating about the origin, then translating by (cx,cy,cz).