//********************************************************************
// This source file is part of Ninfa3D Engine
// 
// Copyright (C) 2008-2009 Viz_fuerte.
// All rights reserved.
// 
// LIMITED WARRANTY
// This software is provided "as-is", without any express or implied warranty.
// In no event shall the author be held liable for any damages arising from the use of this software.
// This is a contract. By accepting the Ninfa3D Engine (the SOFTWARE), 
// you (either an individual or a single entity, the LICENSEE) accept the terms and conditions of this licensing agreement.
// 
// If the LICENSEE does not accept the terms and conditions, then LICENSEE must not accept the SOFTWARE.
// If at a later time the LICENSEE decides not to continue licensing the SOFTWARE under these terms and 
// conditions, then the LICENSEE must delete permanently all files constituting the SOFTWARE.
//
// File: Terrain.cpp
//********************************************************************

/*--------------------------------------------------------------------
Includos*/

	#include "..\..\Header Files\Ninfa3D.h"

/*--------------------------------------------------------------------
Variables externas*/

	extern ISceneManager* SceneManager;
	extern int TotalMeshes;

/*--------------------------------------------------------------------
Declaration global de funciones*/

extern "C"
{

	/*====================================================================
	Carga un archivo para escribir*/

	

	DLL_EXPORT void* DLL_APIENTRY LoadTerrain(
								  char *cptrFile,
								  float xPos, float yPos, float zPos,
								  float xRot, float yRot, float zRot,
								  float xSca, float ySca, float zSca,
								  int a, int r, int g, int b,
								  int smoothing,
								  int maxLOD,
								  int patchSize )
{
    ITerrainSceneNode* terrain = SceneManager->addTerrainSceneNode(
			cptrFile,								// heightmap
			NULL,									// parent
			-1,										// id
			core::vector3df(xPos,yPos,zPos),		// position
			core::vector3df(xRot,yRot,zRot),		// rotation
			core::vector3df(xSca,ySca,zSca),		// scale
			video::SColor(a,r,g,b),					// vertex color
			(s32)maxLOD,							// the maximum level of detail
			(scene::E_TERRAIN_PATCH_SIZE)patchSize,	// the size of the patches
			(s32)smoothing );						// the number of times to smooth the terrain
		
		terrain->setMaterialFlag(EMF_TRILINEAR_FILTER,true);
		terrain->setMaterialFlag(EMF_ANISOTROPIC_FILTER,true);
		terrain->setMaterialFlag(EMF_FOG_ENABLE,true);

		TotalMeshes = TotalMeshes+1;

		return (void*)terrain;
}


	DLL_EXPORT void DLL_APIENTRY ScaleTexture(ITerrainSceneNode* terrain,float SX,float SY)
	{
		terrain->scaleTexture(SX,SY);
	}

	DLL_EXPORT float DLL_APIENTRY TerrainHeight(ITerrainSceneNode* terrain,float X,float Z)
	{
		return terrain->getHeight(X,Z);
	}

}
