The reason why I added them is because after those angles, the movement would not go in the correct direction. For example: if my camera was rotated to the left (-yaw) and I moved the camera forward and backward it would work fine. However if I rotated the camera to the right(+yaw) would not work properly, so I figured that the formula had to change depending on which quadrant I was working in. I did notice in my time searching for an answer that none of the examples people have posted do not have conditions and work like what Columbo posted. Are those conditions then just hiding a problem somewhere else in my math?
I'm not at the computer with my code on it at the moment, so I can't post my matrix code...but it's setup very similarly to this guide:
http://openglbook.com/the-book/chapter-4-entering-the-third-dimension/EDIT:
So I commented out all of the conditions so I was only left with
y = std::sin(mRotation.x) * distance;
x = std::sin(mRotation.y) * distance;
z = std::cos(mRotation.y) * distance;
and the movement does work fine on the horizontal plane. However, if I face directly up or directly down (as in, looking down the y axis) the camera moves on the horizontal plane (x and z) when it should be restricted to moving vertically.
EDIT #2:
Okay, instead of using the translation method I had before, I did this:
mTransformationMatrix = Matrix4f::getIdentityMatrix();
mTransformationMatrix.rotate(mRotation);
mTransformationMatrix.translateMatrix(0.f, 0.f, mPosition.z += 1.f*distance);
And it sorta works how I want it to. I'm rotating the camera around a center point. Doesn't feel like I'm flying around.
EDIT #3: I have no idea what I'm doing
void ITransformable::translate(const Vector3f &vec) {
mPosition += vec;
mTransformationMatrix = Matrix4f::getIdentityMatrix();
mTransformationMatrix.scaleMatrix(mScale);
mTransformationMatrix.rotate(mRotation);
mTransformationMatrix.translateMatrix(mPosition);
}
Matrix functions:
void rotate(float x, float y, float z) {
Matrix4f xRotation = getIdentityMatrix();
Matrix4f yRotation = getIdentityMatrix();
Matrix4f zRotation = getIdentityMatrix();
float cos = std::cos(x);
float sin = std::sin(x);
xRotation[5] = cos;
xRotation[6] = -sin;
xRotation[9] = sin;
xRotation[10] = cos;
cos = std::cos(y);
sin = std::sin(y);
yRotation[0] = cos;
yRotation[2] = sin;
yRotation[8] = -sin;
yRotation[10] = cos;
cos = std::cos(z);
sin = std::sin(z);
zRotation[0] = cos;
zRotation[1] = -sin;
zRotation[4] = sin;
zRotation[5] = cos;
Matrix4f r = xRotation * yRotation * zRotation;
const float *result = ((*this)*r).getValues();
memcpy(mValues, result, sizeof(float)*16);
}
void translateMatrix(float x, float y, float z) {
Matrix4f translation = getIdentityMatrix();
translation[12] = x;
translation[13] = y;
translation[14] = z;
/*translation[3] = x;
translation[7] = y;
translation[11] = z;*/
const float *result = ((*this)*translation).getValues();
memcpy(mValues, result, sizeof(float)*16);
}