added modiefied maya camera animator
MODIFY
include/ISceneManager.h
include/ISceneManager.h
@@ -246,6 +246,11 @@ namespace scene
float translationSpeed=1500.f, int32_t id=-1, float distance=70.f,
bool makeActive=true) =0;
+ virtual ICameraSceneNode* addCameraSceneNodeModifiedMaya(IDummyTransformationSceneNode* parent = 0,
+ float rotateSpeed = -1500.f, float zoomSpeed = 200.f,
+ float translationSpeed = 1500.f, int32_t id = -1, float distance = 70.f,
+ bool makeActive = true) = 0;
+
//! Adds a camera scene node with an animator which provides mouse and keyboard control appropriate for first person shooters (FPS).
/** This FPS camera is intended to provide a demonstration of a
camera that behaves like a typical First Person Shooter. It is

MODIFY
source/Irrlicht/CSceneManager.cpp
source/Irrlicht/CSceneManager.cpp
#include "CSceneNodeAnimatorFollowSpline.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
+#include "CSceneNodeAnimatorCameraModifiedMaya.h"
#include "irr/asset/CGeometryCreator.h"
@@ -363,6 +364,24 @@ ICameraSceneNode* CSceneManager::addCameraSceneNodeMaya(IDummyTransformationScen
return node;
}
+ICameraSceneNode* CSceneManager::addCameraSceneNodeModifiedMaya(IDummyTransformationSceneNode* parent,
+ float rotateSpeed, float zoomSpeed, float translationSpeed, int32_t id, float distance,
+ bool makeActive)
+{
+ ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
+ core::vector3df(0, 0, 100), id, makeActive);
+ if (node)
+ {
+ ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraModifiedMaya(CursorControl,
+ rotateSpeed, zoomSpeed, translationSpeed, distance);
+
+ node->addAnimator(anm);
+ anm->drop();
+ }
+
+ return node;
+}
+
//! Adds a camera scene node which is able to be controlled with the mouse and keys
//! like in most first person shooters (FPS):

MODIFY
source/Irrlicht/CSceneManager.h
source/Irrlicht/CSceneManager.h
@@ -113,6 +113,11 @@ namespace scene
float translationSpeed=1500.f, int32_t id=-1, float distance=70.f,
bool makeActive=true);
+ virtual ICameraSceneNode* addCameraSceneNodeModifiedMaya(IDummyTransformationSceneNode* parent = 0,
+ float rotateSpeed = -1500.f, float zoomSpeed = 200.f,
+ float translationSpeed = 1500.f, int32_t id = -1, float distance = 70.f,
+ bool makeActive = true);
+
//! Adds a camera scene node which is able to be controled with the mouse and keys
//! like in most first person shooters (FPS):
virtual ICameraSceneNode* addCameraSceneNodeFPS(IDummyTransformationSceneNode* parent = 0,

ADD
source/Irrlicht/CSceneNodeAnimatorCameraModifiedMaya.cpp
+// Copyright (C) 2002-2012 Nikolaus Gebhardt
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in irrlicht.h
+
+#include "CSceneNodeAnimatorCameraModifiedMaya.h"
+#include "ICursorControl.h"
+#include "ICameraSceneNode.h"
+#include "SViewFrustum.h"
+#include "ISceneManager.h"
+
+#include <iostream>
+
+namespace irr
+{
+ namespace scene
+ {
+
+ //! constructor
+ CSceneNodeAnimatorCameraModifiedMaya::CSceneNodeAnimatorCameraModifiedMaya(gui::ICursorControl* cursor,
+ float rotateSpeed, float zoomSpeed, float translateSpeed, float distance)
+ : CursorControl(cursor), OldCamera(0), MousePos(0.5f, 0.5f),
+ ZoomSpeed(zoomSpeed), RotateSpeed(rotateSpeed), TranslateSpeed(translateSpeed),
+ CurrentZoom(distance), RotX(0.0f), RotY(0.0f),
+ ZoomDelta(0.0f), ZoomWithRMB(false), StepZooming(false),
+ Zooming(false), Rotating(false), Moving(false), Translating(false)
+ {
+#ifdef _IRR_DEBUG
+ setDebugName("CSceneNodeAnimatorCameraModifiedMaya");
+#endif
+
+ if (CursorControl)
+ {
+ CursorControl->grab();
+ MousePos = CursorControl->getRelativePosition();
+ }
+
+ allKeysUp();
+ }
+
+
+ //! destructor
+ CSceneNodeAnimatorCameraModifiedMaya::~CSceneNodeAnimatorCameraModifiedMaya()
+ {
+ 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::addMeshViewerCameraSceneNode, may want to get this input
+ //! for changing their position, look at target or whatever.
+ bool CSceneNodeAnimatorCameraModifiedMaya::OnEvent(const SEvent& event)
+ {
+ if (event.EventType != EET_MOUSE_INPUT_EVENT)
+ return false;
+
+ switch (event.MouseInput.Event)
+ {
+ case EMIE_LMOUSE_PRESSED_DOWN:
+ MouseKeys[0] = true;
+ break;
+ case EMIE_RMOUSE_PRESSED_DOWN:
+ MouseKeys[2] = true;
+ break;
+ case EMIE_MMOUSE_PRESSED_DOWN:
+ MouseKeys[1] = true;
+ break;
+ case EMIE_LMOUSE_LEFT_UP:
+ MouseKeys[0] = false;
+ break;
+ case EMIE_RMOUSE_LEFT_UP:
+ MouseKeys[2] = false;
+ break;
+ case EMIE_MMOUSE_LEFT_UP:
+ MouseKeys[1] = false;
+ break;
+ case EMIE_MOUSE_MOVED:
+ MousePos = CursorControl->getRelativePosition();
+ break;
+ case EMIE_MOUSE_WHEEL:
+ {
+ if (!Zooming)
+ {
+ StepZooming = true;
+ //this should not be hardcoded i believe (distinct scroll speed for step zooming?)
+ CurrentZoom += event.MouseInput.Wheel * (-10.0f);
+ }
+ }
+
+ case EMIE_LMOUSE_DOUBLE_CLICK:
+ case EMIE_RMOUSE_DOUBLE_CLICK:
+ case EMIE_MMOUSE_DOUBLE_CLICK:
+ case EMIE_LMOUSE_TRIPLE_CLICK:
+ case EMIE_RMOUSE_TRIPLE_CLICK:
+ case EMIE_MMOUSE_TRIPLE_CLICK:
+ case EMIE_COUNT:
+ return false;
+ }
+ return true;
+ }
+
+
+ //! OnAnimate() is called just before rendering the whole scene.
+ void CSceneNodeAnimatorCameraModifiedMaya::animateNode(IDummyTransformationSceneNode* node, uint32_t timeMs)
+ {
+
+ if (!node || node->getType() != ESNT_CAMERA)
+ return;
+
+ ICameraSceneNode * camera = static_cast<ICameraSceneNode*>(node);
+
+ // If the camera isn't the active camera, and receiving input, then don't process it.
+ if (!camera->isInputReceiverEnabled())
+ return;
+
+ scene::ISceneManager * smgr = camera->getSceneManager();
+ if (smgr && smgr->getActiveCamera() != camera)
+ return;
+
+ if (OldCamera != camera)
+ {
+ LastCameraTarget = OldTarget = camera->getTarget();
+ OldCamera = camera;
+ }
+ else
+ {
+ OldTarget += camera->getTarget() - LastCameraTarget;
+ }
+
+ float nRotX = RotX;
+ float nRotY = RotY;
+ float nZoom = CurrentZoom;
+
+ // Check for zooming with RMB
+ if (ZoomWithRMB && isMouseKeyDown(2))
+ {
+ if (!Zooming)
+ {
+ ZoomStart = MousePos;
+ Zooming = true;
+ }
+ else
+ {
+ const float targetMinDistance = 0.1f;
+ nZoom += (ZoomStart.X - MousePos.X) * ZoomSpeed;
+
+ if (nZoom < targetMinDistance)
+ nZoom = targetMinDistance;
+ }
+ }
+ else if (Zooming)
+ {
+ const float old = CurrentZoom;
+ CurrentZoom = CurrentZoom + (ZoomStart.X - MousePos.X) * ZoomSpeed;
+ nZoom = CurrentZoom;
+
+ if (nZoom < 0)
+ nZoom = CurrentZoom = old;
+ Zooming = false;
+ }
+
+ // Translation ---------------------------------
+
+ core::vector3df translate(OldTarget);
+
+ core::vector3df_SIMD target, upVector;
+ upVector.getAsVector3df() = camera->getUpVector();
+ target.getAsVector3df() = camera->getTarget();
+
+ core::vector3df_SIMD pos, tvectX;
+ pos.getAsVector3df() = camera->getPosition();
+ tvectX = pos - target;
+ tvectX = normalize(cross(tvectX, upVector));
+
+ const SViewFrustum* const va = camera->getViewFrustum();
+ core::vector3df_SIMD tvectY = (va->getFarLeftDown() - va->getFarRightDown());
+ tvectY = normalize(cross(tvectY, upVector.Y > 0 ? pos - target : target - pos));
+
+ if ((isMouseKeyDown(1) || isMouseKeyDown(2)) && !(Zooming || StepZooming))
+ {
+ if (!Translating)
+ {
+ TranslateStart = MousePos;
+ Translating = true;
+ }
+ else
+ {
+ translate += tvectX.getAsVector3df() * (TranslateStart.X - MousePos.X) * TranslateSpeed +
+ tvectY.getAsVector3df() * (TranslateStart.Y - MousePos.Y) * TranslateSpeed;
+ }
+ }
+ else if (Translating)
+ {
+ translate += tvectX.getAsVector3df() * (TranslateStart.X - MousePos.X) * TranslateSpeed +
+ tvectY.getAsVector3df() * (TranslateStart.Y - MousePos.Y) * TranslateSpeed;
+ OldTarget = translate;
+ Translating = false;
+ }
+
+ // Rotation ------------------------------------
+ if (isMouseKeyDown(0) && !(Zooming || StepZooming))
+ {
+ if (!Rotating)
+ {
+ RotateStart = MousePos;
+ Rotating = true;
+ nRotX = RotX;
+ nRotY = RotY;
+ }
+ else
+ {
+ nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
+ nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ }
+ }
+ else if (Rotating)
+ {
+ RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
+ RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
+ nRotX = RotX;
+ nRotY = RotY;
+ Rotating = false;
+ }
+
+ // Set pos ------------------------------------
+
+ pos.getAsVector3df() = translate;
+ pos.X += nZoom;
+
+ pos.getAsVector3df().rotateXYBy(nRotY, translate);
+ pos.getAsVector3df().rotateXZBy(-nRotX, translate);
+
+ camera->setPosition(pos.getAsVector3df());
+ camera->setTarget(translate);
+
+ ZoomDelta = 0.0f;
+ StepZooming = false;
+
+
+ // Rotation Error ----------------------------
+ pos.set(0, 1, 0);
+ pos.getAsVector3df().rotateXYBy(-nRotY);
+ pos.getAsVector3df().rotateXZBy(-nRotX + 180.f);
+ camera->setUpVector(pos.getAsVector3df());
+ LastCameraTarget = camera->getTarget();
+ }
+
+
+ bool CSceneNodeAnimatorCameraModifiedMaya::isMouseKeyDown(int32_t key) const
+ {
+ return MouseKeys[key];
+ }
+
+
+ void CSceneNodeAnimatorCameraModifiedMaya::allKeysUp()
+ {
+ for (int32_t i = 0; i < 3; ++i)
+ MouseKeys[i] = false;
+ }
+
+
+ //! Sets the rotation speed
+ void CSceneNodeAnimatorCameraModifiedMaya::setRotateSpeed(float speed)
+ {
+ RotateSpeed = speed;
+ }
+
+
+ //! Sets the movement speed
+ void CSceneNodeAnimatorCameraModifiedMaya::setMoveSpeed(float speed)
+ {
+ TranslateSpeed = speed;
+ }
+
+
+ //! Sets the zoom speed
+ void CSceneNodeAnimatorCameraModifiedMaya::setZoomSpeed(float speed)
+ {
+ ZoomSpeed = speed;
+ }
+
+
+ //! Set the distance
+ void CSceneNodeAnimatorCameraModifiedMaya::setDistance(float distance)
+ {
+ CurrentZoom = distance;
+ }
+
+
+ //! Gets the rotation speed
+ float CSceneNodeAnimatorCameraModifiedMaya::getRotateSpeed() const
+ {
+ return RotateSpeed;
+ }
+
+
+ // Gets the movement speed
+ float CSceneNodeAnimatorCameraModifiedMaya::getMoveSpeed() const
+ {
+ return TranslateSpeed;
+ }
+
+
+ //! Gets the zoom speed
+ float CSceneNodeAnimatorCameraModifiedMaya::getZoomSpeed() const
+ {
+ return ZoomSpeed;
+ }
+
+
+ //! Returns the current distance, i.e. orbit radius
+ float CSceneNodeAnimatorCameraModifiedMaya::getDistance() const
+ {
+ return CurrentZoom;
+ }
+
+
+ ISceneNodeAnimator* CSceneNodeAnimatorCameraModifiedMaya::createClone(IDummyTransformationSceneNode * node, ISceneManager * newManager)
+ {
+ CSceneNodeAnimatorCameraModifiedMaya* newAnimator =
+ new CSceneNodeAnimatorCameraModifiedMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed);
+ return newAnimator;
+ }
+
+ } // end namespace
+} // end namespace
+

ADD
source/Irrlicht/CSceneNodeAnimatorCameraModifiedMaya.h
+// Copyright (C) 2002-2012 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_MODIFIED_MAYA_H_INCLUDED__
+#define __C_SCENE_NODE_ANIMATOR_CAMERA_MODIFIED_MAYA_H_INCLUDED__
+
+#include "ISceneNodeAnimatorCameraMaya.h"
+#include "ICameraSceneNode.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 3d modelling tool camera
+ */
+ class CSceneNodeAnimatorCameraModifiedMaya : public ISceneNodeAnimatorCameraMaya
+ {
+ protected:
+ //! Destructor
+ virtual ~CSceneNodeAnimatorCameraModifiedMaya();
+
+ public:
+ //! Constructor
+ CSceneNodeAnimatorCameraModifiedMaya(gui::ICursorControl* cursor, float rotateSpeed = -1500.f,
+ float zoomSpeed = 200.f, float translationSpeed = 1500.f, float distance = 70.f);
+
+ //! Animates the scene node, currently only works on cameras
+ virtual void animateNode(IDummyTransformationSceneNode* node, uint32_t timeMs);
+
+ //! Event receiver
+ virtual bool OnEvent(const SEvent& event);
+
+ //! Returns the speed of movement in units per millisecond
+ virtual float getMoveSpeed() const;
+
+ //! Sets the speed of movement in units per millisecond
+ virtual void setMoveSpeed(float moveSpeed);
+
+ //! Returns the rotation speed
+ virtual float getRotateSpeed() const;
+
+ //! Set the rotation speed
+ virtual void setRotateSpeed(float rotateSpeed);
+
+ //! Returns the zoom speed
+ virtual float getZoomSpeed() const;
+
+ //! Set the zoom speed
+ virtual void setZoomSpeed(float zoomSpeed);
+
+ //! Returns the current distance, i.e. orbit radius
+ virtual float getDistance() const;
+
+ //! Set the distance
+ virtual void setDistance(float distance);
+
+ //! This animator will receive events when attached to the active camera
+ virtual bool isEventReceiverEnabled() const
+ {
+ return true;
+ }
+
+ //! Enable zooming with right mouse button
+ void enableRMBZoom()
+ {
+ ZoomWithRMB = true;
+ }
+
+ //! Enable zooming with right mouse button
+ void disableRMBZoom()
+ {
+ ZoomWithRMB = false;
+ }
+
+ //! Returns type of the scene node
+ virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
+ {
+ return ESNAT_CAMERA_MODIFIED_MAYA;
+ }
+
+ //! Creates a clone of this animator.
+ /** Please note that you will have to drop
+ (IReferenceCounted::drop()) the returned pointer after calling
+ this. */
+ virtual ISceneNodeAnimator* createClone(IDummyTransformationSceneNode* node, ISceneManager* newManager = 0);
+
+ private:
+ void allKeysUp();
+ void animate();
+ bool isMouseKeyDown(int32_t key) const;
+
+ bool MouseKeys[3];
+
+
+ gui::ICursorControl* CursorControl;
+ scene::ICameraSceneNode* OldCamera;
+ core::vector3df OldTarget;
+ core::vector3df LastCameraTarget; // to find out if the camera target was moved outside this animator
+ core::position2df RotateStart;
+ core::position2df ZoomStart;
+ core::position2df TranslateStart;
+ core::position2df MousePos;
+ float ZoomSpeed;
+ float ZoomDelta;
+ float RotateSpeed;
+ float TranslateSpeed;
+ float CurrentZoom;
+ float RotX, RotY;
+ bool StepZooming;
+ bool ZoomWithRMB;
+ bool Zooming;
+ bool Rotating;
+ bool Moving;
+ bool Translating;
+ };
+
+ } // end namespace scene
+} // end namespace irr
+
+#endif
+

added modiefied maya camera animator