//********************************************************************
// 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: World.cpp
//********************************************************************

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

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

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

	extern NewtonWorld *nWorld;
	//extern const dMOUSE_POINT& mouse1;
	float GravityX = 0;
	float GravityY = -9.81;
	float GravityZ = 0;
	
/*--------------------------------------------------------------------
Declaracion global de funciones*/

extern "C"
{

	/*====================================================================
	Crea un cuerpo vacio*/

	DLL_EXPORT void DLL_APIENTRY WorldGravity(float gx,float gy,float gz)
	{
		GravityX = gx;
		GravityY = gy;
		GravityZ = gz;
	}

	/*====================================================================
	Crea una malla vacia*/

	DLL_EXPORT void DLL_APIENTRY WorldSize(float sx,float sy,float sz)
	{
		dVector minWorldBox(-sx,-sy,-sz);
		dVector maxWorldBox( sx, sy, sz);
		NewtonSetWorldSize(nWorld,&minWorldBox.m_x,&maxWorldBox.m_x);
	}

	/*====================================================================
	Crea una malla vacia*/

	DLL_EXPORT void DLL_APIENTRY PhysicQuality(int model)
	{
		switch(model)
		{
			case(0):
				NewtonSetSolverModel(nWorld,4);
				NewtonSetFrictionModel(nWorld,1);
				NewtonSetPlatformArchitecture(nWorld,3);
				NewtonSetThreadsCount(nWorld,0);
				NewtonSetMultiThreadSolverOnSingleIsland(nWorld,1);
			break;
			case(1):
				NewtonSetSolverModel(nWorld,2);
				NewtonSetFrictionModel(nWorld,1);
				NewtonSetPlatformArchitecture(nWorld,2);
				NewtonSetThreadsCount(nWorld,4);
				NewtonSetMultiThreadSolverOnSingleIsland(nWorld,1);
			break;
			case(2):
				NewtonSetSolverModel(nWorld,0);
				NewtonSetFrictionModel(nWorld,0);
				NewtonSetPlatformArchitecture(nWorld,0);
				NewtonSetThreadsCount(nWorld,8);
				NewtonSetMultiThreadSolverOnSingleIsland(nWorld,0);
			break;
		}

	}

	

	DLL_EXPORT void* DLL_APIENTRY WorldMousePick(int mouse1x,int mouse1y,int mouseLeftKey1)
	{
		return (void*)MousePick(mouse1x,mouse1y,mouseLeftKey1);
	}

}