hybrid wrote:You're creating a clone of the cam, but use it as the camera animator...
Code: Select all
// Creating a clone of the animator
ISceneNodeAnimatorCameraFPS *pFPSAnimatorCLONE = (ISceneNodeAnimatorCameraFPS *)pFPSAnimator->createClone(cam);
I clone the animator. It actually doesn't matter what I pass on to the
createClone() argument here because it does nothing with it - see
createClone() implementation:
Code: Select all
ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(ISceneNode* node, ISceneManager* newManager)
{
CSceneNodeAnimatorCameraFPS * newAnimator =
new CSceneNodeAnimatorCameraFPS(CursorControl, RotateSpeed, (MoveSpeed * 1000.0f), JumpSpeed,
KeyMapArray, KeyMapSize, NoVerticalMovement);
return newAnimator;
}
When I debugged my code the KeyMapArray pointer was NULL when the clone was created.
Why? Because when creating a dumb camera and using
setKeyMap() to set a key map the KeyMapArray pointer is unchanged due to the reasons I explained in the first post (in short it is unchanged in the
setKeyMap() method) and so when cloning the animator the key map is still NULL (as it was initialized).
When creating a FPS camera scene node and setting it a key map (like in the documentation of the
addCameraSceneNodeFPS() the constructor assigns the KeyMapArray pointer to the received key map array and so when using the following way of setting a key map the KeyMapArray pointer is set to the right values:
Code: Select all
SKeyMap keyMap[8];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;
keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;
keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;
keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;
camera = sceneManager->addCameraSceneNodeFPS(0, 100, 500, -1, keyMap, 8);
The catch is this: Because KeyMapArray is given any values only in the constructor, when changing the key map only the core::array object is changed (and so the actual behavior DOES change) but when cloning, because we're using the KeyMapArray it is not guaranteed that we would get the same values the core::array object has.
In my test case the first value KeyMapArray had was NULL and so when I cloned it I got that NULL value regardless of the core::array having other values. If I would change the KeyMapArray (using the constructor) then changing it again using
setKeyMap() the clone version would have the first values which I inserted in the constructor - because it was never changed again (which it should have by
setKeyMap()).
I hope I'm clear enough.