Commit f9b538f9 authored by cutealien's avatar cutealien

- Added ISceneNodeAnimatorCameraFPS::getKeyMap and a new ISceneNodeAnimatorCameraFPS::setKeyMap.

- CSceneNodeAnimatorCameraFPS uses now SKeyMap instead of SCamKeyMap (structs were identical which was confusing and there wasn't any explanation in comments, so I decided to simplify it).
- Add some workaround to MeshViewer to show how we can currently fix the FPS-cam when users to alt-tab while moving. We can improve that some day when we have focus-events, but this works for now.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3920 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c40df30f
...@@ -349,6 +349,32 @@ void updateToolBox() ...@@ -349,6 +349,32 @@ void updateToolBox()
} }
} }
void onKillFocus()
{
// Avoid that the FPS-camera continues moving when the user presses alt-tab while
// moving the camera.
const core::list<scene::ISceneNodeAnimator*>& animators = Camera[1]->getAnimators();
core::list<irr::scene::ISceneNodeAnimator*>::ConstIterator iter = animators.begin();
while ( iter != animators.end() )
{
if ( (*iter)->getType() == scene::ESNAT_CAMERA_FPS )
{
// we send a key-down event for all keys used by this animator
scene::ISceneNodeAnimatorCameraFPS * fpsAnimator = static_cast<scene::ISceneNodeAnimatorCameraFPS*>(*iter);
const core::array<SKeyMap>& keyMap = fpsAnimator->getKeyMap();
for ( irr::u32 i=0; i< keyMap.size(); ++i )
{
irr::SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
event.KeyInput.Key = keyMap[i].KeyCode;
event.KeyInput.PressedDown = false;
fpsAnimator->OnEvent(event);
}
}
++iter;
}
}
/* /*
To get all the events sent by the GUI Elements, we need to create an event To get all the events sent by the GUI Elements, we need to create an event
receiver. This one is really simple. If an event occurs, it checks the id of receiver. This one is really simple. If an event occurs, it checks the id of
...@@ -930,10 +956,19 @@ int main(int argc, char* argv[]) ...@@ -930,10 +956,19 @@ int main(int argc, char* argv[])
img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,
EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
// remember state so we notice when the window does lose the focus
bool hasFocus = Device->isWindowFocused();
// draw everything // draw everything
while(Device->run() && driver) while(Device->run() && driver)
{ {
// Catch focus changes (workaround until Irrlicht has events for this)
bool focused = Device->isWindowFocused();
if ( hasFocus && !focused )
onKillFocus();
hasFocus = focused;
if (Device->isWindowActive()) if (Device->isWindowActive())
{ {
driver->beginScene(true, true, video::SColor(150,50,50,50)); driver->beginScene(true, true, video::SColor(150,50,50,50));
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ISceneNodeAnimator.h" #include "ISceneNodeAnimator.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
#include "irrArray.h"
namespace irr namespace irr
{ {
...@@ -38,11 +39,18 @@ namespace scene ...@@ -38,11 +39,18 @@ namespace scene
//! Set the rotation speed in degrees //! Set the rotation speed in degrees
virtual void setRotateSpeed(f32 rotateSpeed) = 0; virtual void setRotateSpeed(f32 rotateSpeed) = 0;
//! Sets the keyboard mapping for this animator //! Sets the keyboard mapping for this animator (old style)
/** \param map Array of keyboard mappings, see irr::SKeyMap /** \param map Array of keyboard mappings, see irr::SKeyMap
\param count Size of the keyboard map array. */ \param count Size of the keyboard map array. */
virtual void setKeyMap(SKeyMap *map, u32 count) = 0; virtual void setKeyMap(SKeyMap *map, u32 count) = 0;
//! Sets the keyboard mapping for this animator
//! \param keymap The new keymap array
virtual void setKeyMap(const core::array<SKeyMap>& keymap) = 0;
//! Gets the keyboard mapping for this animator
virtual const core::array<SKeyMap>& getKeyMap() const = 0;
//! Sets whether vertical movement should be allowed. //! Sets whether vertical movement should be allowed.
/** If vertical movement is enabled then the camera may fight with /** If vertical movement is enabled then the camera may fight with
gravity causing camera shake. Disable this if the camera has gravity causing camera shake. Disable this if the camera has
......
...@@ -28,6 +28,9 @@ namespace irr ...@@ -28,6 +28,9 @@ namespace irr
//! Struct storing which key belongs to which action. //! Struct storing which key belongs to which action.
struct SKeyMap struct SKeyMap
{ {
SKeyMap() {}
SKeyMap(EKEY_ACTION action, EKEY_CODE keyCode) : Action(action), KeyCode(keyCode) {}
EKEY_ACTION Action; EKEY_ACTION Action;
EKEY_CODE KeyCode; EKEY_CODE KeyCode;
}; };
......
...@@ -37,11 +37,11 @@ CSceneNodeAnimatorCameraFPS::CSceneNodeAnimatorCameraFPS(gui::ICursorControl* cu ...@@ -37,11 +37,11 @@ CSceneNodeAnimatorCameraFPS::CSceneNodeAnimatorCameraFPS(gui::ICursorControl* cu
if (!keyMapArray || !keyMapSize) if (!keyMapArray || !keyMapSize)
{ {
// create default key map // create default key map
KeyMap.push_back(SCamKeyMap(EKA_MOVE_FORWARD, irr::KEY_UP)); KeyMap.push_back(SKeyMap(EKA_MOVE_FORWARD, irr::KEY_UP));
KeyMap.push_back(SCamKeyMap(EKA_MOVE_BACKWARD, irr::KEY_DOWN)); KeyMap.push_back(SKeyMap(EKA_MOVE_BACKWARD, irr::KEY_DOWN));
KeyMap.push_back(SCamKeyMap(EKA_STRAFE_LEFT, irr::KEY_LEFT)); KeyMap.push_back(SKeyMap(EKA_STRAFE_LEFT, irr::KEY_LEFT));
KeyMap.push_back(SCamKeyMap(EKA_STRAFE_RIGHT, irr::KEY_RIGHT)); KeyMap.push_back(SKeyMap(EKA_STRAFE_RIGHT, irr::KEY_RIGHT));
KeyMap.push_back(SCamKeyMap(EKA_JUMP_UP, irr::KEY_KEY_J)); KeyMap.push_back(SKeyMap(EKA_JUMP_UP, irr::KEY_KEY_J));
} }
else else
{ {
...@@ -71,9 +71,9 @@ bool CSceneNodeAnimatorCameraFPS::OnEvent(const SEvent& evt) ...@@ -71,9 +71,9 @@ bool CSceneNodeAnimatorCameraFPS::OnEvent(const SEvent& evt)
case EET_KEY_INPUT_EVENT: case EET_KEY_INPUT_EVENT:
for (u32 i=0; i<KeyMap.size(); ++i) for (u32 i=0; i<KeyMap.size(); ++i)
{ {
if (KeyMap[i].keycode == evt.KeyInput.Key) if (KeyMap[i].KeyCode == evt.KeyInput.Key)
{ {
CursorKeys[KeyMap[i].action] = evt.KeyInput.PressedDown; CursorKeys[KeyMap[i].Action] = evt.KeyInput.PressedDown;
return true; return true;
} }
} }
...@@ -257,7 +257,7 @@ void CSceneNodeAnimatorCameraFPS::animateNode(ISceneNode* node, u32 timeMs) ...@@ -257,7 +257,7 @@ void CSceneNodeAnimatorCameraFPS::animateNode(ISceneNode* node, u32 timeMs)
void CSceneNodeAnimatorCameraFPS::allKeysUp() void CSceneNodeAnimatorCameraFPS::allKeysUp()
{ {
for (u32 i=0; i<6; ++i) for (u32 i=0; i<EKA_COUNT; ++i)
CursorKeys[i] = false; CursorKeys[i] = false;
} }
...@@ -299,24 +299,20 @@ void CSceneNodeAnimatorCameraFPS::setKeyMap(SKeyMap *map, u32 count) ...@@ -299,24 +299,20 @@ void CSceneNodeAnimatorCameraFPS::setKeyMap(SKeyMap *map, u32 count)
// add actions // add actions
for (u32 i=0; i<count; ++i) for (u32 i=0; i<count; ++i)
{ {
switch(map[i].Action) KeyMap.push_back(map[i]);
{
case EKA_MOVE_FORWARD: KeyMap.push_back(SCamKeyMap(EKA_MOVE_FORWARD, map[i].KeyCode));
break;
case EKA_MOVE_BACKWARD: KeyMap.push_back(SCamKeyMap(EKA_MOVE_BACKWARD, map[i].KeyCode));
break;
case EKA_STRAFE_LEFT: KeyMap.push_back(SCamKeyMap(EKA_STRAFE_LEFT, map[i].KeyCode));
break;
case EKA_STRAFE_RIGHT: KeyMap.push_back(SCamKeyMap(EKA_STRAFE_RIGHT, map[i].KeyCode));
break;
case EKA_JUMP_UP: KeyMap.push_back(SCamKeyMap(EKA_JUMP_UP, map[i].KeyCode));
break;
default:
break;
}
} }
} }
void CSceneNodeAnimatorCameraFPS::setKeyMap(const core::array<SKeyMap>& keymap)
{
KeyMap=keymap;
}
const core::array<SKeyMap>& CSceneNodeAnimatorCameraFPS::getKeyMap() const
{
return KeyMap;
}
//! Sets whether vertical movement should be allowed. //! Sets whether vertical movement should be allowed.
void CSceneNodeAnimatorCameraFPS::setVerticalMovement(bool allow) void CSceneNodeAnimatorCameraFPS::setVerticalMovement(bool allow)
...@@ -345,12 +341,6 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(ISceneNode* node, I ...@@ -345,12 +341,6 @@ ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(ISceneNode* node, I
} }
void CSceneNodeAnimatorCameraFPS::setKeyMap(const core::array<SCamKeyMap>& keymap)
{
KeyMap=keymap;
}
} // namespace scene } // namespace scene
} // namespace irr } // namespace irr
...@@ -53,11 +53,18 @@ namespace scene ...@@ -53,11 +53,18 @@ namespace scene
//! Set the rotation speed //! Set the rotation speed
virtual void setRotateSpeed(f32 rotateSpeed); virtual void setRotateSpeed(f32 rotateSpeed);
//! Sets the keyboard mapping for this animator //! Sets the keyboard mapping for this animator (old style)
//! \param keymap: an array of keyboard mappings, see SKeyMap //! \param keymap: an array of keyboard mappings, see SKeyMap
//! \param count: the size of the keyboard map array //! \param count: the size of the keyboard map array
virtual void setKeyMap(SKeyMap *map, u32 count); virtual void setKeyMap(SKeyMap *map, u32 count);
//! Sets the keyboard mapping for this animator
//! \param keymap The new keymap array
virtual void setKeyMap(const core::array<SKeyMap>& keymap);
//! Gets the keyboard mapping for this animator
virtual const core::array<SKeyMap>& getKeyMap() const;
//! Sets whether vertical movement should be allowed. //! Sets whether vertical movement should be allowed.
virtual void setVerticalMovement(bool allow); virtual void setVerticalMovement(bool allow);
...@@ -84,20 +91,6 @@ namespace scene ...@@ -84,20 +91,6 @@ namespace scene
done with it. */ done with it. */
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0);
struct SCamKeyMap
{
SCamKeyMap() {};
SCamKeyMap(s32 a, EKEY_CODE k) : action(a), keycode(k) {}
s32 action;
EKEY_CODE keycode;
};
//! Sets the keyboard mapping for this animator
/** Helper function for the clone method.
\param keymap the new keymap array */
void setKeyMap(const core::array<SCamKeyMap>& keymap);
private: private:
void allKeysUp(); void allKeysUp();
...@@ -113,10 +106,10 @@ namespace scene ...@@ -113,10 +106,10 @@ namespace scene
s32 LastAnimationTime; s32 LastAnimationTime;
core::array<SCamKeyMap> KeyMap; core::array<SKeyMap> KeyMap;
core::position2d<f32> CenterCursor, CursorPos; core::position2d<f32> CenterCursor, CursorPos;
bool CursorKeys[6]; bool CursorKeys[EKA_COUNT];
bool firstUpdate; bool firstUpdate;
bool NoVerticalMovement; bool NoVerticalMovement;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment