Hi again jonnin,
You may be doing this and me not remembering what the set orientation commands do. |
As far as what the set orientation commands do, in this case they're custom written, as I wanted to avoid using GLM. I used a nice guide from 1990, which really has been great for 99% of the needed matrix operations:
http://www.fastgraph.com/makegames/3drotation/3dsrce.html
remember too that there are anomalies in rotations and translations. Straight up / spin / fall back flat ... what direction are you pointing? |
The camera initially starts at identity, so I'm thinking it's not that. If I stay at the origin and only alter my RotX,RotY,RotZ, everything looks fine, even while rotated, but if I translate, things start warping.
So my first thought was that something's wrong with Translate... but it's the most trivial matrix function of them all, so I'm not sure how I could've messed that up:
1 2 3 4 5 6 7 8
|
void _FillTranslationMatrix(float* a, float x, float y, float z)
{
// Fill out a translation matrix
a[0] = 1.0f; a[1] = 0.0f; a[2] = 0.0f; a[3] = x;
a[4] = 0.0f; a[5] = 1.0f; a[6] = 0.0f; a[7] = y;
a[8] = 0.0f; a[9] = 0.0f; a[10] = 1.0f; a[11] = z;
a[12] = 0.0f; a[13] = 0.0f; a[14] = 0.0f; a[15] = 1.0f;
}
|
(And then matrix multiply with the rotation matrix. And since rotating the models or view looks correct, I'm assuming my rotation function is ok.)
It's either something related to translating, OR, it's something related to my Set Projection function.
In the link I mentioned, it actually didn't have a Set Projection function -- so I looked elsewhere online for it. I found it, but I'm wondering if this function is assuming that worldUp is 0,1,0. I'm using a worldUp of 0,0,1. The way I'm accomplishing this and still rendering in OpenGL is just swapping the Y and Z in the shader when I send the matrix to it. Just for fun, I un-swapped them to see what happens... my view turned upside-down and things still warp as I translate forward.
So yeah, I'm thinking the math in this function is making an assumption of what the worldUp is, and maybe that's why things are warping?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
void SetProjectionPerspective(float fov, float aspect_ratio, float near, float far)
{
float degrees_to_radians = _pi / 180.0f;
float sy = 1.0f / tan(degrees_to_radians * fov / 2.0f);
float sx = sy / aspect_ratio;
float nmf = near - far;
float form1 = (far + near) / nmf;
float form2 = 2.0f * far * near / nmf;
// Fill out the matrix
float* p = m_perspective_matrix;
p[0] = sx; p[1] = 0.0f; p[2] = 0.0f; p[3] = 0.0f;
p[4] = 0.0f; p[5] = sy; p[6] = 0.0f; p[7] = 0.0f;
p[8] = 0.0f; p[9] = 0.0f; p[10] = form1; p[11] = 1.0f;
p[12] = 0.0f; p[13] = 0.0f; p[14] = form2; p[15] = 1.0f;
}
|
I tried messing with the values in the matrices, but not really knowing how it works, I haven't yet produced anything that looks correct. (Usually, everything just disappears when I mess with it.)