/* 
Level of Details class
Copyright (C) 2007 Pierre Schwartz

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef H__LOD_Animated_scenenode__
#define H__LOD_Animated_scenenode__

#include <irrlicht.h>
#include <vector>

/**
 * generic SceneNode class, implementing Level of Details
 */
class LOD_Animated_scenenode : public irr::scene::IAnimatedMeshSceneNode{
public:
	LOD_Animated_scenenode(std::vector<irr::scene::IAnimatedMesh*>&, std::vector<irr::f32>&, irr::scene::ISceneNode *, irr::scene::ISceneManager *, irr::s32);
	
	// ISceneNode
	void OnRegisterSceneNode();
	void render();
	const irr::core::aabbox3d<irr::f32>& getBoundingBox() const;
	void OnPreRender();

	// IAnimatedMeshSceneNode
	void setCurrentFrame(irr::s32);
	bool setFrameLoop(irr::s32, irr::s32);
	void setAnimationSpeed(irr::s32);
	irr::scene::IShadowVolumeSceneNode* addShadowVolumeSceneNode(irr::s32 id=-1, bool zfailmethod=true, irr::f32 infinity=10000.0f);
	irr::scene::ISceneNode* getMS3DJointNode(const irr::c8*);
	irr::scene::ISceneNode* getXJointNode(const irr::c8*);
	irr::scene::ISceneNode* getB3DJointNode(const irr::c8*);
	bool setMD2Animation(irr::scene::EMD2_ANIMATION_TYPE);
	bool setMD2Animation(const irr::c8*);
	irr::s32 getFrameNr();
	void setLoopMode(bool);
	void setAnimationEndCallback(irr::scene::IAnimationEndCallBack* callback=0);
	void setReadOnlyMaterials(bool);
	bool isReadOnlyMaterials();
	irr::scene::IAnimatedMesh* getMesh(void);
	void setMesh(irr::scene::IAnimatedMesh *);
	void setMaterialTexture(irr::s32, irr::video::ITexture*);
	void setMaterialFlag(irr::video::E_MATERIAL_FLAG, bool);

protected:
	irr::core::aabbox3d<irr::f32> Box;

	int current_index;
	irr::scene::IAnimatedMeshSceneNode* current_node;
	irr::f32 current_distance;

	std::vector<irr::scene::IAnimatedMeshSceneNode*> l_nodes;
	std::vector<irr::f32> l_distances;

	// the LOD is always done according to a specific camera
	irr::scene::ICameraSceneNode *c;
};

#endif
