# GLSL - Stretched vertices after translating

I'm trying to translate 3D object in my game engine. I copied all formulas from my old, working game engine, where translation was working.

When I set position and rotation to 0, everything looks to be fine, but when I try to change position of my 3D object, something strange happens. I'm not sure if it is projection matrix issue, or maybe transform matrix issue.

Position: x = 0, y = 0, z = 0
Rotation: x = 0, y = 0, z = 0


Position: x = 0, y = 0, z = 0
Rotation: x = 0, y = 45.0, z = 0


Position: x = 1.5, y = 0, z = 0
Rotation: x = 0, y = 0, z = 0


Position: x = 3.5, y = 0, z = 0
Rotation: x = 0, y = 0, z = 0


I checked all formulas once again, checked transformation matrix output, projection matrix output, and everything seems to be fine.

#version 400

in vec3 position;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;

void main(void)
{
gl_Position = projectionMatrix * viewMatrix * transformationMatrix * vec4(position,1.0);
}


#version 400

uniform vec2 textureVec;

layout(location = 0) out vec3 out_Diffuse;
layout(location = 1) out vec3 out_Texture;

void main(void)
{
out_Diffuse = vec3(0.5, 0.5, 0.5);
out_Texture = vec3(textureVec, 0.0);
}


Projection matrix formula:

  float aspectRatio = static_cast<float>(windowSize.x) / static_cast<float>(windowSize.y);
float yScale = static_cast<float>((1.0f / tanf(MathUtil::degToRad(fov / 2.0f))));
float xScale = yScale / aspectRatio;
float frustumLen = farPlane - nearPlane;

projectionMatrix.m00 = xScale;
projectionMatrix.m11 = yScale;
projectionMatrix.m22 = -((farPlane + nearPlane) / frustumLen);
projectionMatrix.m23 = -1.0f;
projectionMatrix.m32 = -((2.0f * nearPlane * farPlane) / frustumLen);
projectionMatrix.m33 = 0.0f;


View matrix formula:

  viewMatrix.setIdentity();
viewMatrix.scale(Vector3(1.0f, -1.0f, 1.0f));

Vector3 negativeCam = Vector3::negate(transformComponent->position);

viewMatrix.translate(negativeCam);


And transformation matrix formula:

  transformationMatrix.setIdentity();

transformationMatrix.translate(position);
transformationMatrix.scale(scale);


Same happens for "y" and "z" position axis, but object "rotates" in different axis.

I also checked my VAO loader, vertices, uniform values loader, and everything else. If you need more code, let me know.

• You haven't identified what problem you want to solve. (If it's the third image "looking wrong", it might actually be right, but surprising with an empty scene. With a wide field of view, that's what happens.) – david van brink Jan 11 '17 at 19:12
• What is your field of view (fov) set to? It looks like you're doing the equivalent of using a really wide angle lens up close to an object, which would cause this exact kind of distortion. – user1118321 Jan 12 '17 at 3:31