I'm currently working on my own 2D Maths library for my project to improve my understanding of the underlying matrix math. In the past I've use libraries such as GLM but I felt like it might be worth looking into as a learning experience.
Most of this has been straightforward and the majority of my Maths classes integrate and work well with OpenGL, however my view matrix appears to be stretching my quad at the edges of the window.
Note this isn't an issue of perspective, not only am I using an Orthographic Matrix but I've separated this from the MVP, using the view matrix in the place of the MVP and the issue still persists.
Below is my View Matrix generation code:
Matrix4x4 GenerateView(const Vector2f &cameraPosition)
{
Matrix4x4 mat;
//Right
mat.elements[0][0] = 1;
mat.elements[0][1] = 0;
mat.elements[0][2] = 0;
mat.elements[0][3] = -Dot(cameraPosition.x, cameraPosition.y, 10, 1, 0, 0);
//Up
mat.elements[1][0] = 0;
mat.elements[1][1] = 1;
mat.elements[1][2] = 0;
mat.elements[1][3] = -Dot(cameraPosition.x, cameraPosition.y, 10, 0, 1, 0);
//Look
mat.elements[2][0] = cameraPosition.x;
mat.elements[2][1] = cameraPosition.y;
mat.elements[2][2] = -1;
mat.elements[2][3] = -Dot(cameraPosition.x, cameraPosition.y, 10, cameraPosition.x, cameraPosition.y, -1);
//Last Column
mat.elements[3][0] = 0;
mat.elements[3][1] = 0;
mat.elements[3][2] = 0;
mat.elements[3][3] = 1;
return mat;
}
The Matrices are Column major (If I understand correctly). I was unclear whether the 'Look' was referring to a forward unit vector so I tried that as well as a 'center' but the issue persists.
//Look
mat.elements[2][0] = 0;
mat.elements[2][1] = 0;
mat.elements[2][2] = -1;
mat.elements[2][3] = -Dot(cameraPosition.x, cameraPosition.y, 10, 0, 0, -1);
Finally, in case anyone suspects that the Dot product is implemented incorrectly:
float Dot(float x1, float y1, float z1, float x2, float y2, float z2)
{
return x1 * x2 + y1 * y2 + z1 * z2;
}