Agh!
I've come across a problem, and I cannot figure out if it's a bug in JPCT or a bug in my code. I've double and triple checked everything and I cannot seem to find the cause of the problem.
I have reproduced the problem by modifying the fps demo. My aim is to store independent camera settings in a set of object array variables. Note that in this example, there is only one setting in the arrays:
private SimpleVector[] storedPosition = {new SimpleVector(STARTING_POS)};
private SimpleVector[] storedDirection = {new SimpleVector()};
private Matrix[] storedPlayerDirection = {new Matrix()};
A new function swaps the camera object with one of the values in the settings. Again, for the purposes of this demo, the value which is swapped in is arbitrarily fixed at index 0.
protected void swapCameraWithStoredVariables()
{
SimpleVector swap;
SimpleVector swap2;
Matrix otherSwap;
swap = storedPosition[0];
storedPosition[0] = camera.getPosition();
camera.setPosition(swap);
swap2 = storedDirection[0];
storedDirection[0] = camera.getDirection();
camera.setBack(swap2.getRotationMatrix().invert3x3());
otherSwap = storedPlayerDirection[0];
storedPlayerDirection[0] = playerDirection;
playerDirection = otherSwap;
}
This function (swapCameraWithStoredVariables ) gets called at the top and bottom of the doMovement() function.
Finally, in gameLoop, I added two lines to set the camera to use the stored values. This occurs immediately before the poll() function:
camera.setPosition(storedPosition[0]);
camera.setBack(storedDirection[0].getRotationMatrix().invert3x3());
Once more, in this example, the camera is set to display a single camera.
To my knowledge, adding this code should have no effect to the operation of the fps demo. All it does is copy the stored variables in to the current camera to carry out any movement. When the movement is calculated, the values are copied back to the stored variables. When the scene is displayed, the variables are loaded in to the camera object.
Therefore, it should behave as the original fps does.
However, in practice, the forward/backward controls move at right angles to the camera direction. For example, if the camera is pointing straight ahead, the forward/backward controls move the camera left and right (strafing).
I cannot for the life of me, determine why this is happening. Is it a bug in my code, or a bug in jpct?
I can supply the modified fps demo code if required.