Commit f524ab2b authored by bitplane's avatar bitplane

ISceneNodeAnimator now inherits IEventReceiver, cameras send events to their...

ISceneNodeAnimator now inherits IEventReceiver, cameras send events to their animators. FPS and Maya cameras are now animators.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1321 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 304c3b24
Changes in version 1.5 (... 2008)
- FPS and Maya style cameras are now standard cameras with a special animator.
- ISceneNodeAnimator now inherits IEventReceiver
- New method ISceneNodeAnimator::isEventReceiverEnabled, returns false by default
- CCameraSceneNode::OnEvent passes events to animators with enabled event receivers
- ISceneNodeAnimatorCameraFPS and ISceneNodeAnimatorCameraMaya interfaces for changing camera settings at run-time.
- Fixed a performance bug in ISceneNode constructor reported by izhbq412
- Added volume light scene node
......
......@@ -34,6 +34,12 @@ namespace scene
//! Collision respose scene node animator
ESNAT_COLLISION_RESPONSE,
//! FPS camera animator
ESNAT_CAMERA_FPS,
//! Maya camera animator
ESNAT_CAMERA_MAYA,
//! Amount of built-in scene node animators
ESNAT_COUNT,
......
......@@ -57,12 +57,6 @@ namespace scene
//! Camera Scene Node
ESNT_CAMERA = MAKE_IRR_ID('c','a','m','_'),
//! Maya Camera Scene Node
ESNT_CAMERA_MAYA = MAKE_IRR_ID('c','a','m','M'),
//! First Person Shooter style Camera
ESNT_CAMERA_FPS = MAKE_IRR_ID('c','a','m','F'),
//! Billboard Scene Node
ESNT_BILLBOARD = MAKE_IRR_ID('b','i','l','l'),
......@@ -76,7 +70,16 @@ namespace scene
ESNT_MD3_SCENE_NODE = MAKE_IRR_ID('m','d','3','_'),
//! Unknown scene node
ESNT_UNKNOWN = MAKE_IRR_ID('u','n','k','n')
ESNT_UNKNOWN = MAKE_IRR_ID('u','n','k','n'),
//! Maya Camera Scene Node
//! Legacy, for loading version <= 1.4.x .irr files
ESNT_CAMERA_MAYA = MAKE_IRR_ID('c','a','m','M'),
//! First Person Shooter Camera
//! Legacy, for loading version <= 1.4.x .irr files
ESNT_CAMERA_FPS = MAKE_IRR_ID('c','a','m','F')
};
......
......@@ -478,8 +478,8 @@ namespace scene
const core::vector3df& lookat = core::vector3df(0,0,100), s32 id=-1) = 0;
//! Adds a maya style user controlled camera scene node to the scene graph.
/** The maya camera is able to be controlled with the mouse similar
like in the 3D Software Maya by Alias Wavefront.
/** This is a standard camera with an animator that provides mouse control similar
to camera in the 3D Software Maya by Alias Wavefront.
\param parent: Parent scene node of the camera. Can be null.
\param rotateSpeed: Rotation speed of the camera.
\param zoomSpeed: Zoom speed of the camera.
......@@ -490,7 +490,8 @@ namespace scene
virtual ICameraSceneNode* addCameraSceneNodeMaya(ISceneNode* parent = 0,
f32 rotateSpeed = -1500.0f, f32 zoomSpeed = 200.0f, f32 translationSpeed = 1500.0f, s32 id=-1) = 0;
//! Adds a camera scene node which is able to be controlled with the mouse and keys like in most first person shooters (FPS).
//! Adds a camera scene node with an animator which provides mouse and keyboard control
//! like in most first person shooters (FPS).
/** Look with the mouse, move with cursor keys. If you do not like the default
key layout, you may want to specify your own. For example to make the camera
be controlled by the cursor keys AND the keys W,A,S, and D, do something
......
......@@ -9,6 +9,7 @@
#include "vector3d.h"
#include "ESceneNodeAnimatorTypes.h"
#include "IAttributeExchangingObject.h"
#include "IEventReceiver.h"
namespace irr
{
......@@ -26,7 +27,7 @@ namespace scene
change its position, rotation, scale and/or material. There are lots of animators
to choose from. You can create scene node animators with the ISceneManager interface.
*/
class ISceneNodeAnimator : public io::IAttributeExchangingObject
class ISceneNodeAnimator : public io::IAttributeExchangingObject, public IEventReceiver
{
public:
......@@ -46,6 +47,20 @@ namespace scene
return 0; // to be implemented by derived classes.
}
//! Returns true if this animator receives events.
//! When attached to the an active camera, this animator will be able to respond to events
//! such as mouse and keyboard events.
virtual bool isEventReceiverEnabled() const
{
return false;
}
//! Event receiver, override this function for camera controlling animators
virtual bool OnEvent(const SEvent& event)
{
return false;
}
//! Returns type of the scene node animator
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
{
......
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __I_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED__
#define __I_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED__
#include "ISceneNodeAnimator.h"
#include "IEventReceiver.h"
namespace irr
{
struct SKeyMap;
namespace scene
{
//! Special scene node animator for FPS cameras
/** This scene node animator can be attached to a camera to make it act like a first
person shooter
*/
class ISceneNodeAnimatorCameraFPS : public ISceneNodeAnimator
{
public:
//! Returns the speed of movement in units per millisecond
virtual f32 getMoveSpeed() const = 0;
//! Sets the speed of movement in units per millisecond
virtual void setMoveSpeed(f32 moveSpeed) = 0;
//! Returns the rotation speed
virtual f32 getRotateSpeed() const = 0;
//! Set the rotation speed
virtual void setRotateSpeed(f32 rotateSpeed) = 0;
//! Sets the keyboard mapping for this animator
//! \param keymap: an array of keyboard mappings, see SKeyMap
//! \param count: the size of the keyboard map array
virtual void setKeyMap(SKeyMap *map, u32 count) = 0;
//! Sets whether vertical movement should be allowed.
//! If vertical movement is enabled then the camera may fight with
//! gravity causing camera shake. Disable this if the camera has
//! a collision animator with gravity enabled.
virtual void setVerticalMovement(bool allow) = 0;
};
} // end namespace scene
} // end namespace irr
#endif
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __I_SCENE_NODE_ANIMATOR_CAMERA_MAYA_H_INCLUDED__
#define __I_SCENE_NODE_ANIMATOR_CAMERA_MAYA_H_INCLUDED__
#include "ISceneNodeAnimator.h"
namespace irr
{
namespace scene
{
//! Special scene node animator for FPS cameras
/** This scene node animator can be attached to a camera to make it act like a first
person shooter
*/
class ISceneNodeAnimatorCameraMaya : public ISceneNodeAnimator
{
public:
//! Returns the speed of movement in units per millisecond
virtual f32 getMoveSpeed() const = 0;
//! Sets the speed of movement in units per millisecond
virtual void setMoveSpeed(f32 moveSpeed) = 0;
//! Returns the rotation speed
virtual f32 getRotateSpeed() const = 0;
//! Set the rotation speed
virtual void setRotateSpeed(f32 rotateSpeed) = 0;
//! Returns the zoom speed
virtual f32 getZoomSpeed() const = 0;
//! Set the zoom speed
virtual void setZoomSpeed(f32 zoomSpeed) = 0;
};
} // end namespace scene
} // end namespace irr
#endif
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CCameraFPSSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "os.h"
#include "Keycodes.h"
namespace irr
{
namespace scene
{
const f32 MAX_VERTICAL_ANGLE = 88.0f;
//! constructor
CCameraFPSSceneNode::CCameraFPSSceneNode(ISceneNode* parent, ISceneManager* mgr,
gui::ICursorControl* cursorControl, s32 id, f32 rotateSpeed , f32 moveSpeed,f32 jumpSpeed,
SKeyMap* keyMapArray, s32 keyMapSize, bool noVerticalMovement)
: CCameraSceneNode(parent, mgr, id), CursorControl(cursorControl),
MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed),
firstUpdate(true), LastAnimationTime(0), NoVerticalMovement(noVerticalMovement)
{
#ifdef _DEBUG
setDebugName("CCameraFPSSceneNode");
#endif
if (CursorControl)
CursorControl->grab();
MoveSpeed /= 1000.0f;
recalculateViewArea();
allKeysUp();
// create key map
if (!keyMapArray || !keyMapSize)
{
// create default key map
KeyMap.push_back(SCamKeyMap(0, irr::KEY_UP));
KeyMap.push_back(SCamKeyMap(1, irr::KEY_DOWN));
KeyMap.push_back(SCamKeyMap(2, irr::KEY_LEFT));
KeyMap.push_back(SCamKeyMap(3, irr::KEY_RIGHT));
KeyMap.push_back(SCamKeyMap(4, irr::KEY_KEY_J));
}
else
{
// create custom key map
for (s32 i=0; i<keyMapSize; ++i)
{
switch(keyMapArray[i].Action)
{
case EKA_MOVE_FORWARD: KeyMap.push_back(SCamKeyMap(0, keyMapArray[i].KeyCode));
break;
case EKA_MOVE_BACKWARD: KeyMap.push_back(SCamKeyMap(1, keyMapArray[i].KeyCode));
break;
case EKA_STRAFE_LEFT: KeyMap.push_back(SCamKeyMap(2, keyMapArray[i].KeyCode));
break;
case EKA_STRAFE_RIGHT: KeyMap.push_back(SCamKeyMap(3, keyMapArray[i].KeyCode));
break;
case EKA_JUMP_UP: KeyMap.push_back(SCamKeyMap(4, keyMapArray[i].KeyCode));
break;
default:
break;
} // end switch
} // end for
}// end if
}
//! destructor
CCameraFPSSceneNode::~CCameraFPSSceneNode()
{
if (CursorControl)
CursorControl->drop();
}
//! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addFPSCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
bool CCameraFPSSceneNode::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
const u32 cnt = KeyMap.size();
for (u32 i=0; i<cnt; ++i)
if (KeyMap[i].keycode == event.KeyInput.Key)
{
CursorKeys[KeyMap[i].action] = event.KeyInput.PressedDown;
if ( InputReceiverEnabled )
return true;
}
}
return false;
}
//! OnAnimate() is called just before rendering the whole scene.
//! nodes may calculate or store animations here, and may do other useful things,
//! dependent on what they are.
void CCameraFPSSceneNode::OnAnimate(u32 timeMs)
{
animate( timeMs );
core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin();
for (; ait != Animators.end(); ++ait)
(*ait)->animateNode(this, timeMs);
updateAbsolutePosition();
Target = getPosition() + TargetVector;
core::list<ISceneNode*>::Iterator it = Children.begin();
for (; it != Children.end(); ++it)
(*it)->OnAnimate(timeMs);
}
void CCameraFPSSceneNode::animate( u32 timeMs )
{
const u32 camIsMe = SceneManager->getActiveCamera() == this;
if (firstUpdate)
{
if (CursorControl && camIsMe)
{
CursorControl->setPosition(0.5f, 0.5f);
CenterCursor = CursorControl->getRelativePosition();
}
LastAnimationTime = os::Timer::getTime();
firstUpdate = false;
}
// get time. only operate on valid camera
f32 timeDiff = 0.f;
if ( camIsMe )
{
timeDiff = (f32) ( timeMs - LastAnimationTime );
LastAnimationTime = timeMs;
}
// update position
core::vector3df pos = getPosition();
// Update rotation
// if (InputReceiverEnabled)
{
Target.set(0,0,1);
if (CursorControl && InputReceiverEnabled && camIsMe )
{
core::position2d<f32> cursorpos = CursorControl->getRelativePosition();
if (!core::equals(cursorpos.X, CenterCursor.X) ||
!core::equals(cursorpos.Y, CenterCursor.Y))
{
RelativeRotation.X *= -1.0f;
RelativeRotation.Y *= -1.0f;
RelativeRotation.Y += (0.5f - cursorpos.X) * RotateSpeed;
RelativeRotation.X = core::clamp(
RelativeRotation.X + (0.5f - cursorpos.Y) * RotateSpeed,
-MAX_VERTICAL_ANGLE,
+MAX_VERTICAL_ANGLE);
RelativeRotation.X *= -1.0f;
RelativeRotation.Y *= -1.0f;
CursorControl->setPosition(0.5f, 0.5f);
CenterCursor = CursorControl->getRelativePosition();
}
}
// set target
core::matrix4 mat;
mat.setRotationDegrees(core::vector3df( RelativeRotation.X, RelativeRotation.Y, 0));
mat.transformVect(Target);
core::vector3df movedir = Target;
if (NoVerticalMovement)
movedir.Y = 0.f;
movedir.normalize();
if (InputReceiverEnabled && camIsMe)
{
if (CursorKeys[0])
pos += movedir * timeDiff * MoveSpeed;
if (CursorKeys[1])
pos -= movedir * timeDiff * MoveSpeed;
// strafing
core::vector3df strafevect = Target;
strafevect = strafevect.crossProduct(UpVector);
if (NoVerticalMovement)
strafevect.Y = 0.0f;
strafevect.normalize();
if (CursorKeys[2])
pos += strafevect * timeDiff * MoveSpeed;
if (CursorKeys[3])
pos -= strafevect * timeDiff * MoveSpeed;
// jumping ( need's a gravity , else it's a fly to the World-UpVector )
if (CursorKeys[4])
{
pos += UpVector * timeDiff * JumpSpeed;
}
}
// write translation
setPosition(pos);
}
// write right target
TargetVector = Target;
Target += pos;
}
void CCameraFPSSceneNode::allKeysUp()
{
for (s32 i=0; i<6; ++i)
CursorKeys[i] = false;
}
//! sets the look at target of the camera
//! \param pos: Look at target of the camera.
void CCameraFPSSceneNode::setTarget(const core::vector3df& tgt)
{
updateAbsolutePosition();
core::vector3df vect = tgt - getAbsolutePosition();
vect = vect.getHorizontalAngle();
RelativeRotation.X = vect.X;
RelativeRotation.Y = vect.Y;
if (RelativeRotation.X > MAX_VERTICAL_ANGLE)
RelativeRotation.X -= 360.0f;
}
//! Disables or enables the camera to get key or mouse inputs.
void CCameraFPSSceneNode::setInputReceiverEnabled(bool enabled)
{
// So we don't skip when we return from a non-enabled mode and the
// mouse cursor is now not in the middle of the screen
if( !InputReceiverEnabled && enabled )
firstUpdate = true;
InputReceiverEnabled = enabled;
}
//! Sets the rotation speed
void CCameraFPSSceneNode::setRotateSpeed(const f32 speed)
{
RotateSpeed = speed;
}
//! Sets the movement speed
void CCameraFPSSceneNode::setMoveSpeed(const f32 speed)
{
MoveSpeed = speed;
}
//! Gets the rotation speed
f32 CCameraFPSSceneNode::getRotateSpeed()
{
return RotateSpeed;
}
// Gets the movement speed
f32 CCameraFPSSceneNode::getMoveSpeed()
{
return MoveSpeed;
}
} // end namespace
} // end namespace
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_CAMERA_FPS_SCENE_NODE_H_INCLUDED__
#define __C_CAMERA_FPS_SCENE_NODE_H_INCLUDED__
#include "ICursorControl.h"
#include "CCameraSceneNode.h"
#include "vector2d.h"
#include "SKeyMap.h"
#include "irrArray.h"
namespace irr
{
namespace scene
{
class CCameraFPSSceneNode : public CCameraSceneNode
{
public:
//! constructor
CCameraFPSSceneNode(ISceneNode* parent, ISceneManager* mgr,
gui::ICursorControl* cursorControl, s32 id,
f32 rotateSpeed, f32 moveSpeed,f32 jumpSpeed,
SKeyMap* keyMapArray, s32 keyMapSize, bool noVerticalMovement = false );
//! destructor
virtual ~CCameraFPSSceneNode();
//! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
virtual bool OnEvent(const SEvent& event);
//! OnAnimate() is called just before rendering the whole scene.
//! nodes may calculate or store animations here, and may do other useful things,
//! dependent on what they are.
virtual void OnAnimate(u32 timeMs);
//! sets the look at target of the camera
//! \param pos: Look at target of the camera.
virtual void setTarget(const core::vector3df& pos);
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA_FPS; }
//! Disables or enables the camera to get key or mouse inputs.
//! If this is set to true, the camera will respond to key inputs
//! otherwise not.
virtual void setInputReceiverEnabled(bool enabled);
//! Sets the speed that this camera rotates
virtual void setRotateSpeed(const f32 speed);
//! Sets the speed that this camera moves
virtual void setMoveSpeed(const f32 speed);
//! Gets the rotation speed
virtual f32 getRotateSpeed();
// Gets the movement speed
virtual f32 getMoveSpeed();
private:
struct SCamKeyMap
{
SCamKeyMap() {};
SCamKeyMap(s32 a, EKEY_CODE k) : action(a), keycode(k) {}
s32 action;
EKEY_CODE keycode;
};
void allKeysUp();
void animate( u32 timeMs );
bool CursorKeys[6];
gui::ICursorControl* CursorControl;
f32 MoveSpeed;
f32 RotateSpeed;
f32 JumpSpeed;
bool firstUpdate;
s32 LastAnimationTime;
core::vector3df TargetVector;
core::array<SCamKeyMap> KeyMap;
core::position2d<f32> CenterCursor;
bool NoVerticalMovement;
};
} // end namespace
} // end namespace
#endif
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_CAMERA_MAYA_SCENE_NODE_H_INCLUDED__
#define __C_CAMERA_MAYA_SCENE_NODE_H_INCLUDED__
#include "CCameraSceneNode.h"
#include "vector2d.h"
namespace irr
{
namespace scene
{
class CCameraMayaSceneNode : public CCameraSceneNode
{
public:
//! constructor
CCameraMayaSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
f32 rotateSpeed = -1500.0f, f32 zoomSpeed = 200.0f, f32 translationSpeed = 100.0f);
//! destructor
virtual ~CCameraMayaSceneNode();
//! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
virtual bool OnEvent(const SEvent& event);
//! OnAnimate() is called just before rendering the whole scene.
//! nodes may calculate or store animations here, and may do other useful things,
//! dependent on what they are.
virtual void OnAnimate(u32 timeMs);
//! Sets the position of the node. Note that the position is
//! relative to the parent.
virtual void setPosition(const core::vector3df& newpos);
//! Sets the position of the node. Note that the position is
//! relative to the parent.
virtual void setTarget(const core::vector3df& newpos);
//! Sets the rotation speed
virtual void setRotateSpeed(const f32 speed);
//! Sets the movement speed
virtual void setMoveSpeed(const f32 speed);
//! Gets the rotation speed
virtual f32 getRotateSpeed();
// Gets the movement speed
virtual f32 getMoveSpeed();
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA_MAYA; }
private:
void allKeysUp();
void animate();
bool isMouseKeyDown(s32 key);
void updateAnimationState();
bool MouseKeys[3];
core::vector3df Pos;
bool Zooming, Rotating, Moving, Translating;
f32 ZoomSpeed;
f32 RotateSpeed;
f32 TranslateSpeed;
f32 RotateStartX, RotateStartY;
f32 ZoomStartX, ZoomStartY;
f32 TranslateStartX, TranslateStartY;
f32 CurrentZoom;
f32 RotX, RotY;
core::vector3df OldTarget;
core::vector2df MousePos;
};
} // end namespace
} // end namespace
#endif
......@@ -103,6 +103,18 @@ const core::matrix4& CCameraSceneNode::getViewMatrix() const
//! for changing their position, look at target or whatever.
bool CCameraSceneNode::OnEvent(const SEvent& event)
{
if (!InputReceiverEnabled)
return false;
// send events to event receiving animators
core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin();
for (; ait != Animators.end(); ++ait)
if ((*ait)->isEventReceiverEnabled() && (*ait)->OnEvent(event))
return true;
// if nobody processed the event, return false
return false;
}
......
......@@ -3,6 +3,9 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CDefaultSceneNodeAnimatorFactory.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "ICursorControl.h"
#include "ISceneNodeAnimatorCollisionResponse.h"
#include "ISceneManager.h"
......@@ -21,16 +24,25 @@ const c8* const SceneNodeAnimatorTypeNames[] =
"texture",
"deletion",
"collisionResponse",
"cameraFPS",
"cameraMaya",
0
};
CDefaultSceneNodeAnimatorFactory::CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr)
: Manager(mgr)
CDefaultSceneNodeAnimatorFactory::CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr, gui::ICursorControl* crs)
: Manager(mgr), CursorControl(crs)
{
// don't grab the scene manager here to prevent cyclic references
if (CursorControl)
CursorControl->grab();
}
CDefaultSceneNodeAnimatorFactory::~CDefaultSceneNodeAnimatorFactory()
{
if (CursorControl)
CursorControl->drop();
}
//! creates a scene node animator based on its type id
ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target)
......@@ -68,6 +80,12 @@ ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(ES
case ESNAT_COLLISION_RESPONSE:
anim = Manager->createCollisionResponseAnimator(0, target);
break;
case ESNAT_CAMERA_FPS:
anim = new CSceneNodeAnimatorCameraFPS(CursorControl);
break;
case ESNAT_CAMERA_MAYA:
anim = new CSceneNodeAnimatorCameraMaya(CursorControl);
break;
default:
break;
}
......
......@@ -9,6 +9,10 @@
namespace irr
{
namespace gui
{
class ICursorControl;
}
namespace scene
{
class ISceneNodeAnimator;
......@@ -19,7 +23,9 @@ namespace scene
{
public:
CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr);
CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr, gui::ICursorControl* crs);
virtual ~CDefaultSceneNodeAnimatorFactory();
//! creates a scene node animator based on its type id
/** \param type: Type of the scene node animator to add.
......@@ -58,6 +64,7 @@ namespace scene
ESCENE_NODE_ANIMATOR_TYPE getTypeFromName(const c8* name) const;
ISceneManager* Manager;
gui::ICursorControl* CursorControl;
};
......
......@@ -38,12 +38,14 @@ CDefaultSceneNodeFactory::CDefaultSceneNodeFactory(ISceneManager* mgr)
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_EMPTY, "empty"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_DUMMY_TRANSFORMATION, "dummyTransformation"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA, "camera"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_MAYA, "cameraMaya"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_FPS, "cameraFPS"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_BILLBOARD, "billBoard"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_ANIMATED_MESH, "animatedMesh"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_PARTICLE_SYSTEM, "particleSystem"));
// SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_MD3_SCENE_NODE, "md3"));
// legacy, for version <= 1.4.x irr files
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_MAYA, "cameraMaya"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_CAMERA_FPS, "cameraFPS"));
}
......
......@@ -108,8 +108,7 @@
#include "CAnimatedMeshSceneNode.h"
#include "COctTreeSceneNode.h"
#include "CCameraSceneNode.h"
#include "CCameraMayaSceneNode.h"
#include "CCameraFPSSceneNode.h"
#include "CLightSceneNode.h"
#include "CBillboardSceneNode.h"
#include "CMeshSceneNode.h"
......@@ -138,6 +137,8 @@
#include "CSceneNodeAnimatorCollisionResponse.h"
#include "CSceneNodeAnimatorDelete.h"
#include "CSceneNodeAnimatorFollowSpline.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "CDefaultSceneNodeAnimatorFactory.h"
#include "CQuake3ShaderSceneNode.h"
......@@ -252,7 +253,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
registerSceneNodeFactory(factory);
factory->drop();
ISceneNodeAnimatorFactory* animatorFactory = new CDefaultSceneNodeAnimatorFactory(this);
ISceneNodeAnimatorFactory* animatorFactory = new CDefaultSceneNodeAnimatorFactory(this, CursorControl);
registerSceneNodeAnimatorFactory(animatorFactory);
animatorFactory->drop();
}
......@@ -625,8 +626,8 @@ ICameraSceneNode* CSceneManager::addCameraSceneNode(ISceneNode* parent,
}
//! Adds a camera scene node which is able to be controlle with the mouse similar
//! like in the 3D Software Maya by Alias Wavefront.
//! Adds a camera scene node which is able to be controlld with the mouse similar
//! to in the 3D Software Maya by Alias Wavefront.
//! The returned pointer must not be dropped.
ICameraSceneNode* CSceneManager::addCameraSceneNodeMaya(ISceneNode* parent,
f32 rotateSpeed, f32 zoomSpeed, f32 translationSpeed, s32 id)
......@@ -634,8 +635,12 @@ ICameraSceneNode* CSceneManager::addCameraSceneNodeMaya(ISceneNode* parent,
if (!parent)
parent = this;
ICameraSceneNode* node = new CCameraMayaSceneNode(parent, this, id, rotateSpeed,
zoomSpeed, translationSpeed);
ICameraSceneNode* node = new CCameraSceneNode(parent, this, id);
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraMaya(CursorControl,
rotateSpeed, zoomSpeed, translationSpeed);
node->addAnimator(anm);
anm->drop();
node->drop();
setActiveCamera(node);
......@@ -653,12 +658,17 @@ ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(ISceneNode* parent,
if (!parent)
parent = this;
ICameraSceneNode* node = new CCameraFPSSceneNode(parent, this, CursorControl,
id, rotateSpeed, moveSpeed, jumpSpeed, keyMapArray, keyMapSize, noVerticalMovement);
ICameraSceneNode* node = new CCameraSceneNode(parent, this, id);
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraFPS(CursorControl, rotateSpeed,
moveSpeed, jumpSpeed, keyMapArray, keyMapSize, noVerticalMovement);
node->addAnimator(anm);
anm->drop();
node->drop();
setActiveCamera(node);
return node;
}
......
#include "CSceneNodeAnimatorCameraFPS.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "Keycodes.h"
#include "ICursorControl.h"
#include "ICameraSceneNode.h"
namespace irr
{
namespace scene
{
const f32 MAX_VERTICAL_ANGLE = 88.0f;
//! constructor
CSceneNodeAnimatorCameraFPS::CSceneNodeAnimatorCameraFPS(gui::ICursorControl* cursorControl, f32 rotateSpeed,
f32 moveSpeed, f32 jumpSpeed, SKeyMap* keyMapArray, s32 keyMapSize, bool noVerticalMovement)
: CursorControl(cursorControl), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed),
firstUpdate(true), LastAnimationTime(0), NoVerticalMovement(noVerticalMovement)
{
#ifdef _DEBUG
setDebugName("CCameraSceneNodeAnimatorFPS");
#endif
if (CursorControl)
CursorControl->grab();
MoveSpeed /= 1000.0f;
allKeysUp();
// create key map
if (!keyMapArray || !keyMapSize)
{
// create default key map
KeyMap.push_back(SCamKeyMap(0, irr::KEY_UP));
KeyMap.push_back(SCamKeyMap(1, irr::KEY_DOWN));
KeyMap.push_back(SCamKeyMap(2, irr::KEY_LEFT));
KeyMap.push_back(SCamKeyMap(3, irr::KEY_RIGHT));
KeyMap.push_back(SCamKeyMap(4, irr::KEY_KEY_J));
}
else
{
// create custom key map
setKeyMap(keyMapArray, keyMapSize);
}// end if
}
//! destructor
CSceneNodeAnimatorCameraFPS::~CSceneNodeAnimatorCameraFPS()
{
if (CursorControl)
CursorControl->drop();
}
//! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addFPSCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
bool CSceneNodeAnimatorCameraFPS::OnEvent(const SEvent& evt)
{
switch(evt.EventType)
{
case EET_KEY_INPUT_EVENT:
for (u32 i=0; i<KeyMap.size(); ++i)
if (KeyMap[i].keycode == evt.KeyInput.Key)
{
CursorKeys[KeyMap[i].action] = evt.KeyInput.PressedDown;
return true;
}
break;
case EET_MOUSE_INPUT_EVENT:
if (evt.MouseInput.Event == EMIE_MOUSE_MOVED)
{
CursorPos = CursorControl->getRelativePosition();
return true;
}
break;
default:
break;
}
return false;
}
void CSceneNodeAnimatorCameraFPS::animateNode(ISceneNode* node, u32 timeMs)
{
ICameraSceneNode* camera = 0;
if (node->getType() != ESNT_CAMERA)
return;
camera = static_cast<ICameraSceneNode*>(node);
if (firstUpdate)
{
if (CursorControl && camera)
{
CursorControl->setPosition(0.5f, 0.5f);
CursorPos = CenterCursor = CursorControl->getRelativePosition();
}
LastAnimationTime = timeMs;
firstUpdate = false;
}
// get time
f32 timeDiff = 0.f;
timeDiff = (f32) ( timeMs - LastAnimationTime );
LastAnimationTime = timeMs;
// update position
core::vector3df pos = camera->getPosition();
// Update rotation
core::vector3df Target = (camera->getTarget() - camera->getAbsolutePosition());
core::vector3df RelativeRotation = Target.getHorizontalAngle();
if (CursorControl)
{
if (CursorPos != CenterCursor)
{
RelativeRotation.Y -= (0.5f - CursorPos.X) * RotateSpeed;
RelativeRotation.X -= (0.5f - CursorPos.Y) * RotateSpeed;
// X < MAX_VERTICAL_ANGLE or X > 360-MAX_VERTICAL_ANGLE
if (RelativeRotation.X > MAX_VERTICAL_ANGLE*2 &&
RelativeRotation.X < 360.0f-MAX_VERTICAL_ANGLE)
{
RelativeRotation.X = 360.0f-MAX_VERTICAL_ANGLE;
}
else
if (RelativeRotation.X > MAX_VERTICAL_ANGLE &&
RelativeRotation.X < 360.0f-MAX_VERTICAL_ANGLE)
{
RelativeRotation.X = MAX_VERTICAL_ANGLE;
}
// reset cursor position
CursorControl->setPosition(0.5f, 0.5f);
CenterCursor = CursorControl->getRelativePosition();
}
}
// set target
Target.set(0,0,1);
core::matrix4 mat;
mat.setRotationDegrees(core::vector3df( RelativeRotation.X, RelativeRotation.Y, 0));
mat.transformVect(Target);
core::vector3df movedir = Target;
if (NoVerticalMovement)
movedir.Y = 0.f;
movedir.normalize();
if (CursorKeys[0])
pos += movedir * timeDiff * MoveSpeed;
if (CursorKeys[1])
pos -= movedir * timeDiff * MoveSpeed;
// strafing
core::vector3df strafevect = Target;
strafevect = strafevect.crossProduct(camera->getUpVector());
if (NoVerticalMovement)
strafevect.Y = 0.0f;
strafevect.normalize();
if (CursorKeys[2])
pos += strafevect * timeDiff * MoveSpeed;
if (CursorKeys[3])
pos -= strafevect * timeDiff * MoveSpeed;
// jumping ( need's a gravity , else it's a fly to the World-UpVector )
if (CursorKeys[4])
{
pos += camera->getUpVector() * timeDiff * JumpSpeed;
}
// write translation
camera->setPosition(pos);
// write right target
TargetVector = Target;
Target += pos;
camera->setTarget(Target);
}
void CSceneNodeAnimatorCameraFPS::allKeysUp()
{
for (s32 i=0; i<6; ++i)
CursorKeys[i] = false;
}
//! Sets the rotation speed
void CSceneNodeAnimatorCameraFPS::setRotateSpeed(f32 speed)
{
RotateSpeed = speed;
}
//! Sets the movement speed
void CSceneNodeAnimatorCameraFPS::setMoveSpeed(f32 speed)
{
MoveSpeed = speed;
}
//! Gets the rotation speed
f32 CSceneNodeAnimatorCameraFPS::getRotateSpeed() const
{
return RotateSpeed;
}
// Gets the movement speed
f32 CSceneNodeAnimatorCameraFPS::getMoveSpeed() const
{
return MoveSpeed;
}
//! Sets the keyboard mapping for this animator
void CSceneNodeAnimatorCameraFPS::setKeyMap(SKeyMap *map, u32 count)
{
// clear the keymap
KeyMap.clear();
// add actions
for (u32 i=0; i<count; ++i)
{
switch(map[i].Action)
{
case EKA_MOVE_FORWARD: KeyMap.push_back(SCamKeyMap(0, map[i].KeyCode));
break;
case EKA_MOVE_BACKWARD: KeyMap.push_back(SCamKeyMap(1, map[i].KeyCode));
break;
case EKA_STRAFE_LEFT: KeyMap.push_back(SCamKeyMap(2, map[i].KeyCode));
break;
case EKA_STRAFE_RIGHT: KeyMap.push_back(SCamKeyMap(3, map[i].KeyCode));
break;
case EKA_JUMP_UP: KeyMap.push_back(SCamKeyMap(4, map[i].KeyCode));
break;
default:
break;
}
}
}
//! Sets whether vertical movement should be allowed.
void CSceneNodeAnimatorCameraFPS::setVerticalMovement(bool allow)
{
NoVerticalMovement = !allow;
}
} // namespace scene
} // namespace irr
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED__
#define __C_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED__
#include "ISceneNodeAnimatorCameraFPS.h"
#include "vector2d.h"
#include "SKeyMap.h"
#include "irrArray.h"
namespace irr
{
namespace gui
{
class ICursorControl;
}
namespace scene
{
//! Special scene node animator for FPS cameras
class CSceneNodeAnimatorCameraFPS : public ISceneNodeAnimatorCameraFPS
{
public:
//! Constructor
CSceneNodeAnimatorCameraFPS(gui::ICursorControl* cursorControl,
f32 rotateSpeed = 100.0f, f32 moveSpeed = 500.0f, f32 jumpSpeed=0.f,
SKeyMap* keyMapArray=0, s32 keyMapSize=0, bool noVerticalMovement=false);
//! Destructor
virtual ~CSceneNodeAnimatorCameraFPS();
//! Animates the scene node, currently only works on cameras
virtual void animateNode(ISceneNode* node, u32 timeMs);
//! Event receiver
virtual bool OnEvent(const SEvent& event);
//! Returns the speed of movement in units per millisecond
virtual f32 getMoveSpeed() const;
//! Sets the speed of movement in units per millisecond
virtual void setMoveSpeed(f32 moveSpeed);
//! Returns the rotation speed
virtual f32 getRotateSpeed() const;
//! Set the rotation speed
virtual void setRotateSpeed(f32 rotateSpeed);
//! Sets the keyboard mapping for this animator
//! \param keymap: an array of keyboard mappings, see SKeyMap
//! \param count: the size of the keyboard map array
virtual void setKeyMap(SKeyMap *map, u32 count);
//! Sets whether vertical movement should be allowed.
virtual void setVerticalMovement(bool allow);
//! This animator will receive events when attached to the active camera
virtual bool isEventReceiverEnabled() const
{
return true;
}
//! Returns the type of this animator
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
{
return ESNAT_CAMERA_FPS;
}
private:
struct SCamKeyMap
{
SCamKeyMap() {};
SCamKeyMap(s32 a, EKEY_CODE k) : action(a), keycode(k) {}
s32 action;
EKEY_CODE keycode;
};
void allKeysUp();
bool CursorKeys[6];
gui::ICursorControl *CursorControl;
f32 MoveSpeed;
f32 RotateSpeed;
f32 JumpSpeed;
bool firstUpdate;
s32 LastAnimationTime;
core::vector3df TargetVector;
core::array<SCamKeyMap> KeyMap;
core::position2d<f32> CenterCursor, CursorPos;
bool NoVerticalMovement;
};
} // end namespace scene
} // end namespace irr
#endif // __C_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED__
......@@ -2,9 +2,10 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CCameraMayaSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "ICursorControl.h"
#include "ICameraSceneNode.h"
#include "SViewFrustum.h"
namespace irr
{
......@@ -12,29 +13,28 @@ namespace scene
{
//! constructor
CCameraMayaSceneNode::CCameraMayaSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
f32 rs, f32 zs, f32 ts)
: CCameraSceneNode(parent, mgr, id),
Zooming(false), Rotating(false), Moving(false), Translating(false),
ZoomSpeed(zs), RotateSpeed(rs), TranslateSpeed(ts),
CSceneNodeAnimatorCameraMaya::CSceneNodeAnimatorCameraMaya(gui::ICursorControl* cursor, f32 rotate, f32 zoom, f32 translate)
: CursorControl(cursor), Zooming(false), Rotating(false), Moving(false), Translating(false),
ZoomSpeed(zoom), RotateSpeed(rotate), TranslateSpeed(translate),
RotateStartX(0.0f), RotateStartY(0.0f), ZoomStartX(0.0f), ZoomStartY(0.0f),
TranslateStartX(0.0f), TranslateStartY(0.0f), CurrentZoom(70.0f), RotX(0.0f), RotY(0.0f)
{
#ifdef _DEBUG
setDebugName("CCameraMayaSceneNode");
setDebugName("CSceneNodeAnimatorCameraMaya");
#endif
Target.set(0.0f, 0.0f, 0.0f);
OldTarget = Target;
if (CursorControl)
CursorControl->grab();
allKeysUp();
recalculateViewArea();
}
//! destructor
CCameraMayaSceneNode::~CCameraMayaSceneNode()
CSceneNodeAnimatorCameraMaya::~CSceneNodeAnimatorCameraMaya()
{
if (CursorControl)
CursorControl->drop();
}
......@@ -43,10 +43,9 @@ CCameraMayaSceneNode::~CCameraMayaSceneNode()
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
bool CCameraMayaSceneNode::OnEvent(const SEvent& event)
bool CSceneNodeAnimatorCameraMaya::OnEvent(const SEvent& event)
{
if (event.EventType != EET_MOUSE_INPUT_EVENT ||
!InputReceiverEnabled)
if (event.EventType != EET_MOUSE_INPUT_EVENT)
return false;
switch(event.MouseInput.Event)
......@@ -70,15 +69,7 @@ bool CCameraMayaSceneNode::OnEvent(const SEvent& event)
MouseKeys[1] = false;
break;
case EMIE_MOUSE_MOVED:
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if (driver)
{
core::dimension2d<s32> ssize = SceneManager->getVideoDriver()->getScreenSize();
MousePos.X = event.MouseInput.X / (f32)ssize.Width;
MousePos.Y = event.MouseInput.Y / (f32)ssize.Height;
}
}
MousePos = CursorControl->getRelativePosition();
break;
case EMIE_MOUSE_WHEEL:
case EMIE_COUNT:
......@@ -90,32 +81,20 @@ bool CCameraMayaSceneNode::OnEvent(const SEvent& event)
//! OnAnimate() is called just before rendering the whole scene.
//! nodes may calculate or store animations here, and may do other useful things,
//! dependent on what they are.
void CCameraMayaSceneNode::OnAnimate(u32 timeMs)
{
animate();
ISceneNode::setPosition(Pos);
updateAbsolutePosition();
// This scene node cannot be animated by scene node animators, so
// don't invoke them.
}
bool CCameraMayaSceneNode::isMouseKeyDown(s32 key)
{
return MouseKeys[key];
}
void CCameraMayaSceneNode::animate()
void CSceneNodeAnimatorCameraMaya::animateNode(ISceneNode *node, u32 timeMs)
{
//Alt + LM = Rotate around camera pivot
//Alt + LM + MM = Dolly forth/back in view direction (speed % distance camera pivot - max distance to pivot)
//Alt + MM = Move on camera plane (Screen center is about the mouse pointer, depending on move speed)
const SViewFrustum* va = getViewFrustum();
if (node->getType() != ESNT_CAMERA)
return;
ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
Target = camera->getTarget();
const SViewFrustum* va = camera->getViewFrustum();
f32 nRotX = RotX;
f32 nRotY = RotY;
......@@ -160,7 +139,7 @@ void CCameraMayaSceneNode::animate()
// Translation ---------------------------------
core::vector3df translate(OldTarget);
core::vector3df translate(OldTarget), UpVector(camera->getUpVector());
core::vector3df tvectX = Pos - Target;
tvectX = tvectX.crossProduct(UpVector);
......@@ -246,44 +225,27 @@ void CCameraMayaSceneNode::animate()
UpVector.rotateXYBy(-nRotY, core::vector3df(0,0,0));
UpVector.rotateXZBy(-nRotX+180.f, core::vector3df(0,0,0));
/*if (nRotY < 0.0f)
nRotY *= -1.0f;
nRotY = (f32)fmod(nRotY, 360.0f);
if (nRotY >= 90.0f && nRotY <= 270.0f)
UpVector.set(0, -1, 0);
else
UpVector.set(0, 1, 0);*/
camera->setPosition(Pos);
camera->setTarget(Target);
camera->setUpVector(UpVector);
}
void CCameraMayaSceneNode::allKeysUp()
bool CSceneNodeAnimatorCameraMaya::isMouseKeyDown(s32 key)
{
for (s32 i=0; i<3; ++i)
MouseKeys[i] = false;
return MouseKeys[key];
}
// function added by jox: fix setPosition()
void CCameraMayaSceneNode::setPosition(const core::vector3df& pos)
{
Pos = pos;
updateAnimationState();
ISceneNode::setPosition(pos);
}
// function added by jox: fix setTarget()
void CCameraMayaSceneNode::setTarget(const core::vector3df& pos)
void CSceneNodeAnimatorCameraMaya::allKeysUp()
{
Target = OldTarget = pos;
updateAnimationState();
for (s32 i=0; i<3; ++i)
MouseKeys[i] = false;
}
// function added by jox
void CCameraMayaSceneNode::updateAnimationState()
void CSceneNodeAnimatorCameraMaya::updateAnimationState()
{
core::vector3df pos(Pos - Target);
......@@ -301,29 +263,42 @@ void CCameraMayaSceneNode::updateAnimationState()
}
//! Sets the rotation speed
void CCameraMayaSceneNode::setRotateSpeed(const f32 speed)
void CSceneNodeAnimatorCameraMaya::setRotateSpeed(f32 speed)
{
RotateSpeed = speed;
}
//! Sets the movement speed
void CCameraMayaSceneNode::setMoveSpeed(const f32 speed)
void CSceneNodeAnimatorCameraMaya::setMoveSpeed(f32 speed)
{
TranslateSpeed = speed;
}
//! Sets the zoom speed
void CSceneNodeAnimatorCameraMaya::setZoomSpeed(f32 speed)
{
ZoomSpeed = speed;
}
//! Gets the rotation speed
f32 CCameraMayaSceneNode::getRotateSpeed()
f32 CSceneNodeAnimatorCameraMaya::getRotateSpeed() const
{
return RotateSpeed;
}
// Gets the movement speed
f32 CCameraMayaSceneNode::getMoveSpeed()
f32 CSceneNodeAnimatorCameraMaya::getMoveSpeed() const
{
return TranslateSpeed;
}
//! Gets the zoom speed
f32 CSceneNodeAnimatorCameraMaya::getZoomSpeed() const
{
return ZoomSpeed;
}
} // end namespace
} // end namespace
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_SCENE_NODE_ANIMATOR_CAMERA_MAYA_H_INCLUDED__
#define __C_SCENE_NODE_ANIMATOR_CAMERA_MAYA_H_INCLUDED__
#include "ISceneNodeAnimatorCameraMaya.h"
#include "vector2d.h"
namespace irr
{
namespace gui
{
class ICursorControl;
}
namespace scene
{
//! Special scene node animator for FPS cameras
/** This scene node animator can be attached to a camera to make it act like a first
person shooter
*/
class CSceneNodeAnimatorCameraMaya : public ISceneNodeAnimatorCameraMaya
{
public:
//! Constructor
CSceneNodeAnimatorCameraMaya(gui::ICursorControl* cursor, f32 rotateSpeed = -1500.0f,
f32 zoomSpeed = 200.0f, f32 translationSpeed = 1500.0f);
//! Destructor
virtual ~CSceneNodeAnimatorCameraMaya();
//! Animates the scene node, currently only works on cameras
virtual void animateNode(ISceneNode* node, u32 timeMs);
//! Event receiver
virtual bool OnEvent(const SEvent& event);
//! Returns the speed of movement in units per millisecond
virtual f32 getMoveSpeed() const;
//! Sets the speed of movement in units per millisecond
virtual void setMoveSpeed(f32 moveSpeed);
//! Returns the rotation speed
virtual f32 getRotateSpeed() const;
//! Set the rotation speed
virtual void setRotateSpeed(f32 rotateSpeed);
//! Returns the zoom speed
virtual f32 getZoomSpeed() const;
//! Set the zoom speed
virtual void setZoomSpeed(f32 zoomSpeed);
//! This animator will receive events when attached to the active camera
virtual bool isEventReceiverEnabled() const
{
return true;
}
//! Returns type of the scene node
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
{
return ESNAT_CAMERA_MAYA;
}
private:
void allKeysUp();
void animate();
bool isMouseKeyDown(s32 key);
void updateAnimationState();
bool MouseKeys[3];
gui::ICursorControl *CursorControl;
core::vector3df Pos;
bool Zooming, Rotating, Moving, Translating;
f32 ZoomSpeed;
f32 RotateSpeed;
f32 TranslateSpeed;
f32 RotateStartX, RotateStartY;
f32 ZoomStartX, ZoomStartY;
f32 TranslateStartX, TranslateStartY;
f32 CurrentZoom;
f32 RotX, RotY;
core::vector3df Target, OldTarget;
core::position2d<f32> MousePos;
};
} // end namespace scene
} // end namespace irr
#endif
This diff is collapsed.
......@@ -496,6 +496,12 @@
<File
RelativePath=".\..\..\include\ISceneNodeAnimator.h">
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCameraFPS.h">
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCameraMaya.h">
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCollisionResponse.h">
</File>
......@@ -1423,18 +1429,6 @@
<File
RelativePath=".\CBoneSceneNode.h">
</File>
<File
RelativePath=".\CCameraFPSSceneNode.cpp">
</File>
<File
RelativePath=".\CCameraFPSSceneNode.h">
</File>
<File
RelativePath=".\CCameraMayaSceneNode.cpp">
</File>
<File
RelativePath=".\CCameraMayaSceneNode.h">
</File>
<File
RelativePath=".\CCameraSceneNode.cpp">
</File>
......@@ -1627,6 +1621,18 @@
</Filter>
<Filter
Name="animators">
<File
RelativePath="CSceneNodeAnimatorCameraFPS.cpp">
</File>
<File
RelativePath="CSceneNodeAnimatorCameraFPS.h">
</File>
<File
RelativePath="CSceneNodeAnimatorCameraMaya.cpp">
</File>
<File
RelativePath="CSceneNodeAnimatorCameraMaya.h">
</File>
<File
RelativePath="CSceneNodeAnimatorCollisionResponse.cpp">
</File>
......
......@@ -677,19 +677,23 @@
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCollisionResponse.h"
RelativePath="..\..\include\ISceneNodeAnimatorCameraFPS.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorFactory.h"
RelativePath="..\..\include\ISceneNodeAnimatorCameraMaya.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeFactory.h"
RelativePath=".\..\..\include\ISceneNodeAnimatorCollisionResponse.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorFactory.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeMeshLoader.h"
RelativePath=".\..\..\include\ISceneNodeFactory.h"
>
</File>
<File
......@@ -709,11 +713,11 @@
>
</File>
<File
RelativePath=".\..\..\include\IVolumeLightSceneNode.h"
RelativePath=".\..\..\include\ITriangleSelector.h"
>
</File>
<File
RelativePath=".\..\..\include\ITriangleSelector.h"
RelativePath=".\..\..\include\IVolumeLightSceneNode.h"
>
</File>
<File
......@@ -1912,22 +1916,6 @@
RelativePath=".\CBoneSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraFPSSceneNode.cpp"
>
</File>
<File
RelativePath=".\CCameraFPSSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraMayaSceneNode.cpp"
>
</File>
<File
RelativePath=".\CCameraMayaSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraSceneNode.cpp"
>
......@@ -2184,6 +2172,22 @@
<Filter
Name="animators"
>
<File
RelativePath=".\CSceneNodeAnimatorCameraFPS.cpp"
>
</File>
<File
RelativePath=".\CSceneNodeAnimatorCameraFPS.h"
>
</File>
<File
RelativePath=".\CSceneNodeAnimatorCameraMaya.cpp"
>
</File>
<File
RelativePath=".\CSceneNodeAnimatorCameraMaya.h"
>
</File>
<File
RelativePath="CSceneNodeAnimatorCollisionResponse.cpp"
>
......
......@@ -159,6 +159,8 @@
<Unit filename="../../include/ISceneManager.h" />
<Unit filename="../../include/ISceneNode.h" />
<Unit filename="../../include/ISceneNodeAnimator.h" />
<Unit filename="../../include/ISceneNodeAnimatorCameraFPS.h" />
<Unit filename="../../include/ISceneNodeAnimatorCameraMaya.h" />
<Unit filename="../../include/ISceneNodeAnimatorCollisionResponse.h" />
<Unit filename="../../include/ISceneNodeAnimatorFactory.h" />
<Unit filename="../../include/ISceneNodeFactory.h" />
......@@ -246,10 +248,6 @@
<Unit filename="CBurningShader_Raster_Reference.cpp" />
<Unit filename="CCSMLoader.cpp" />
<Unit filename="CCSMLoader.h" />
<Unit filename="CCameraFPSSceneNode.cpp" />
<Unit filename="CCameraFPSSceneNode.h" />
<Unit filename="CCameraMayaSceneNode.cpp" />
<Unit filename="CCameraMayaSceneNode.h" />
<Unit filename="CCameraSceneNode.cpp" />
<Unit filename="CCameraSceneNode.h" />
<Unit filename="CColladaFileLoader.cpp" />
......@@ -499,6 +497,10 @@
<Unit filename="CSceneCollisionManager.h" />
<Unit filename="CSceneManager.cpp" />
<Unit filename="CSceneManager.h" />
<Unit filename="CSceneNodeAnimatorCameraFPS.cpp" />
<Unit filename="CSceneNodeAnimatorCameraFPS.h" />
<Unit filename="CSceneNodeAnimatorCameraMaya.cpp" />
<Unit filename="CSceneNodeAnimatorCameraMaya.h" />
<Unit filename="CSceneNodeAnimatorCollisionResponse.cpp" />
<Unit filename="CSceneNodeAnimatorCollisionResponse.h" />
<Unit filename="CSceneNodeAnimatorDelete.cpp" />
......
This diff is collapsed.
......@@ -676,6 +676,14 @@
RelativePath=".\..\..\include\ISceneNodeAnimator.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCameraFPS.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCameraMaya.h"
>
</File>
<File
RelativePath=".\..\..\include\ISceneNodeAnimatorCollisionResponse.h"
>
......@@ -1912,22 +1920,6 @@
RelativePath=".\CBoneSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraFPSSceneNode.cpp"
>
</File>
<File
RelativePath=".\CCameraFPSSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraMayaSceneNode.cpp"
>
</File>
<File
RelativePath=".\CCameraMayaSceneNode.h"
>
</File>
<File
RelativePath=".\CCameraSceneNode.cpp"
>
......@@ -2184,6 +2176,22 @@
<Filter
Name="animators"
>
<File
RelativePath="CSceneNodeAnimatorCameraFPS.cpp"
>
</File>
<File
RelativePath="CSceneNodeAnimatorCameraFPS.h"
>
</File>
<File
RelativePath="CSceneNodeAnimatorCameraMaya.cpp"
>
</File>
<File
RelativePath="CSceneNodeAnimatorCameraMaya.h"
>
</File>
<File
RelativePath="CSceneNodeAnimatorCollisionResponse.cpp"
>
......
......@@ -25,9 +25,9 @@ IRRMESHOBJ = $(IRRMESHLOADER) $(IRRMESHWRITER) \
CSkinnedMesh.o CBoneSceneNode.o CMeshSceneNode.o \
CAnimatedMeshSceneNode.o CAnimatedMeshMD2.o CAnimatedMeshMD3.o \
CQ3LevelMesh.o CQuake3ShaderSceneNode.o
IRROBJ = CBillboardSceneNode.o CCameraFPSSceneNode.o CCameraMayaSceneNode.o CCameraSceneNode.o CDummyTransformationSceneNode.o CEmptySceneNode.o CGeometryCreator.o CLightSceneNode.o CMeshManipulator.o CMetaTriangleSelector.o COctTreeSceneNode.o COctTreeTriangleSelector.o CSceneCollisionManager.o CSceneManager.o CShadowVolumeSceneNode.o CSkyBoxSceneNode.o CSkyDomeSceneNode.o CTerrainSceneNode.o CTerrainTriangleSelector.o CVolumeLightSceneNode.o CCubeSceneNode.o CSphereSceneNode.o CTextSceneNode.o CTriangleBBSelector.o CTriangleSelector.o CWaterSurfaceSceneNode.o CMeshCache.o CDefaultSceneNodeAnimatorFactory.o CDefaultSceneNodeFactory.o
IRROBJ = CBillboardSceneNode.o CCameraSceneNode.o CDummyTransformationSceneNode.o CEmptySceneNode.o CGeometryCreator.o CLightSceneNode.o CMeshManipulator.o CMetaTriangleSelector.o COctTreeSceneNode.o COctTreeTriangleSelector.o CSceneCollisionManager.o CSceneManager.o CShadowVolumeSceneNode.o CSkyBoxSceneNode.o CSkyDomeSceneNode.o CTerrainSceneNode.o CTerrainTriangleSelector.o CVolumeLightSceneNode.o CCubeSceneNode.o CSphereSceneNode.o CTextSceneNode.o CTriangleBBSelector.o CTriangleSelector.o CWaterSurfaceSceneNode.o CMeshCache.o CDefaultSceneNodeAnimatorFactory.o CDefaultSceneNodeFactory.o
IRRPARTICLEOBJ = CParticleAnimatedMeshSceneNodeEmitter.o CParticleBoxEmitter.o CParticleCylinderEmitter.o CParticleMeshEmitter.o CParticlePointEmitter.o CParticleRingEmitter.o CParticleSphereEmitter.o CParticleAttractionAffector.o CParticleFadeOutAffector.o CParticleGravityAffector.o CParticleRotationAffector.o CParticleSystemSceneNode.o
IRRANIMOBJ = CSceneNodeAnimatorCollisionResponse.o CSceneNodeAnimatorDelete.o CSceneNodeAnimatorFlyCircle.o CSceneNodeAnimatorFlyStraight.o CSceneNodeAnimatorFollowSpline.o CSceneNodeAnimatorRotation.o CSceneNodeAnimatorTexture.o
IRRANIMOBJ = CSceneNodeAnimatorFPS.o CSceneNodeAnimatorMaya.o CSceneNodeAnimatorCollisionResponse.o CSceneNodeAnimatorDelete.o CSceneNodeAnimatorFlyCircle.o CSceneNodeAnimatorFlyStraight.o CSceneNodeAnimatorFollowSpline.o CSceneNodeAnimatorRotation.o CSceneNodeAnimatorTexture.o
IRRDRVROBJ = CNullDriver.o COpenGLDriver.o COpenGLNormalMapRenderer.o COpenGLParallaxMapRenderer.o COpenGLShaderMaterialRenderer.o COpenGLTexture.o COpenGLSLMaterialRenderer.o COpenGLExtensionHandler.o CD3D8Driver.o CD3D8NormalMapRenderer.o CD3D8ParallaxMapRenderer.o CD3D8ShaderMaterialRenderer.o CD3D8Texture.o CD3D9Driver.o CD3D9HLSLMaterialRenderer.o CD3D9NormalMapRenderer.o CD3D9ParallaxMapRenderer.o CD3D9ShaderMaterialRenderer.o CD3D9Texture.o
IRRIMAGEOBJ = CColorConverter.o CImage.o CImageLoaderBMP.o CImageLoaderJPG.o CImageLoaderPCX.o CImageLoaderPNG.o CImageLoaderPSD.o CImageLoaderTGA.o CImageLoaderPPM.o CImageLoaderWAL.o \
CImageWriterBMP.o CImageWriterJPG.o CImageWriterPCX.o CImageWriterPNG.o CImageWriterPPM.o CImageWriterPSD.o CImageWriterTGA.o
......
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