//Grass.cpp
//Adapted by Frank Dodd for IrrlichtWrapper
//Adapted by nespa for Ninfa3D

#include "..\..\Header Files\Ninfa3D.h"
#include "..\..\Codes\CGrassPatchSceneNode.h"
#include "..\..\Codes\CWindGenerator.h"


//extern ISceneNode* parent;
extern ITerrainSceneNode* terrain;
extern IrrlichtDevice* device;
extern IVideoDriver* driver;
extern ISceneManager* SceneManager;
extern IGUIEnvironment* guienv;
extern CGrassPatchSceneNode* grass;
extern IWindGenerator* wind;
extern position2d<s32> dataPosition;
extern IImage* heightMap;
extern IImage* textureMap;
extern IImage* grassMap;
extern ITexture* grassTexture;
//extern char* "grass";

extern "C"
{
/* ----------------------------------------------------------------------------
Adds a grass object to the scene
*/
DLL_EXPORT CGrassPatchSceneNode* DLL_APIENTRY  nAddGrass(
                                    scene::ITerrainSceneNode* terrain,
                                    s32 x,
                                    s32 z,
                                    s32 patchSize,
                                    f32 grassScale,
									u32 maxDensity,
									u32 dataPositionX,
									u32 dataPositionY,
                                    video::IImage* heightMap,
                                    video::IImage* textureMap,
                                    video::IImage* grassMap,
                                    video::ITexture* grassTexture )
{
    scene::IWindGenerator* wind;
    

    wind = scene::createWindGenerator( 30.0f, 3.0f );

	core::position2d<s32> dataPosition( dataPositionX, dataPositionY );

	scene::CGrassPatchSceneNode* grass = new scene::CGrassPatchSceneNode(
            terrain,
            SceneManager,
            -1,
            core::vector3d<s32>(x,0,z),
            patchSize,
            grassScale,
			maxDensity,
			dataPosition,
            "grass",
            heightMap,
            textureMap,
            grassMap,
            wind);

    grass->setMaterialFlag(video::EMF_LIGHTING,false);
    grass->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
    grass->setMaterialTexture(0,grassTexture);

    return (CGrassPatchSceneNode*)grass;
}


/* ----------------------------------------------------------------------------
Set grass density
*/
void DLL_EXPORT nSetGrassDensity( CGrassPatchSceneNode * grass, int density, float distance )
{
    grass->setMaxDensity( density );
    grass->setDrawDistance( distance );
}


/* ----------------------------------------------------------------------------
Adds a grass object to the scene
*/
void DLL_EXPORT nSetGrassWind( CGrassPatchSceneNode * grass, float strength, float res )
{
    grass->getWind()->setStrength( strength );
    grass->getWind()->setRegularity( res );
}


/* ----------------------------------------------------------------------------
get the number of grass objects drawn
*/
u32 DLL_EXPORT nGetGrassDrawCount( CGrassPatchSceneNode * grass )
{
    return grass->getLastDrawCount();
}


}