Use Example:
Code: Select all
scene::ISceneNodeAnimator* anim = smgr->createRotationFixedAnimator(core::vector3df(0, 0, 0), core::vector3df(0, 180, 0), 1000, false);
node->addAnimator(anim);This animator is useful for sooth animation of MOB orientation when updating over a network. This way you can send a message that the player turned 90 degrees in 1.5 seconds and it will be animated on the other player’s screens instead of just snapping to the new orientation.
My question is where should I send it to get my patch included into the SVN?
Patch file contents:
Code: Select all
Index: include/ESceneNodeAnimatorTypes.h
===================================================================
--- include/ESceneNodeAnimatorTypes.h (revision 272)
+++ include/ESceneNodeAnimatorTypes.h (working copy)
@@ -17,6 +17,9 @@
//! Fly straight scene node animator
ESNAT_FLY_STRAIGHT,
+
+ //! Rotate Fixed scene node animator
+ ESNAT_FIXED_ROTATE,
//! Follow spline scene node animator
ESNAT_FOLLOW_SPLINE,
Index: include/ISceneManager.h
===================================================================
--- include/ISceneManager.h (revision 272)
+++ include/ISceneManager.h (working copy)
@@ -817,6 +817,20 @@
virtual ISceneNodeAnimator* createFlyStraightAnimator(const core::vector3df& startPoint,
const core::vector3df& endPoint, u32 timeForWay, bool loop=false) = 0;
+ //! Creates fixed rotation animator, which lets the attached scene node rotation between two fixed rotation values.
+ /** \param startPoint: The rotation amount to start from.
+ \param endPoint: The rotation amount to stop at.
+ \param timeForWay: Time in milli seconds how long the node should need to
+ move from the start point to the end point.
+ \param loop: If set to false, the node stops when the end point is reached.
+ If loop is true, the node begins again at the start.
+ \return Returns the animator. Attach it to a scene node with ISceneNode::addAnimator()
+ and the animator will animate it.
+ If you no longer need the animator, you should call ISceneNodeAnimator::drop().
+ See IUnknown::drop() for more information. */
+ virtual ISceneNodeAnimator* createRotationFixedAnimator(const core::vector3df& startPoint,
+ const core::vector3df& endPoint, u32 timeForWay, bool loop=false) = 0;
+
//! Creates a texture animator, which switches the textures of the target scene node based on a list of textures.
/** \param textures: List of textures to use.
\param timePerFrame: Time in milliseconds, how long any texture in the list
Index: source/Irrlicht/CDefaultSceneNodeAnimatorFactory.cpp
===================================================================
--- source/Irrlicht/CDefaultSceneNodeAnimatorFactory.cpp (revision 272)
+++ source/Irrlicht/CDefaultSceneNodeAnimatorFactory.cpp (working copy)
@@ -51,6 +51,9 @@
case ESNAT_FLY_STRAIGHT:
anim = Manager->createFlyStraightAnimator(core::vector3df(0,0,0), core::vector3df(100,100,100), 10000, true );
break;
+ case ESNAT_FIXED_ROTATE:
+ anim = Manager->createRotationFixedAnimator(core::vector3df(0,0,0), core::vector3df(100,100,100), 10000, true );
+ break;
case ESNAT_FOLLOW_SPLINE:
{
core::array<core::vector3df> points;
Index: source/Irrlicht/CSceneManager.cpp
===================================================================
--- source/Irrlicht/CSceneManager.cpp (revision 272)
+++ source/Irrlicht/CSceneManager.cpp (working copy)
@@ -60,6 +60,7 @@
#include "CSceneNodeAnimatorRotation.h"
#include "CSceneNodeAnimatorFlyCircle.h"
#include "CSceneNodeAnimatorFlyStraight.h"
+#include "CSceneNodeAnimatorRotationFixed.h"
#include "CSceneNodeAnimatorTexture.h"
#include "CSceneNodeAnimatorCollisionResponse.h"
#include "CSceneNodeAnimatorDelete.h"
@@ -934,8 +935,18 @@
return anim;
}
+//! Creates a fixed rotation animator, which lets the attached scene node
+//! rotate between 2 fixed absolute rotation settings.
+ISceneNodeAnimator* CSceneManager::createRotationFixedAnimator(const core::vector3df& startPoint,
+ const core::vector3df& endPoint, u32 timeForWay, bool loop)
+{
+ ISceneNodeAnimator* anim = new CSceneNodeAnimatorRotationFixed(startPoint,
+ endPoint, timeForWay, loop, os::Timer::getTime());
+ return anim;
+}
+
//! Creates a texture animator, which switches the textures of the target scene
//! node based on a list of textures.
ISceneNodeAnimator* CSceneManager::createTextureAnimator(const core::array<video::ITexture*>& textures,
Index: source/Irrlicht/CSceneManager.h
===================================================================
--- source/Irrlicht/CSceneManager.h (revision 272)
+++ source/Irrlicht/CSceneManager.h (working copy)
@@ -242,6 +242,11 @@
//! fly or move along a line between two points.
virtual ISceneNodeAnimator* createFlyStraightAnimator(const core::vector3df& startPoint,
const core::vector3df& endPoint, u32 timeForWay, bool loop=false);
+
+ //Creates a fixed rotation animator, which lets the attached scene node
+ // rotate from a starting fixed rotation to an ending fixed rotation
+ virtual ISceneNodeAnimator* createRotationFixedAnimator(const core::vector3df& startPoint,
+ const core::vector3df& endPoint, u32 timeForWay, bool loop=false);
//! Creates a texture animator, which switches the textures of the target scene
//! node based on a list of textures.
Index: source/Irrlicht/CSceneNodeAnimatorRotationFixed.cpp
===================================================================
--- source/Irrlicht/CSceneNodeAnimatorRotationFixed.cpp (revision 0)
+++ source/Irrlicht/CSceneNodeAnimatorRotationFixed.cpp (revision 0)
@@ -0,0 +1,82 @@
+// fixed rotation animator by Kenneth Peterson aka CodeDog
+//This animator allows you to start a node at a certain rotation and then animate it
+// to another amount of rotation. Good for smooth rotation sync when networking
+#include "CSceneNodeAnimatorRotationFixed.h"
+namespace irr
+{
+namespace scene
+{
+
+//! constructor
+CSceneNodeAnimatorRotationFixed::CSceneNodeAnimatorRotationFixed(const core::vector3df& startRotation,
+ const core::vector3df& endRotation, u32 timeForWay,
+ bool loop, u32 now)
+: Start(startRotation), End(endRotation), StartTime(now), TimeForWay(timeForWay), Loop(loop)
+{
+ #ifdef _DEBUG
+ setDebugName("CSceneNodeAnimatorRotationFixed");
+ #endif
+
+ recalculateImidiateValues();
+}
+
+
+void CSceneNodeAnimatorRotationFixed::recalculateImidiateValues()
+{
+ Vector = End - Start;
+ WayLength = (f32)Vector.getLength();
+ Vector.normalize();
+
+ TimeFactor = WayLength / TimeForWay;
+}
+
+
+
+//! destructor
+CSceneNodeAnimatorRotationFixed::~CSceneNodeAnimatorRotationFixed()
+{
+}
+
+
+
+//! animates a scene node
+void CSceneNodeAnimatorRotationFixed::animateNode(ISceneNode* node, u32 timeMs)
+{
+ if (!node)
+ return;
+
+ u32 t = (timeMs-StartTime);
+
+ core::vector3df rot = Start;
+
+ if (!Loop && t >= TimeForWay)
+ rot = End;
+ else
+ rot += Vector * (f32)fmod((f32)t, (f32)TimeForWay) * TimeFactor;
+
+ node->setRotation(rot);
+}
+
+
+//! Writes attributes of the scene node animator.
+void CSceneNodeAnimatorRotationFixed::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options)
+{
+ out->addVector3d("Start", Start);
+ out->addVector3d("End", End);
+ out->addInt("TimeForWay", TimeForWay);
+ out->addBool("Loop", Loop);
+}
+
+
+//! Reads attributes of the scene node animator.
+void CSceneNodeAnimatorRotationFixed::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
+{
+ Start = in->getAttributeAsVector3d("Start");
+ End = in->getAttributeAsVector3d("End");
+ TimeForWay = in->getAttributeAsInt("TimeForWay");
+ Loop = in->getAttributeAsBool("Loop");
+
+ recalculateImidiateValues();
+}
+}//end namespace scene
+}//end namespace irr
Index: source/Irrlicht/CSceneNodeAnimatorRotationFixed.h
===================================================================
--- source/Irrlicht/CSceneNodeAnimatorRotationFixed.h (revision 0)
+++ source/Irrlicht/CSceneNodeAnimatorRotationFixed.h (revision 0)
@@ -0,0 +1,46 @@
+// fixed rotation animator by Kenneth Peterson aka CodeDog
+// This animator allows you to start a node at a certain rotation and then animate it
+// to another amount of rotation. Good for smooth rotation sync when networking
+// The fly straight animator was used as a referance when constructing this animator
+#pragma once
+#include "ISceneNode.h"
+namespace irr
+{
+namespace scene
+{
+class CSceneNodeAnimatorRotationFixed :
+ public ISceneNodeAnimator
+{
+public:
+ CSceneNodeAnimatorRotationFixed(const core::vector3df& startRotation,
+ const core::vector3df& endRotation, u32 timeForWay,
+ bool loop, u32 now);
+public:
+ ~CSceneNodeAnimatorRotationFixed(void);
+//! animates a scene node
+ virtual void animateNode(ISceneNode* node, u32 timeMs);
+
+ //! Writes attributes of the scene node animator.
+ virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0);
+
+ //! Reads attributes of the scene node animator.
+ virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
+
+ //! Returns type of the scene node animator
+ virtual ESCENE_NODE_ANIMATOR_TYPE getType() { return ESNAT_FIXED_ROTATE; }
+
+ private:
+
+ void recalculateImidiateValues();
+
+ core::vector3df Start;
+ core::vector3df End;
+ core::vector3df Vector;
+ f32 WayLength;
+ f32 TimeFactor;
+ u32 StartTime;
+ u32 TimeForWay;
+ bool Loop;
+};
+}
+}