781f5e0bd7
- aggiunte funzioni Exe e Lua CDeRectPrismoidSolid e CDeConeSolid - ricompilazione per nuova versione 2.3.
180 lines
5.7 KiB
C++
180 lines
5.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2020-2020
|
|
//----------------------------------------------------------------------------
|
|
// File : LUA_CDeObjSolid.cpp Data : 09.01.20 Versione : 2.2a2
|
|
// Contenuto : Funzioni di verifica collisioni tra oggetti e solidi.
|
|
// Oggetti = Box, Sfere, Cilindri
|
|
// Solidi = SurfTriMesh, VolZMap
|
|
//
|
|
// Modifiche : 09.01.20 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LUA.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkLuaAux.h"
|
|
#include "/EgtDev/Include/EgnStringUtils.h"
|
|
|
|
using namespace std ;
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCDeBoxSolid( lua_State* L)
|
|
{
|
|
// 4 o 5 parametri : frBox, vtDiag, nSolidId, dSafeDist [, nRefType]
|
|
Frame3d frBox ;
|
|
LuaCheckParam( L, 1, frBox)
|
|
Vector3d vtDiag ;
|
|
LuaCheckParam( L, 2, vtDiag)
|
|
int nSolidId ;
|
|
LuaCheckParam( L, 3, nSolidId)
|
|
double dSafeDist ;
|
|
LuaCheckParam( L, 4, dSafeDist)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 5, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo verifica di collisione
|
|
int nRes = ExeCDeBoxSolid( frBox, vtDiag, nSolidId, dSafeDist, nRefType) ;
|
|
// restituisco il risultato
|
|
if ( nRes >= 0)
|
|
LuaSetParam( L, ( nRes != 0)) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCDeRectPrismoidSolid( lua_State* L)
|
|
{
|
|
// 8 o 9 parametri : frBox, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSolidId, dSafeDist [, nRefType]
|
|
Frame3d frBox ;
|
|
LuaCheckParam( L, 1, frBox)
|
|
double dBaseLenX ;
|
|
LuaCheckParam( L, 2, dBaseLenX)
|
|
double dBaseLenY ;
|
|
LuaCheckParam( L, 3, dBaseLenY)
|
|
double dTopLenX ;
|
|
LuaCheckParam( L, 4, dTopLenX)
|
|
double dTopLenY ;
|
|
LuaCheckParam( L, 5, dTopLenY)
|
|
double dHeight ;
|
|
LuaCheckParam( L, 6, dHeight)
|
|
int nSolidId ;
|
|
LuaCheckParam( L, 7, nSolidId)
|
|
double dSafeDist ;
|
|
LuaCheckParam( L, 8, dSafeDist)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 9, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo verifica di collisione
|
|
int nRes = ExeCDeRectPrismoidSolid( frBox, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSolidId, dSafeDist, nRefType) ;
|
|
// restituisco il risultato
|
|
if ( nRes >= 0)
|
|
LuaSetParam( L, ( nRes != 0)) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCDeCylSolid( lua_State* L)
|
|
{
|
|
// 5 o 6 parametri : frCyl, dR, dH, nSolidId, dSafeDist [, nRefType]
|
|
Frame3d frCyl ;
|
|
LuaCheckParam( L, 1, frCyl)
|
|
double dR ;
|
|
LuaCheckParam( L, 2, dR)
|
|
double dH ;
|
|
LuaCheckParam( L, 3, dH)
|
|
int nSolidId ;
|
|
LuaCheckParam( L, 4, nSolidId)
|
|
double dSafeDist ;
|
|
LuaCheckParam( L, 5, dSafeDist)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 6, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo verifica di collisione
|
|
int nRes = ExeCDeCylSolid( frCyl, dR, dH, nSolidId, dSafeDist, nRefType) ;
|
|
// restituisco il risultato
|
|
if ( nRes >= 0)
|
|
LuaSetParam( L, ( nRes != 0)) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
static int
|
|
LuaCDeConeSolid( lua_State* L)
|
|
{
|
|
// 6 o 7 parametri : frCone, dR1, dR2, dH, nSolidId, dSafeDist [, nRefType]
|
|
Frame3d frCone ;
|
|
LuaCheckParam( L, 1, frCone)
|
|
double dR1 ;
|
|
LuaCheckParam( L, 2, dR1)
|
|
double dR2 ;
|
|
LuaCheckParam( L, 3, dR2)
|
|
double dH ;
|
|
LuaCheckParam( L, 4, dH)
|
|
int nSolidId ;
|
|
LuaCheckParam( L, 5, nSolidId)
|
|
double dSafeDist ;
|
|
LuaCheckParam( L, 6, dSafeDist)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 7, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo verifica di collisione
|
|
int nRes = ExeCDeConeSolid( frCone, dR1, dR2, dH, nSolidId, dSafeDist, nRefType) ;
|
|
// restituisco il risultato
|
|
if ( nRes >= 0)
|
|
LuaSetParam( L, ( nRes != 0)) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int
|
|
LuaCDeSpheSolid( lua_State* L)
|
|
{
|
|
// 4 o 5 parametri : ptCen, dRad, nSolidId, dSafeDist [, nRefType]
|
|
Point3d ptCen ;
|
|
LuaCheckParam( L, 1, ptCen)
|
|
double dR ;
|
|
LuaCheckParam( L, 2, dR)
|
|
int nSolidId ;
|
|
LuaCheckParam( L, 3, nSolidId)
|
|
double dSafeDist ;
|
|
LuaCheckParam( L, 4, dSafeDist)
|
|
int nRefType = RTY_DEFAULT ;
|
|
LuaGetParam( L, 5, nRefType) ;
|
|
LuaClearStack( L) ;
|
|
// eseguo verifica di collisione
|
|
int nRes = ExeCDeSpheSolid( ptCen, dR, nSolidId, dSafeDist, nRefType) ;
|
|
// restituisco il risultato
|
|
if ( nRes >= 0)
|
|
LuaSetParam( L, ( nRes != 0)) ;
|
|
else
|
|
LuaSetParam( L) ;
|
|
return 1 ;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------
|
|
bool
|
|
LuaInstallCDeObjSolid( LuaMgr& luaMgr)
|
|
{
|
|
bool bOk = ( &luaMgr != nullptr) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCDeBoxSolid", LuaCDeBoxSolid) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCDeRectPrismoidSolid", LuaCDeRectPrismoidSolid) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCDeCylSolid", LuaCDeCylSolid) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCDeConeSolid", LuaCDeConeSolid) ;
|
|
bOk = bOk && luaMgr.RegisterFunction( "EgtCDeSpheSolid", LuaCDeSpheSolid) ;
|
|
return bOk ;
|
|
}
|