Rotation of model with translation results in rotation not at origin
<p>I have a model I'm trying to move through the air in OpenGL with GLSL and, ultimately, have it spin as it flies. I started off just trying to do a static rotation. Here's an example of the result:</p>

<p><a href="https://i.stack.imgur.com/f5kaH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f5kaH.png" alt="image"></a></p>

<p>The gray track at the bottom is on the floor. The little white blocks all over the place represent an explosion chunk model and are supposed to shoot up and bounce on the floor.</p>

<p>Without rotation, if the model matrix is just an identity, everything works perfectly.</p>

<p>When introducing rotation, it looks they move based on their rotation. That means that some of them, when coming to a stop, rest in the air instead of the floor. (That slightly flatter white block on the gray line next to the red square is not the same as the other little ones. Placeholders!)</p>

<p>I'm using glm for all the math. Here are the relevant lines of code, in order of execution. This particular model is rendered instanced so each entity's position and model matrix get uploaded through the uniform buffer.</p>

<p>Object creation:</p>

<pre><code>// should result in a model rotated along the Y axis
auto quat = glm::normalize(glm::angleAxis(RandomAngle, glm::vec3(0.0, 1.0, 0.0))); 
myModelMatrix = glm::toMat4(quat);
</code></pre>

<p>Vertex shader:</p>

<pre><code>struct Instance
{
    vec4 position;
    mat4 model;
};

layout(std140) uniform RenderInstances
{
    Instance instance[500];
} instances;

layout(location = 1) in vec4 modelPos;
layout(location = 2) in vec4 modelColor;
layout(location = 3) out vec4 fragColor;

void main()
{
    fragColor = vec4(modelColor.r, modelColor.g, modelColor.b, 1);
    vec4 pos = instances.instance[gl_InstanceID].position + modelPos;

    gl_Position = camera.projection * camera.view * instances.instance[gl_InstanceID].model * pos;
}
</code></pre>

<p>I don't know where I went wrong. I do know that if I make the model matrix do a simple translation, that works as expected, so at least the uniform buffer works. The camera is also a uniform buffer shared across all shaders, and that works fine. Any comments on the shader itself are also welcome. Learning!</p>