The package can be downloaded from my homepage (http://bulletbyte.de/products.php?sub=i ... dowmanager), or you simply copy the code posted below (but the irrEdit plugin is not included here):And another little addon for Irrlicht from myself: This time I have created a scene node that doesn't do anything but add and remove shadow volume scene nodes to / from it's parent (which must be of type IAnimatedMeshSceneNode). There is this "CManagedShadow" scene node and a "CShadowManager" that work in the following way: you define a level for the shadow of an animated mesh scene node, and then you tell the shadow manager that the level for shadows has a certain value. All shadows with a level less or equal to the manager's level will be shown, all others will be hidden. You can change the level at runtime, the shadows are added and removed dynamically.
The package contains:
* the source code of the managed shadow scene node
* the source code of the shadow manager
* a demo application
* a plugin for IrrEdit so that you can define the shadows at design time
The whole package is licensed under the terms of the zlib license.
CManagedShadow.h
Code: Select all
#ifndef _C_MANAGED_SHADOW
#define _C_MANAGED_SHADOW
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class CShadowManager;
const int MANAGED_SHADOW_ID=MAKE_IRR_ID('m','g','s','d');
const c8 MANAGED_SHADOW_NAME[0xFF]="CManagedShadow";
class CManagedShadow : public ISceneNode {
private:
IShadowVolumeSceneNode *m_pShadow;
ISceneManager *m_pSceneManager;
u32 m_iLevel;
public:
CManagedShadow(ISceneNode *pParent, ISceneManager *pMgr, s32 iId=-1, const vector3df pos=vector3df(0,0,0), const vector3df rot=vector3df(0,0,0), const vector3df scale=vector3df(1,1,1));
virtual void render() { }
virtual const aabbox3df &getBoundingBox() const {
static aabbox3df aBox;
return aBox;
}
void setLevel(u32 iLevel);
u32 getLevel();
virtual ESCENE_NODE_TYPE getType() const;
void update(u32 theLevel);
virtual void serializeAttributes(IAttributes* out, SAttributeReadWriteOptions* options) const;
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
virtual ISceneNode *clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
};
#endif
Code: Select all
#include <irrlicht.h>
#include <CManagedShadow.h>
#include <CShadowManager.h>
CManagedShadow::CManagedShadow(ISceneNode *pParent, ISceneManager *pMgr, s32 iId, const vector3df pos, const vector3df rot, const vector3df scale) : ISceneNode(pParent,pMgr,iId,pos,rot,scale) {
m_pShadow=NULL;
m_iLevel=3;
m_pSceneManager=pMgr;
CShadowManager::getSharedInstance()->addShadow(this);
}
void CManagedShadow::setLevel(u32 iLevel) {
m_iLevel=iLevel;
}
u32 CManagedShadow::getLevel() {
return m_iLevel;
}
void CManagedShadow::update(u32 theLevel) {
if (m_iLevel<=theLevel) {
if (m_pShadow==NULL) {
IAnimatedMeshSceneNode *pParent=reinterpret_cast<IAnimatedMeshSceneNode *>(getParent());
m_pShadow=pParent->addShadowVolumeSceneNode();
}
}
else {
if (m_pShadow!=NULL) {
m_pShadow->setShadowMesh(NULL);
m_pShadow->updateShadowVolumes();
m_pShadow->remove();
m_pShadow=NULL;
}
}
}
ESCENE_NODE_TYPE CManagedShadow::getType() const {
return (ESCENE_NODE_TYPE)MANAGED_SHADOW_ID;
}
void CManagedShadow::serializeAttributes(IAttributes* out, SAttributeReadWriteOptions* options) const {
ISceneNode::serializeAttributes(out,options);
out->addInt("ShadowLevel",m_iLevel);
}
void CManagedShadow::deserializeAttributes(IAttributes* in, SAttributeReadWriteOptions* options) {
ISceneNode::deserializeAttributes(in,options);
m_iLevel=in->getAttributeAsInt("ShadowLevel");
}
ISceneNode *CManagedShadow::clone(ISceneNode* newParent, ISceneManager* newManager) {
CManagedShadow *pRet=new CManagedShadow(newParent,newManager?newManager:m_pSceneManager);
pRet->setLevel(m_iLevel);
return pRet;
}
Code: Select all
#ifndef _C_SHADOW_MANAGER
#define _C_SHADOW_MANAGER
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class CManagedShadow;
class CShadowManager {
private:
list <CManagedShadow *> m_lShadows;
u32 m_iPriority;
protected:
CShadowManager();
public:
static CShadowManager *getSharedInstance();
void addShadow(CManagedShadow *pNew);
void setPriority(u32 iPrio);
};
#endif
Code: Select all
#include <irrlicht.h>
#include <CShadowManager.h>
#include <CManagedShadow.h>
CShadowManager::CShadowManager() {
}
CShadowManager *CShadowManager::getSharedInstance() {
static CShadowManager theManager;
return &theManager;
}
void CShadowManager::addShadow(CManagedShadow *pNew) {
m_lShadows.push_back(pNew);
}
void CShadowManager::setPriority(u32 iPrio) {
if (iPrio!=m_iPriority) {
m_iPriority=iPrio;
list<CManagedShadow *>::Iterator it;
for (it=m_lShadows.begin(); it!=m_lShadows.end(); it++) {
(*it)->update(m_iPriority);
}
}
}
