Commit 9a1db251 authored by hybrid's avatar hybrid

Added particle affectors with interfaces from IrrSpintz.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@869 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 0f0a06c2
......@@ -17,8 +17,10 @@ namespace scene
enum E_PARTICLE_AFFECTOR_TYPE
{
EPAT_NONE = 0,
EPAT_ATTRACT,
EPAT_FADE_OUT,
EPAT_GRAVITY,
EPAT_ROTATE,
EPAT_COUNT
};
......@@ -26,8 +28,10 @@ enum E_PARTICLE_AFFECTOR_TYPE
const c8* const ParticleAffectorTypeNames[] =
{
"None",
"Attract",
"FadeOut",
"Gravity",
"Rotate",
0
};
......@@ -46,10 +50,10 @@ public:
virtual void affect(u32 now, SParticle* particlearray, u32 count) = 0;
//! Sets whether or not the affector is currently enabled.
virtual void setEnabled(bool enabled) {Enabled = enabled;}
virtual void setEnabled(bool enabled) { Enabled = enabled; }
//! Gets whether or not the affector is currently enabled.
virtual bool getEnabled() const { return Enabled;}
virtual bool getEnabled() const { return Enabled; }
//! Writes attributes of the object.
//! Implement this to expose the attributes of your scene node animator for
......
// 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_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
#define __I_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
namespace irr
{
namespace scene
{
//! A particle affector which attracts or detracts particles.
class IParticleAttractionAffector : public IParticleAffector
{
public:
//! Set the point that particles will attract to
virtual void setPoint( const core::vector3df& point ) = 0;
//! Set whether or not the particles are attracting or detracting
virtual void setAttract( bool attract ) = 0;
//! Set whether or not this will affect particles in the X direction
virtual void setAffectX( bool affect ) = 0;
//! Set whether or not this will affect particles in the Y direction
virtual void setAffectY( bool affect ) = 0;
//! Set whether or not this will affect particles in the Z direction
virtual void setAffectZ( bool affect ) = 0;
//! Get the point that particles are attracted to
virtual const core::vector3df& getPoint() const = 0;
//! Get whether or not the particles are attracting or detracting
virtual bool getAttract() const = 0;
//! Get whether or not the particles X position are affected
virtual bool getAffectX() const = 0;
//! Get whether or not the particles Y position are affected
virtual bool getAffectY() const = 0;
//! Get whether or not the particles Z position are affected
virtual bool getAffectZ() const = 0;
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_ATTRACT; }
};
} // end namespace scene
} // end namespace irr
#endif // __I_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
// 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_PARTICLE_FADE_OUT_AFFECTOR_H_INCLUDED__
#define __I_PARTICLE_FADE_OUT_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
namespace irr
{
namespace scene
{
//! A particle affector which fades out the particles.
class IParticleFadeOutAffector : public IParticleAffector
{
public:
//! Sets the targetColor, i.e. the color the particles will interpolate
//! to over time.
virtual void setTargetColor( const video::SColor& targetColor ) = 0;
//! Sets the amount of time it takes for each particle to fade out.
virtual void setFadeOutTime( f32 fadeOutTime ) = 0;
//! Sets the targetColor, i.e.the color the particles will interpolate
//! to over time.
virtual const video::SColor& getTargetColor() const = 0;
//! Sets the amount of time it takes for each particle to fade out.
virtual f32 getFadeOutTime() const = 0;
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_FADE_OUT; }
};
} // end namespace scene
} // end namespace irr
#endif // __I_PARTICLE_FADE_OUT_AFFECTOR_H_INCLUDED__
// 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_PARTICLE_GRAVITY_AFFECTOR_H_INCLUDED__
#define __I_PARTICLE_GRAVITY_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
namespace irr
{
namespace scene
{
//! A particle affector which applies gravity to particles.
class IParticleGravityAffector : public IParticleAffector
{
public:
//! Set the time in milliseconds when the gravity force is totally
//! lost and the particle does not move any more.
virtual void setTimeForceLost( f32 timeForceLost ) = 0;
//! Set the direction and force of gravity in all 3 dimensions.
virtual void setGravity( const core::vector3df& gravity ) = 0;
//! Get the time in milliseconds when the gravity force is totally
//! lost and the particle does not move any more.
virtual f32 getTimeForceLost() const = 0;
//! Get the direction and force of gravity.
virtual const core::vector3df& getGravity() const = 0;
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_GRAVITY; }
};
} // end namespace scene
} // end namespace irr
#endif // __I_PARTICLE_GRAVITY_AFFECTOR_H_INCLUDED__
// 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_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
#define __I_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
namespace irr
{
namespace scene
{
//! A particle affector which rotates the particle system.
class IParticleRotationAffector : public IParticleAffector
{
public:
//! Set the point that particles will rotate around
virtual void setPivotPoint( const core::vector3df& point ) = 0;
//! Set the speed in degrees per second in all 3 dimensions
virtual void setSpeed( const core::vector3df& speed ) = 0;
//! Get the point that particles are attracted to
virtual const core::vector3df& getPivotPoint() const = 0;
//! Get the speed in degrees per second in all 3 dimensions
virtual const core::vector3df& getSpeed() const = 0;
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_ROTATE; }
};
} // end namespace scene
} // end namespace irr
#endif // __I_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
......@@ -7,7 +7,10 @@
#include "ISceneNode.h"
#include "IParticleEmitter.h"
#include "IParticleAffector.h"
#include "IParticleAttractionAffector.h"
#include "IParticleFadeOutAffector.h"
#include "IParticleGravityAffector.h"
#include "IParticleRotationAffector.h"
#include "dimension2d.h"
namespace irr
......@@ -139,6 +142,23 @@ public:
u32 lifeTimeMin=2000, u32 lifeTimeMax=4000,
s32 maxAngleDegrees=0) = 0;
//! Creates a point attraction affector. This affector modifies the positions of the
//! particles and attracts them to a specified point at a specified speed per second.
//! \param point: Point to attract particles to.
//! \param speed: Speed in units per second, to attract to the specified point.
//! \param attract: Whether the particles attract or detract from this point.
//! \param affectX: Whether or not this will affect the X position of the particle.
//! \param affectY: Whether or not this will affect the Y position of the particle.
//! \param affectZ: Whether or not this will affect the Z position of the particle.
//! \return Returns a pointer to the created particle affector.
//! To add this affector as new affector of this particle system,
//! just call addAffector(). Note that you'll have to drop() the
//! returned pointer, after you don't need it any more, see
//! IUnknown::drop() for more informations.
virtual IParticleAttractionAffector* createAttractionAffector(
const core::vector3df& point, f32 speed = 1.0f, bool attract = true,
bool affectX = true, bool affectY = true, bool affectZ = true) = 0;
//! Creates a fade out particle affector. This affector modifies
//! the color of every particle and and reaches the final color
//! when the particle dies.
......@@ -153,8 +173,8 @@ public:
//! just call addAffector(). Note that you'll have to drop() the
//! returned pointer, after you don't need it any more, see
//! IUnknown::drop() for more informations.
virtual IParticleAffector* createFadeOutParticleAffector(
video::SColor targetColor = video::SColor(0,0,0,0),
virtual IParticleFadeOutAffector* createFadeOutParticleAffector(
const video::SColor& targetColor = video::SColor(0,0,0,0),
u32 timeNeededToFadeOut = 1000) = 0;
//! Creates a gravity affector. This affector modifies the direction
......@@ -171,9 +191,22 @@ public:
//! just call addAffector(). Note that you'll have to drop() the
//! returned pointer, after you don't need it any more, see
//! IUnknown::drop() for more informations.
virtual IParticleAffector* createGravityAffector(
virtual IParticleGravityAffector* createGravityAffector(
const core::vector3df& gravity = core::vector3df(0.0f,-0.03f,0.0f),
u32 timeForceLost = 1000) = 0;
//! Creates a rotation affector. This affector modifies the positions of the
//! particles and attracts them to a specified point at a specified speed per second.
//! \param speed: Rotation in degrees per second
//! \param pivotPoint: Point to rotate the particles around
//! \return Returns a pointer to the created particle affector.
//! To add this affector as new affector of this particle system,
//! just call addAffector(). Note that you'll have to drop() the
//! returned pointer, after you don't need it any more, see
//! IUnknown::drop() for more informations.
virtual IParticleRotationAffector* createRotationAffector(
const core::vector3df& speed = core::vector3df(5.0f,5.0f,5.0f),
const core::vector3df& pivotPoint = core::vector3df(0.0f,0.0f,0.0f) ) = 0;
};
} // end namespace scene
......
......@@ -23,59 +23,70 @@ class map
public:
RBTree(const KeyTypeRB& k, const ValueTypeRB& v)
: mLeftChild(0), mRightChild(0), mParent(0), mKey(k),
mValue(v), mIsRed(true) {}
: LeftChild(0), RightChild(0), Parent(0), Key(k),
Value(v), IsRed(true) {}
virtual ~RBTree(){}
~RBTree() {}
void setLeftChild(RBTree* p) { mLeftChild=p; if (p) p->setParent(this); }
void setRightChild(RBTree* p) { mRightChild=p;if (p) p->setParent(this); }
void setParent(RBTree* p) { mParent=p; }
void setLeftChild(RBTree* p)
{
LeftChild=p;
if (p)
p->setParent(this);
}
void setRightChild(RBTree* p)
{
RightChild=p;
if (p)
p->setParent(this);
}
void setParent(RBTree* p) { Parent=p; }
void setValue(const ValueTypeRB& v) { mValue = v; }
void setValue(const ValueTypeRB& v) { Value = v; }
void setRed() { mIsRed = true; }
void setBlack() { mIsRed = false; }
void setRed() { IsRed = true; }
void setBlack() { IsRed = false; }
RBTree* getLeftChild() const { return mLeftChild; }
RBTree* getRightChild() const { return mRightChild; }
RBTree* getParent() const { return mParent; }
RBTree* getLeftChild() const { return LeftChild; }
RBTree* getRightChild() const { return RightChild; }
RBTree* getParent() const { return Parent; }
ValueTypeRB getValue() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mValue;
return Value;
}
KeyTypeRB getKey() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mKey;
return Key;
}
bool isRoot() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mParent==0;
return Parent==0;
}
bool isLeftChild() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mParent!=0 && mParent->getLeftChild()==this;
return (Parent != 0) && (Parent->getLeftChild()==this);
}
bool isRightChild() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mParent!=0 && mParent->getRightChild()==this;
return (Parent!=0) && (Parent->getRightChild()==this);
}
bool isLeaf() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mLeftChild==0 && mRightChild==0;
return (LeftChild==0) && (RightChild==0);
}
unsigned int getLevel() const
......@@ -90,27 +101,27 @@ class map
bool isRed() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mIsRed;
return IsRed;
}
bool isBlack() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return !mIsRed;
return !IsRed;
}
private:
RBTree();
RBTree* mLeftChild;
RBTree* mRightChild;
RBTree* LeftChild;
RBTree* RightChild;
RBTree* mParent;
RBTree* Parent;
KeyTypeRB mKey;
ValueTypeRB mValue;
KeyTypeRB Key;
ValueTypeRB Value;
bool mIsRed;
bool IsRed;
};
public:
......@@ -122,40 +133,40 @@ class map
{
public:
Iterator() : mRoot(0), mCur(0) {}
Iterator() : Root(0), Cur(0) {}
// Constructor(Node*)
Iterator(Node* root):mRoot(root)
Iterator(Node* root) : Root(root)
{
reset();
}
// Copy constructor
Iterator(const Iterator& src) : mRoot(src.mRoot), mCur(src.mCur){}
Iterator(const Iterator& src) : Root(src.Root), Cur(src.Cur) {}
void reset(bool atLowest=true)
{
if (atLowest)
mCur = getMin(mRoot);
Cur = getMin(Root);
else
mCur = getMax(mRoot);
Cur = getMax(Root);
}
bool atEnd() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mCur==0;
return Cur==0;
}
Node* getNode()
{
return mCur;
return Cur;
}
Iterator& operator=(const Iterator& src)
{
mRoot = src.mRoot;
mCur = src.mCur;
Root = src.Root;
Cur = src.Cur;
return (*this);
}
......@@ -180,7 +191,7 @@ class map
if (atEnd())
throw "Iterator at end";
return *mCur;
return *Cur;
}
private:
......@@ -202,20 +213,20 @@ class map
void inc()
{
// Already at end?
if (mCur==0)
if (Cur==0)
return;
if (mCur->getRightChild())
if (Cur->getRightChild())
{
// If current node has a right child, the next higher node is the
// node with lowest key beneath the right child.
mCur = getMin(mCur->getRightChild());
Cur = getMin(Cur->getRightChild());
}
else if (mCur->isLeftChild())
else if (Cur->isLeftChild())
{
// No right child? Well if current node is a left child then
// the next higher node is the parent
mCur = mCur->getParent();
Cur = Cur->getParent();
}
else
{
......@@ -224,29 +235,29 @@ class map
// The next higher node is the parent of the first non-right
// child (ie either a left child or the root) up in the
// hierarchy. Root's parent is 0.
while(mCur->isRightChild())
mCur = mCur->getParent();
mCur = mCur->getParent();
while(Cur->isRightChild())
Cur = Cur->getParent();
Cur = Cur->getParent();
}
}
void dec()
{
// Already at end?
if (mCur==0)
if (Cur==0)
return;
if (mCur->getLeftChild())
if (Cur->getLeftChild())
{
// If current node has a left child, the next lower node is the
// node with highest key beneath the left child.
mCur = getMax(mCur->getLeftChild());
Cur = getMax(Cur->getLeftChild());
}
else if (mCur->isRightChild())
else if (Cur->isRightChild())
{
// No left child? Well if current node is a right child then
// the next lower node is the parent
mCur = mCur->getParent();
Cur = Cur->getParent();
}
else
{
......@@ -256,14 +267,14 @@ class map
// child (ie either a right child or the root) up in the
// hierarchy. Root's parent is 0.
while(mCur->isLeftChild())
mCur = mCur->getParent();
mCur = mCur->getParent();
while(Cur->isLeftChild())
Cur = Cur->getParent();
Cur = Cur->getParent();
}
}
Node* mRoot;
Node* mCur;
Node* Root;
Node* Cur;
}; // Iterator
......@@ -278,38 +289,38 @@ class map
public:
ParentFirstIterator():mRoot(0),mCur(0)
ParentFirstIterator() : Root(0), Cur(0)
{
}
explicit ParentFirstIterator(Node* root):mRoot(root),mCur(0)
explicit ParentFirstIterator(Node* root) : Root(root), Cur(0)
{
reset();
}
void reset()
{
mCur = mRoot;
Cur = Root;
}
bool atEnd() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mCur==0;
return Cur==0;
}
Node* getNode()
{
return mCur;
return Cur;
}
ParentFirstIterator& operator=(const ParentFirstIterator& src)
{
mRoot = src.mRoot;
mCur = src.mCur;
Root = src.Root;
Cur = src.Cur;
return (*this);
}
......@@ -337,41 +348,41 @@ class map
void inc()
{
// Already at end?
if (mCur==0)
if (Cur==0)
return;
// First we try down to the left
if (mCur->getLeftChild())
if (Cur->getLeftChild())
{
mCur = mCur->getLeftChild();
Cur = Cur->getLeftChild();
}
else if (mCur->getRightChild())
else if (Cur->getRightChild())
{
// No left child? The we go down to the right.
mCur = mCur->getRightChild();
Cur = Cur->getRightChild();
}
else
{
// No children? Move up in the hierarcy until
// we either reach 0 (and are finished) or
// find a right uncle.
while (mCur!=0)
while (Cur!=0)
{
// But if parent is left child and has a right "uncle" the parent
// has already been processed but the uncle hasn't. Move to
// the uncle.
if (mCur->isLeftChild() && mCur->getParent()->getRightChild())
if (Cur->isLeftChild() && Cur->getParent()->getRightChild())
{
mCur = mCur->getParent()->getRightChild();
Cur = Cur->getParent()->getRightChild();
return;
}
mCur = mCur->getParent();
Cur = Cur->getParent();
}
}
}
Node* mRoot;
Node* mCur;
Node* Root;
Node* Cur;
}; // ParentFirstIterator
......@@ -385,33 +396,33 @@ class map
{
public:
ParentLastIterator():mRoot(0),mCur(0){}
ParentLastIterator() : Root(0), Cur(0) {}
explicit ParentLastIterator(Node* root) : mRoot(root), mCur(0)
explicit ParentLastIterator(Node* root) : Root(root), Cur(0)
{
reset();
}
void reset()
{
mCur = getMin(mRoot);
Cur = getMin(Root);
}
bool atEnd() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mCur==0;
return Cur==0;
}
Node* getNode()
{
return mCur;
return Cur;
}
ParentLastIterator& operator=(const ParentLastIterator& src)
{
mRoot = src.mRoot;
mCur = src.mCur;
Root = src.Root;
Cur = src.Cur;
return (*this);
}
......@@ -448,7 +459,7 @@ class map
void inc()
{
// Already at end?
if (mCur==0)
if (Cur==0)
return;
// Note: Starting point is the node as far down to the left as possible.
......@@ -456,17 +467,17 @@ class map
// If current node has an uncle to the right, go to the
// node as far down to the left from the uncle as possible
// else just go up a level to the parent.
if (mCur->isLeftChild() && mCur->getParent()->getRightChild())
if (Cur->isLeftChild() && Cur->getParent()->getRightChild())
{
mCur = getMin(mCur->getParent()->getRightChild());
Cur = getMin(Cur->getParent()->getRightChild());
}
else
mCur = mCur->getParent();
Cur = Cur->getParent();
}
Node* mRoot;
Node* mCur;
Node* Root;
Node* Cur;
}; // ParentLastIterator
......@@ -488,13 +499,13 @@ class map
void operator=(const ValueType& value)
{
// Just use the Set method, it handles already exist/not exist situation
mTree.set(mKey,value);
Tree.set(Key,value);
}
// ValueType operator
operator ValueType()
{
Node* node = mTree.find(mKey);
Node* node = Tree.find(Key);
// Not found
if (node==0)
......@@ -506,17 +517,17 @@ class map
private:
AccessClass(map& tree, const KeyType& key):mTree(tree),mKey(key){}
AccessClass(map& tree, const KeyType& key) : Tree(tree), Key(key) {}
AccessClass();
map& mTree;
const KeyType& mKey;
map& Tree;
const KeyType& Key;
}; // AccessClass
// Constructor.
map() : mRoot(0),mSize(0) {}
map() : Root(0), Size(0) {}
// Destructor
~map()
......@@ -608,7 +619,7 @@ class map
}
}
// Color the root black
mRoot->setBlack();
Root->setBlack();
return true;
}
......@@ -662,7 +673,7 @@ class map
// p is now gone from the tree in the sense that
// no one is pointing at it, so return it.
mSize--;
--Size;
return p;
}
......@@ -705,7 +716,7 @@ class map
// no one is pointing at it. Let's get rid of it.
delete p;
mSize--;
--Size;
return true;
}
......@@ -721,8 +732,8 @@ class map
// else iterator will get quite confused.
delete p;
}
mRoot = 0;
mSize= 0;
Root = 0;
Size= 0;
}
//! Is the tree empty?
......@@ -730,7 +741,7 @@ class map
bool isEmpty() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return mRoot == 0;
return Root == 0;
}
//! Search for a node with the specified key.
......@@ -738,7 +749,7 @@ class map
//! \return Returns 0 if node couldn't be found.
Node* find(const KeyType& keyToFind) const
{
Node* pNode = mRoot;
Node* pNode = Root;
while(pNode!=0)
{
......@@ -760,13 +771,13 @@ class map
//! 0 if the tree is empty.
Node* getRoot() const
{
return mRoot;
return Root;
}
//! Returns the number of nodes in the tree.
u32 size() const
{
return mSize;
return Size;
}
//------------------------------
......@@ -804,7 +815,7 @@ class map
// Public Operators
//------------------------------
//! operator [] for accesss to elements
//! operator [] for access to elements
//! for example myMap["key"]
AccessClass operator[](const KeyType& k)
{
......@@ -817,15 +828,15 @@ class map
//------------------------------
//! Copy constructor and assignment operator deliberately
//! defined but not implemented. The tree should never be
//! copied, pass along references to it instead (or use auto_ptr to it).
//! copied, pass along references to it instead.
explicit map(const map& src);
map& operator = (const map& src);
void setRoot(Node* newRoot)
{
mRoot = newRoot;
if (mRoot!=0)
mRoot->setParent(0);
Root = newRoot;
if (Root != 0)
Root->setParent(0);
}
//! Insert a node into the tree without using any fancy balancing logic.
......@@ -834,14 +845,14 @@ class map
{
bool result=true; // Assume success
if (mRoot==0)
if (Root==0)
{
setRoot(newNode);
mSize = 1;
Size = 1;
}
else
{
Node* pNode = mRoot;
Node* pNode = Root;
KeyType keyNew = newNode->getKey();
while (pNode)
{
......@@ -877,7 +888,7 @@ class map
}
if (result)
mSize++;
++Size;
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
......@@ -924,9 +935,8 @@ class map
//------------------------------
// Private Members
//------------------------------
Node* mRoot; // The top node. 0 if empty.
u32 mSize; // Number of nodes in the tree
Node* Root; // The top node. 0 if empty.
u32 Size; // Number of nodes in the tree
};
} // end namespace core
......
// 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 "CParticleAttractionAffector.h"
namespace irr
{
namespace scene
{
//! constructor
CParticleAttractionAffector::CParticleAttractionAffector(
const core::vector3df& point, f32 speed, bool attract,
bool affectX, bool affectY, bool affectZ )
: Point(point), Speed(speed), AffectX(affectX), AffectY(affectY),
AffectZ(affectZ), Attract(attract), LastTime(0)
{
}
//! Affects an array of particles.
void CParticleAttractionAffector::affect(u32 now, SParticle* particlearray, u32 count)
{
if( LastTime == 0 )
{
LastTime = now;
return;
}
f32 timeDelta = ( now - LastTime ) / 1000.0f;
LastTime = now;
if( !Enabled )
return;
for(u32 i=0; i<count; ++i)
{
core::vector3df direction = (Point - particlearray[i].pos).normalize();
direction *= Speed * timeDelta;
if( !Attract )
direction *= -1.0f;
if( AffectX )
particlearray[i].pos.X += direction.X;
if( AffectY )
particlearray[i].pos.Y += direction.Y;
if( AffectZ )
particlearray[i].pos.Z += direction.Z;
}
}
} // end namespace scene
} // end 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_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
#define __C_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
#include "IParticleAttractionAffector.h"
namespace irr
{
namespace scene
{
//! Particle Affector for attracting particles to a point
class CParticleAttractionAffector : public IParticleAttractionAffector
{
public:
CParticleAttractionAffector(
const core::vector3df& point = core::vector3df(), f32 speed = 1.0f,
bool attract = true, bool affectX = true,
bool affectY = true, bool affectZ = true );
//! Affects a particle.
virtual void affect(u32 now, SParticle* particlearray, u32 count);
//! Set the point that particles will attract to
virtual void setPoint( const core::vector3df& point ) { Point = point; }
//! Set the speed, in game units per second that the particles will attract to
//! the specified point
virtual void setSpeed( f32 speed ) { Speed = speed; }
//! Set whether or not the particles are attracting or detracting
virtual void setAttract( bool attract ) { Attract = attract; }
//! Set whether or not this will affect particles in the X direction
virtual void setAffectX( bool affect ) { AffectX = affect; }
//! Set whether or not this will affect particles in the Y direction
virtual void setAffectY( bool affect ) { AffectY = affect; }
//! Set whether or not this will affect particles in the Z direction
virtual void setAffectZ( bool affect ) { AffectZ = affect; }
//! Get the point that particles are attracted to
virtual const core::vector3df& getPoint() const { return Point; }
//! Get the speed that points attract to the specified point
virtual f32 getSpeed() const { return Speed; }
//! Get whether or not the particles are attracting or detracting
virtual bool getAttract() const { return Attract; }
//! Get whether or not the particles X position are affected
virtual bool getAffectX() const { return AffectX; }
//! Get whether or not the particles Y position are affected
virtual bool getAffectY() const { return AffectY; }
//! Get whether or not the particles Z position are affected
virtual bool getAffectZ() const { return AffectZ; }
private:
core::vector3df Point;
f32 Speed;
bool AffectX;
bool AffectY;
bool AffectZ;
bool Attract;
u32 LastTime;
};
} // end namespace scene
} // end namespace irr
#endif // __C_PARTICLE_ATTRACTION_AFFECTOR_H_INCLUDED__
......@@ -13,10 +13,10 @@ namespace scene
//! constructor
CParticleFadeOutAffector::CParticleFadeOutAffector(
video::SColor targetColor, u32 fadeOutTime)
: IParticleAffector(), TargetColor(targetColor)
const video::SColor& targetColor, u32 fadeOutTime)
: IParticleFadeOutAffector(), TargetColor(targetColor)
{
FadeOutTime = fadeOutTime ? (f32)fadeOutTime : 1.0f;
FadeOutTime = fadeOutTime ? static_cast<f32>(fadeOutTime) : 1.0f;
}
......
......@@ -5,7 +5,7 @@
#ifndef __C_PARTICLE_FADE_OUT_AFFECTOR_H_INCLUDED__
#define __C_PARTICLE_FADE_OUT_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
#include "IParticleFadeOutAffector.h"
#include "SColor.h"
namespace irr
......@@ -14,15 +14,29 @@ namespace scene
{
//! Particle Affector for fading out a color
class CParticleFadeOutAffector : public IParticleAffector
class CParticleFadeOutAffector : public IParticleFadeOutAffector
{
public:
CParticleFadeOutAffector(video::SColor targetColor, u32 fadeOutTime);
CParticleFadeOutAffector(const video::SColor& targetColor, u32 fadeOutTime);
//! Affects a particle.
virtual void affect(u32 now, SParticle* particlearray, u32 count);
//! Sets the targetColor, i.e. the color the particles will interpolate
//! to over time.
virtual void setTargetColor( const video::SColor& targetColor ) { TargetColor = targetColor; }
//! Sets the amount of time it takes for each particle to fade out.
virtual void setFadeOutTime( f32 fadeOutTime ) { FadeOutTime = fadeOutTime; }
//! Sets the targetColor, i.e. the color the particles will interpolate
//! to over time.
virtual const video::SColor& getTargetColor() const { return TargetColor; }
//! Sets the amount of time it takes for each particle to fade out.
virtual f32 getFadeOutTime() const { return FadeOutTime; }
//! Writes attributes of the object.
//! Implement this to expose the attributes of your scene node animator for
//! scripting languages, editors, debuggers or xml serialization purposes.
......@@ -35,9 +49,6 @@ public:
//! \return: returns last index of an attribute read by this affector
virtual s32 deserializeAttributes(s32 startIndex, io::IAttributes* in, io::SAttributeReadWriteOptions* options);
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_FADE_OUT; }
private:
video::SColor TargetColor;
......
......@@ -14,7 +14,7 @@ namespace scene
//! constructor
CParticleGravityAffector::CParticleGravityAffector(
const core::vector3df& gravity, u32 timeForceLost)
: IParticleAffector(), TimeForceLost((f32)timeForceLost), Gravity(gravity)
: IParticleGravityAffector(), TimeForceLost(static_cast<f32>(timeForceLost)), Gravity(gravity)
{
}
......
......@@ -5,7 +5,7 @@
#ifndef __C_PARTICLE_GRAVITY_AFFECTOR_H_INCLUDED__
#define __C_PARTICLE_GRAVITY_AFFECTOR_H_INCLUDED__
#include "IParticleAffector.h"
#include "IParticleGravityAffector.h"
#include "SColor.h"
namespace irr
......@@ -14,7 +14,7 @@ namespace scene
{
//! Particle Affector for affecting direction of particle
class CParticleGravityAffector : public IParticleAffector
class CParticleGravityAffector : public IParticleGravityAffector
{
public:
......@@ -25,6 +25,20 @@ public:
//! Affects a particle.
virtual void affect(u32 now, SParticle* particlearray, u32 count);
//! Set the time in milliseconds when the gravity force is totally
//! lost and the particle does not move any more.
virtual void setTimeForceLost( f32 timeForceLost ) { TimeForceLost = timeForceLost; }
//! Set the direction and force of gravity.
virtual void setGravity( const core::vector3df& gravity ) { Gravity = gravity; }
//! Set the time in milliseconds when the gravity force is totally
//! lost and the particle does not move any more.
virtual f32 getTimeForceLost() const { return TimeForceLost; }
//! Set the direction and force of gravity.
virtual const core::vector3df& getGravity() const { return Gravity; }
//! Writes attributes of the object.
//! Implement this to expose the attributes of your scene node animator for
//! scripting languages, editors, debuggers or xml serialization purposes.
......@@ -37,9 +51,6 @@ public:
//! \return: returns last index of an attribute read by this affector
virtual s32 deserializeAttributes(s32 startIndex, io::IAttributes* in, io::SAttributeReadWriteOptions* options);
//! Get emitter type
virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_GRAVITY; }
private:
f32 TimeForceLost;
......
// 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 "CParticleRotationAffector.h"
namespace irr
{
namespace scene
{
//! constructor
CParticleRotationAffector::CParticleRotationAffector( const core::vector3df& speed, const core::vector3df& pivotPoint )
: PivotPoint(pivotPoint), Speed(speed), LastTime(0)
{
}
//! Affects an array of particles.
void CParticleRotationAffector::affect(u32 now, SParticle* particlearray, u32 count)
{
if( LastTime == 0 )
{
LastTime = now;
return;
}
f32 timeDelta = ( now - LastTime ) / 1000.0f;
LastTime = now;
if( !Enabled )
return;
for(u32 i=0; i<count; ++i)
{
if( Speed.X != 0.0f )
particlearray[i].pos.rotateYZBy( timeDelta * Speed.X, PivotPoint );
if( Speed.Y != 0.0f )
particlearray[i].pos.rotateXZBy( timeDelta * Speed.Y, PivotPoint );
if( Speed.Z != 0.0f )
particlearray[i].pos.rotateXYBy( timeDelta * Speed.Z, PivotPoint );
}
}
} // end namespace scene
} // end 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_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
#define __C_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
#include "IParticleRotationAffector.h"
namespace irr
{
namespace scene
{
//! Particle Affector for rotating particles about a point
class CParticleRotationAffector : public IParticleRotationAffector
{
public:
CParticleRotationAffector( const core::vector3df& speed = core::vector3df(5.0f, 5.0f, 5.0f),
const core::vector3df& point = core::vector3df() );
//! Affects a particle.
virtual void affect(u32 now, SParticle* particlearray, u32 count);
//! Set the point that particles will attract to
virtual void setPivotPoint( const core::vector3df& point ) { PivotPoint = point; }
//! Set the speed in degrees per second
virtual void setSpeed( const core::vector3df& speed ) { Speed = speed; }
//! Get the point that particles are attracted to
virtual const core::vector3df& getPivotPoint() const { return PivotPoint; }
//! Get the speed in degrees per second
virtual const core::vector3df& getSpeed() const { return Speed; }
private:
core::vector3df PivotPoint;
core::vector3df Speed;
u32 LastTime;
};
} // end namespace scene
} // end namespace irr
#endif // __C_PARTICLE_ROTATION_AFFECTOR_H_INCLUDED__
......@@ -10,8 +10,10 @@
#include "CParticlePointEmitter.h"
#include "CParticleBoxEmitter.h"
#include "CParticleAttractionAffector.h"
#include "CParticleFadeOutAffector.h"
#include "CParticleGravityAffector.h"
#include "CParticleRotationAffector.h"
#include "SViewFrustum.h"
namespace irr
......@@ -133,22 +135,42 @@ IParticleEmitter* CParticleSystemSceneNode::createBoxEmitter(
//! Creates a point attraction affector. This affector modifies the positions of the
//! particles and attracts them to a specified point at a specified speed per second.
IParticleAttractionAffector* CParticleSystemSceneNode::createAttractionAffector(
const core::vector3df& point, f32 speed, bool attract,
bool affectX, bool affectY, bool affectZ )
{
return new CParticleAttractionAffector( point, speed, attract, affectX, affectY, affectZ );
}
//! Creates a fade out particle affector.
IParticleAffector* CParticleSystemSceneNode::createFadeOutParticleAffector(
video::SColor targetColor, u32 timeNeededToFadeOut)
IParticleFadeOutAffector* CParticleSystemSceneNode::createFadeOutParticleAffector(
const video::SColor& targetColor, u32 timeNeededToFadeOut)
{
return new CParticleFadeOutAffector(targetColor, timeNeededToFadeOut);
}
//! Creates a gravity affector.
IParticleAffector* CParticleSystemSceneNode::createGravityAffector(
IParticleGravityAffector* CParticleSystemSceneNode::createGravityAffector(
const core::vector3df& gravity, u32 timeForceLost)
{
return new CParticleGravityAffector(gravity, timeForceLost);
}
//! Creates a rotation affector. This affector rotates the particles around a specified pivot
//! point. The speed represents Degrees of rotation per second.
IParticleRotationAffector* CParticleSystemSceneNode::createRotationAffector(
const core::vector3df& speed, const core::vector3df& pivotPoint )
{
return new CParticleRotationAffector( speed, pivotPoint );
}
//! pre render event
void CParticleSystemSceneNode::OnRegisterSceneNode()
{
......
......@@ -78,16 +78,28 @@ public:
u32 lifeTimeMin=2000, u32 lifeTimeMax=4000,
s32 maxAngleDegrees=0);
//! Creates a point attraction affector. This affector modifies the positions of the
//! particles and attracts them to a specified point at a specified speed per second.
virtual IParticleAttractionAffector* createAttractionAffector(
const core::vector3df& point, f32 speed = 1.0f, bool attract = true,
bool affectX = true, bool affectY = true, bool affectZ = true);
//! Creates a fade out particle affector.
virtual IParticleAffector* createFadeOutParticleAffector(
video::SColor targetColor = video::SColor(0,0,0,0),
virtual IParticleFadeOutAffector* createFadeOutParticleAffector(
const video::SColor& targetColor = video::SColor(0,0,0,0),
u32 timeNeededToFadeOut = 1000);
//! Creates a gravity affector.
virtual IParticleAffector* createGravityAffector(
virtual IParticleGravityAffector* createGravityAffector(
const core::vector3df& gravity = core::vector3df(0.0f,-0.03f,0.0f),
u32 timeForceLost = 1000);
//! Creates a rotation affector. This affector rotates the particles
//! around a specified pivot point. The speed is in Degrees per second.
virtual IParticleRotationAffector* createRotationAffector(
const core::vector3df& speed = core::vector3df(5.0f,5.0f,5.0f),
const core::vector3df& pivotPoint = core::vector3df(0.0f,0.0f,0.0f) );
//! Sets the size of all particles.
virtual void setParticleSize(
const core::dimension2d<f32> &size = core::dimension2d<f32>(5.0f, 5.0f));
......
......@@ -19,7 +19,7 @@ VERSION = 1.3.1
#
#List of object files, separated based on engine architecture
IRROBJ = C3DSMeshFileLoader.o COgreMeshFileLoader.o COBJMeshFileLoader.o CAnimatedMeshMD2.o CAnimatedMeshMD3.o CMD3MeshFileLoader.o CAnimatedMeshMS3D.o CAnimatedMeshB3d.o CAnimatedMeshSceneNode.o CBillboardSceneNode.o CCameraFPSSceneNode.o CCameraMayaSceneNode.o CCameraSceneNode.o CColladaFileLoader.o CCSMLoader.o CDefaultMeshFormatLoader.o CDMFLoader.o CDummyTransformationSceneNode.o CEmptySceneNode.o CGeometryCreator.o CLightSceneNode.o CLMTSMeshFileLoader.o CMeshManipulator.o CMeshSceneNode.o CMetaTriangleSelector.o CMY3DMeshFileLoader.o COCTLoader.o COctTreeSceneNode.o COctTreeTriangleSelector.o CParticleBoxEmitter.o CParticleFadeOutAffector.o CParticleGravityAffector.o CParticlePointEmitter.o CParticleSystemSceneNode.o CQ3LevelMesh.o CSceneCollisionManager.o CSceneManager.o CSceneNodeAnimatorCollisionResponse.o CSceneNodeAnimatorDelete.o CSceneNodeAnimatorFlyCircle.o CSceneNodeAnimatorFlyStraight.o CSceneNodeAnimatorFollowSpline.o CSceneNodeAnimatorRotation.o CSceneNodeAnimatorTexture.o CShadowVolumeSceneNode.o CSkyBoxSceneNode.o CSkyDomeSceneNode.o CTerrainSceneNode.o CTerrainTriangleSelector.o CCubeSceneNode.o CSphereSceneNode.o CTextSceneNode.o CTriangleBBSelector.o CTriangleSelector.o CWaterSurfaceSceneNode.o CXAnimationPlayer.o CXFileReader.o CXMeshFileLoader.o CMeshCache.o CDefaultSceneNodeAnimatorFactory.o CDefaultSceneNodeFactory.o CQuake3ShaderSceneNode.o
IRROBJ = C3DSMeshFileLoader.o COgreMeshFileLoader.o COBJMeshFileLoader.o CAnimatedMeshMD2.o CAnimatedMeshMD3.o CMD3MeshFileLoader.o CAnimatedMeshMS3D.o CAnimatedMeshB3d.o CAnimatedMeshSceneNode.o CBillboardSceneNode.o CCameraFPSSceneNode.o CCameraMayaSceneNode.o CCameraSceneNode.o CColladaFileLoader.o CCSMLoader.o CDefaultMeshFormatLoader.o CDMFLoader.o CDummyTransformationSceneNode.o CEmptySceneNode.o CGeometryCreator.o CLightSceneNode.o CLMTSMeshFileLoader.o CMeshManipulator.o CMeshSceneNode.o CMetaTriangleSelector.o CMY3DMeshFileLoader.o COCTLoader.o COctTreeSceneNode.o COctTreeTriangleSelector.o CParticleBoxEmitter.o CParticleAttractionAffector.o CParticleFadeOutAffector.o CParticleGravityAffector.o CParticleRotationAffector.o CParticlePointEmitter.o CParticleSystemSceneNode.o CQ3LevelMesh.o CSceneCollisionManager.o CSceneManager.o CSceneNodeAnimatorCollisionResponse.o CSceneNodeAnimatorDelete.o CSceneNodeAnimatorFlyCircle.o CSceneNodeAnimatorFlyStraight.o CSceneNodeAnimatorFollowSpline.o CSceneNodeAnimatorRotation.o CSceneNodeAnimatorTexture.o CShadowVolumeSceneNode.o CSkyBoxSceneNode.o CSkyDomeSceneNode.o CTerrainSceneNode.o CTerrainTriangleSelector.o CCubeSceneNode.o CSphereSceneNode.o CTextSceneNode.o CTriangleBBSelector.o CTriangleSelector.o CWaterSurfaceSceneNode.o CXAnimationPlayer.o CXFileReader.o CXMeshFileLoader.o CMeshCache.o CDefaultSceneNodeAnimatorFactory.o CDefaultSceneNodeFactory.o CQuake3ShaderSceneNode.o
IRRVIDEOOBJ = COpenGLDriver.o COpenGLNormalMapRenderer.o COpenGLParallaxMapRenderer.o COpenGLShaderMaterialRenderer.o COpenGLTexture.o COpenGLSLMaterialRenderer.o COpenGLExtensionHandler.o CD3D8Driver.o CD3D8NormalMapRenderer.o CD3D8ParallaxMapRenderer.o CD3D8ShaderMaterialRenderer.o CD3D8Texture.o CColorConverter.o CFPSCounter.o CImage.o CImageLoaderBMP.o CImageLoaderJPG.o CImageLoaderPCX.o CImageLoaderPNG.o CImageLoaderPSD.o CImageLoaderTGA.o CImageWriterBMP.o CImageWriterJPG.o CImageWriterPCX.o CImageWriterPNG.o CImageWriterPPM.o CImageWriterPSD.o CImageWriterTGA.o CNullDriver.o CD3D9Driver.o CD3D9HLSLMaterialRenderer.o CD3D9NormalMapRenderer.o CD3D9ParallaxMapRenderer.o CD3D9ShaderMaterialRenderer.o CD3D9Texture.o CVideoModeList.o
IRRSWRENDEROBJ = CSoftwareDriver.o CSoftwareTexture.o CTRFlat.o CTRFlatWire.o CTRGouraud.o CTRGouraudWire.o CTRTextureFlat.o CTRTextureFlatWire.o CTRTextureGouraud.o CTRTextureGouraudAdd.o CTRTextureGouraudNoZ.o CTRTextureGouraudWire.o CZBuffer.o CTRTextureGouraudVertexAlpha2.o CTRTextureGouraudNoZ2.o CTRTextureLightMap2_M2.o CTRTextureLightMap2_M4.o CTRTextureLightMap2_M1.o CSoftwareDriver2.o CSoftwareTexture2.o CTRTextureGouraud2.o CTRGouraud2.o CTRGouraudAlpha2.o CTRGouraudAlphaNoZ2.o CTRTextureDetailMap2.o CTRTextureGouraudAdd2.o CTRTextureGouraudAddNoZ2.o CTRTextureWire2.o CTRTextureLightMap2_Add.o CTRTextureLightMapGouraud2_M4.o IBurningShader.o CTRTextureBlend.o CTRTextureGouraudAlpha.o CTRTextureGouraudAlphaNoZ.o CDepthBuffer.o
IRRIOOBJ = CFileList.o CFileSystem.o CLimitReadFile.o CMemoryReadFile.o CReadFile.o CWriteFile.o CXMLReader.o CXMLWriter.o CZipReader.o CPakReader.o irrXML.o CAttributes.o
......@@ -38,7 +38,7 @@ CXXINCS = -I../../include -Izlib -Ijpeglib -Ilibpng
CPPFLAGS = $(CXXINCS) -DIRRLICHT_EXPORTS=1
CXXFLAGS = -Wall
ifndef NDEBUG
CXXFLAGS += -g
CXXFLAGS += -g -D_DEBUG
else
CXXFLAGS += -fexpensive-optimizations -O3
endif
......
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