//------------------------------------------------------------------------------------
// irr::scene::ISceneNode wrappers
//------------------------------------------------------------------------------------
//#include "iostream.h"

extern "C"
{

	void IrrScene_ISceneNode_addAnimator(ISceneNode* sn,ISceneNodeAnimator* animator)
	{
		if (sn)
			sn->addAnimator(animator);
	}
	
	void IrrScene_ISceneNode_OnRegisterSceneNode(ISceneNode* sn)
	{
		if (sn)
			sn->OnRegisterSceneNode();
	}
	
	void IrrScene_ISceneNode_OnAnimate(ISceneNode* sn,u32 timeMs)
	{
		if (sn)
			sn->OnAnimate(timeMs);
	}
	
	void IrrScene_ISceneNode_addChild(ISceneNode* sn,ISceneNode* child)
	{
		if (sn)
			sn->addChild(child);
	}
	
	vector3df* IrrScene_ISceneNode_getAbsolutePosition(ISceneNode* sn)
	{
		if (sn)
			return new vector3df(sn->getAbsolutePosition());
		else return 0;
	}
	
	// do not delete this pointer
	matrix4* IrrScene_ISceneNode_getAbsoluteTransformation(ISceneNode* sn)
	{
		if (sn)
			return new matrix4(sn->getAbsoluteTransformation());
		else return 0;
	}
	
	s32 IrrScene_ISceneNode_getAutomaticCulling(ISceneNode* sn)
	{
		if (sn)
			return sn->getAutomaticCulling();
		else return -1;
	}
	
	aabbox3df* IrrScene_ISceneNode_getBoundingBox(ISceneNode* sn)
	{
		if (sn)
			return new aabbox3df(sn->getBoundingBox());
		else return 0;
	}
	
	s32 IrrScene_ISceneNode_getID(ISceneNode* sn)
	{
		if (sn)
			return sn->getID();
		else return -1;
	}
	
	// do not delete this pointer
	SMaterial* IrrScene_ISceneNode_getMaterial(ISceneNode* sn,u32 i)
	{
		if (sn)
			return &sn->getMaterial(i);
		else return 0;
	}
	
	u32 IrrScene_ISceneNode_getMaterialCount(ISceneNode* sn)
	{
		if (sn)
			return sn->getMaterialCount();
		else return 0;
	}
	
	const char* IrrScene_ISceneNode_getName(ISceneNode* sn)
	{
		if (sn)
			return sn->getName();
		else return "";
	}
	
	// do not delete this pointer
	ISceneNode* IrrScene_ISceneNode_getParent(ISceneNode* sn)
	{
		if (sn)
			return sn->getParent();
		else return 0;
	}
	
	vector3df* IrrScene_ISceneNode_getPosition(ISceneNode* sn)
	{
		if (sn)
			return new vector3df(sn->getPosition());
		else return 0;
	}
	
	matrix4* IrrScene_ISceneNode_getRelativeTransformation(ISceneNode* sn)
	{
		if (sn)
			return new matrix4(sn->getRelativeTransformation());
		else return 0;
	}
	
	vector3df* IrrScene_ISceneNode_getRotation(ISceneNode* sn)
	{
		if (sn)
			return new vector3df(sn->getRotation());
		else return 0;
	}
	
	vector3df* IrrScene_ISceneNode_getScale(ISceneNode* sn)
	{
		if (sn)
			return new vector3df(sn->getScale());
		else return 0;
	}
	
	aabbox3d<f32>* IrrScene_ISceneNode_getTransformedBoundingBox(ISceneNode* sn)
	{
		if (sn)
			return new aabbox3d<f32>(sn->getTransformedBoundingBox());
		else return 0;
	}
	
	ITriangleSelector* IrrScene_ISceneNode_getTriangleSelector(ISceneNode* sn)
	{
		if (sn)
			return sn->getTriangleSelector();
		else return 0;
	}
	
	s32 IrrScene_ISceneNode_isDebugDataVisible(ISceneNode* sn)
	{
		if (sn)
			return sn->isDebugDataVisible();
		else return -1;
	}
	
	bool IrrScene_ISceneNode_isVisible(ISceneNode* sn)
	{
		if (sn)
			return sn->isVisible();
		else return false;
	}
	
	void IrrScene_ISceneNode_remove(ISceneNode* sn)
	{
		if (sn)
			sn->remove();
	}
	
	void IrrScene_ISceneNode_removeAll(ISceneNode* sn)
	{
		if (sn)
			sn->removeAll();
	}
	
	void IrrScene_ISceneNode_removeAnimator(ISceneNode* sn,ISceneNodeAnimator* animator)
	{
		if (sn)
			sn->removeAnimator(animator);
	}
	
	void IrrScene_ISceneNode_removeAnimators(ISceneNode* sn)
	{
		if (sn)
			sn->removeAnimators();
	}
	
	bool IrrScene_ISceneNode_removeChild(ISceneNode* sn,ISceneNode* child)
	{
		if (sn)
			return sn->removeChild(child);
		else return false;
	}
	
	void IrrScene_ISceneNode_render(ISceneNode* sn)
	{
		if (sn)
			sn->render();
	}
	
	void IrrScene_ISceneNode_setAutomaticCulling(ISceneNode* sn,E_CULLING_TYPE state)
	{
		if (sn)
			sn->setAutomaticCulling(state);
	}
	
	void IrrScene_ISceneNode_setDebugDataVisible(ISceneNode* sn, s32 state)
	{
		if (sn)
			sn->setDebugDataVisible(state);
	}
	
	void IrrScene_ISceneNode_setID(ISceneNode* sn,s32 id)
	{
		if (sn)
			sn->setID(id);
	}
	
	void IrrScene_ISceneNode_setMaterialFlag(ISceneNode* sn,E_MATERIAL_FLAG flag,bool newvalue)
	{
		if (sn)
			sn->setMaterialFlag(flag,newvalue);
	}
	
	void IrrScene_ISceneNode_setMaterialTexture(ISceneNode* sn,u32 textureLayer,ITexture* texture)
	{
		if (sn)
			sn->setMaterialTexture(textureLayer,texture);
	}
	
	void IrrScene_ISceneNode_setMaterialType(ISceneNode* sn,E_MATERIAL_TYPE newType)
	{
		if (sn)
			sn->setMaterialType(newType);
	}
	
	void IrrScene_ISceneNode_setMaterial(ISceneNode* sn,s32 i,SMaterial* newmat)
	{
		if (sn)
			sn->getMaterial(i)=*newmat;
	}
	
	void IrrScene_ISceneNode_setName(ISceneNode* sn,const char* name)
	{
		if (sn)
			sn->setName(name);
	}
	
	void IrrScene_ISceneNode_setParent(ISceneNode* sn,ISceneNode* newParent=0)
	{
		if (sn)
			sn->setParent(newParent);
	}
	
	void IrrScene_ISceneNode_setPosition(ISceneNode* sn,vector3df* newpos)
	{
		if (sn)
			sn->setPosition(*newpos);
	}
	
	void IrrScene_ISceneNode_setRotation(ISceneNode* sn,vector3df* rotation)
	{
		if (sn)
			sn->setRotation(*rotation);
	}
	
	void IrrScene_ISceneNode_setScale(ISceneNode* sn,vector3df* scale)
	{
		if (sn)
			sn->setScale(*scale);
	}
	
	void IrrScene_ISceneNode_setTriangleSelector(ISceneNode* sn,ITriangleSelector* selector)
	{
		if (sn)
			sn->setTriangleSelector(selector);
	}
	
	void IrrScene_ISceneNode_setVisible(ISceneNode* sn,bool isVisible)
	{
		if (sn)
			sn->setVisible(isVisible);
	}
	
	void IrrScene_ISceneNode_updateAbsolutePosition(ISceneNode* sn)
	{
		if (sn)
			sn->updateAbsolutePosition();
	}
	
	s32 IrrScene_ISceneNode_getChildren(ISceneNode* sn,u32** children)
	{
		if (sn)	{			
			Irr_ptrarray_allocate(children,sn->getChildren().getSize());

			irr::core::list<ISceneNode*>::ConstIterator it = sn->getChildren().begin();
			s32 i=0;
	
			// put the pointers into an array
			for (; it != sn->getChildren().end(); ++it)
			{
				((u32*)*children)[i]=(u32)(*it);
				i++;
			}		

			return sn->getChildren().getSize();
		} else return 0;
	}
	
	void IrrScene_ISceneNode_setIsDebugObject(ISceneNode* sn,bool debugObject)
	{
		if (sn)
			sn->setIsDebugObject(debugObject);
	}
	
	bool IrrScene_ISceneNode_isDebugObject(ISceneNode* sn)
	{
		if (sn)
			return sn->isDebugObject();
		else return false;
	}
	
	s32 IrrScene_ISceneNode_getType(ISceneNode* sn)
	{
		if (sn)
			return sn->getType();
		else return -1;
	}
	
	// returns # of animators stored.  must not delete ptrs!
	s32 IrrScene_ISceneNode_getAnimators(ISceneNode* sn,u32** animPtr)
	{
		if (sn)	{			
			Irr_ptrarray_allocate(animPtr,sn->getAnimators().getSize());

			irr::core::list<ISceneNodeAnimator*>::ConstIterator it = sn->getAnimators().begin();
			s32 i=0;
	
			// put the pointers into an array
			for (; it != sn->getAnimators().end(); ++it)
			{
				((u32*)*animPtr)[i]=(u32)(*it);
				i++;
			}		

			return sn->getAnimators().getSize();
		} else return 0;
	}

	IReferenceCounted* IrrScene_ISceneNode_castToIReferenceCounted(ISceneNode* unk)
	{
		if (unk) {
			return (IReferenceCounted*)unk;
		} else return 0;
	}

	ISceneNode* IrrScene_ISceneNode_clone(ISceneNode* sn,ISceneNode* newParent=0, ISceneManager* newManager=0) 
	{
		if (sn)
			return sn->clone(newParent,newManager);
		else return 0;
	}

	// do not delete
	ISceneManager* IrrScene_ISceneNode_getSceneManager(ISceneNode* sn) {
    if (sn) {
      return sn->getSceneManager();
    } else return 0;
	}

	bool IrrScene_ISceneNode_isTrulyVisible(ISceneNode* s) {
		if (s)
			return s->isTrulyVisible();
		else return false;
	}
	
}


