From f1f23a3cf451ace91fa38968b2aeeec1570d17ed Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 25 Mar 2024 09:05:21 +0100 Subject: [PATCH] EgtExecutor : - aggiunte funzioni Exe e Lua TestBoxSurface, TestRectPrismoidSurface, TestCylSurface, TestConeSurface, TestSpheSurface, TestSurfaceSurface. --- EXE_CDeObjSolid.cpp | 4 +- EXE_TestObjSurface.cpp | 316 ++++++++++++++++++++++++++++++++++++ EgtExecutor.vcxproj | 2 + EgtExecutor.vcxproj.filters | 6 + LUA.h | 7 +- LUA_Base.cpp | 4 + LUA_TestObjSurface.cpp | 202 +++++++++++++++++++++++ 7 files changed, 537 insertions(+), 4 deletions(-) create mode 100644 EXE_TestObjSurface.cpp create mode 100644 LUA_TestObjSurface.cpp diff --git a/EXE_CDeObjSolid.cpp b/EXE_CDeObjSolid.cpp index c628a32..2b22b72 100644 --- a/EXE_CDeObjSolid.cpp +++ b/EXE_CDeObjSolid.cpp @@ -1,9 +1,9 @@ //---------------------------------------------------------------------------- // EgalTech 2020-2020 //---------------------------------------------------------------------------- -// File : EXE_CDeObjClosedSurfTm.cpp Data : 09.01.20 Versione : 2.2a2 +// File : EXE_CDeObjSolid.cpp Data : 09.01.20 Versione : 2.2a2 // Contenuto : Funzioni per verificare collisioni tra -// Objects e Closed SurftriMesh. +// Objects e Solidi (Closed SurftriMesh e Zmap). // // // Modifiche : 09.01.20 DS Creazione modulo. diff --git a/EXE_TestObjSurface.cpp b/EXE_TestObjSurface.cpp new file mode 100644 index 0000000..6389c34 --- /dev/null +++ b/EXE_TestObjSurface.cpp @@ -0,0 +1,316 @@ +//---------------------------------------------------------------------------- +// EgalTech 2024-2024 +//---------------------------------------------------------------------------- +// File : EXE_TestObjSurface.cpp Data : 24.03.24 Versione : 2.6c2 +// Contenuto : Funzioni per verificare collisioni tra +// Objects e Superfici (TriMesh). +// +// +// Modifiche : 09.01.20 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "EXE_Const.h" +#include "AuxTools.h" +#include "GeoTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkCDeBoxClosedSurfTm.h" +#include "/EgtDev/Include/EGkCDeRectPrismoidClosedSurfTm.h" +#include "/EgtDev/Include/EGkCDeCylClosedSurfTm.h" +#include "/EgtDev/Include/EGkCDeConeFrustumClosedSurfTm.h" +#include "/EgtDev/Include/EGkCDeSpheClosedSurfTm.h" +#include "/EgtDev/Include/EGkCDeClosedSurfTmClosedSurfTm.h" +#include "/EgtDev/Include/EGkSurfLocal.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +static int +MyTestBoxSurfTm( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfTmId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il riferimento della superficie + Frame3d frSurf ; + if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) + return -1 ; + // porto in locale alla superficie il riferimento del box (il vettore è già in questo stesso riferimento) + Frame3d frBoxL = GetFrameLocal( pGeomDB, frBox, nRefType, frSurf) ; + // verifico l'a collisione'interferenza + return ( TestBoxSurfTm( frBoxL, vtDiag, *pStm, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestBoxSurface( const Frame3d& frBox, const Vector3d& vtDiag, int nSurfId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) + nRes = MyTestBoxSurfTm( frBox, vtDiag, nSurfId, dSafeDist, nRefType) ; + // è da aggiungere il test con le superfici di Bezier + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestBoxSurface({{" + ToString( frBox.Orig()) + "},{" + + ToString( frBox.VersX()) + "},{" + + ToString( frBox.VersY()) + "},{" + + ToString( frBox.VersZ()) + "}},{" + + ToString( vtDiag) + "}," + + IdToString( nSurfId) + "," + + ToString( dSafeDist) + "," + + RefTypeToString( nRefType) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} + +//---------------------------------------------------------------------------- +static int +MyTestRectPrismoidSurfTm( const Frame3d& frPrismoid, double dBaseLenX, double dBaseLenY, + double dTopLenX, double dTopLenY, double dHeight, + int nSurfTmId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il riferimento della superficie + Frame3d frSurf ; + if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) + return -1 ; + // porto in locale alla superficie il riferimento del prismoide rettangolare + Frame3d frPrismoidL = GetFrameLocal( pGeomDB, frPrismoid, nRefType, frSurf) ; + // verifico l'a collisione'interferenza + return ( TestRectPrismoidSurfTm( frPrismoidL, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, *pStm, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestRectPrismoidSurface( const Frame3d& frPrismoid, double dBaseLenX, double dBaseLenY, + double dTopLenX, double dTopLenY, double dHeight, + int nSurfId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) + nRes = MyTestRectPrismoidSurfTm( frPrismoid, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSurfId, dSafeDist, nRefType) ; + // è da aggiungere il test con le superfici di Bezier + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestRectPrismoidSurface({{" + ToString( frPrismoid.Orig()) + "},{" + + ToString( frPrismoid.VersX()) + "},{" + + ToString( frPrismoid.VersY()) + "},{" + + ToString( frPrismoid.VersZ()) + "}}," + + ToString( dBaseLenX) + "," + + ToString( dBaseLenY) + "," + + ToString( dTopLenX) + "," + + ToString( dTopLenY) + "," + + ToString( dHeight) + "," + + IdToString( nSurfId) + "," + + ToString( dSafeDist) + "," + + RefTypeToString( nRefType) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} + +//---------------------------------------------------------------------------- +static int +MyTestCylSurfTm( const Frame3d& frCyl, double dR, double dH, int nSurfTmId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il riferimento della superficie + Frame3d frSurf ; + if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) + return -1 ; + // porto in locale alla superficie il riferimento del cilindro + Frame3d frCylL = GetFrameLocal( pGeomDB, frCyl, nRefType, frSurf) ; + // verifico l'interferenza + return ( TestCylSurfTm( frCylL, dR, dH, *pStm, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestCylSurface( const Frame3d& frCyl, double dR, double dH, int nSurfId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) + nRes = MyTestCylSurfTm( frCyl, dR, dH, nSurfId, dSafeDist, nRefType) ; + // è da aggiungere il test con le superfici di Bezier + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestCylSurface({{" + ToString( frCyl.Orig()) + "},{" + + ToString( frCyl.VersX()) + "},{" + + ToString( frCyl.VersY()) + "},{" + + ToString( frCyl.VersZ()) + "}}," + + ToString( dR) + "," + + ToString( dH) + "," + + IdToString( nSurfId) + "," + + ToString( dSafeDist) + "," + + RefTypeToString( nRefType) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} + +//---------------------------------------------------------------------------- +static int +MyTestConeSurfTm( const Frame3d& frCone, double dR1, double dR2, double dH, int nSurfTmId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il riferimento della superficie + Frame3d frSurf ; + if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) + return -1 ; + // porto in locale alla superficie il riferimento del cilindro + Frame3d frConeL = GetFrameLocal( pGeomDB, frCone, nRefType, frSurf) ; + // verifico l'interferenza + return ( TestConeFrustumSurfTm( frConeL, dR1, dR2, dH, *pStm, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestConeSurface( const Frame3d& frCone, double dR1, double dR2, double dH, int nSurfId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) + nRes = MyTestConeSurfTm( frCone, dR1, dR2, dH, nSurfId, dSafeDist, nRefType) ; + // è da aggiungere il test con le superfici di Bezier + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestConeSurface({{" + ToString( frCone.Orig()) + "},{" + + ToString( frCone.VersX()) + "},{" + + ToString( frCone.VersY()) + "},{" + + ToString( frCone.VersZ()) + "}}," + + ToString( dR1) + "," + + ToString( dR2) + "," + + ToString( dH) + "," + + IdToString( nSurfId) + "," + + ToString( dSafeDist) + "," + + RefTypeToString( nRefType) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} + +//---------------------------------------------------------------------------- +static int +MyTestSpheSurfTm( const Point3d& ptCen, double dR, int nSurfTmId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ; + if ( pStm == nullptr) + return -1 ; + // recupero il riferimento della superficie + Frame3d frSurf ; + if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf)) + return -1 ; + // porto in locale alla superficie il centro della sfera + Point3d ptCenL = GetPointLocal( pGeomDB, ptCen, nRefType, frSurf) ; + // verifico l'a collisione'interferenza + return ( TestSpheSurfTm( ptCenL, dR, *pStm, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestSpheSurface( const Point3d& ptCen, double dR, int nSurfId, double dSafeDist, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr && pGeomDB->GetGeoType( nSurfId) == SRF_TRIMESH) + nRes = MyTestSpheSurfTm( ptCen, dR, nSurfId, dSafeDist, nRefType) ; + // è da aggiungere il test con le superfici di Bezier + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestSpheSurface({" + ToString( ptCen) + "}," + + ToString( dR) + "," + + IdToString( nSurfId) + "," + + ToString( dSafeDist) + "," + + RefTypeToString( nRefType) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} + +//---------------------------------------------------------------------------- +static int +MyTestSurfTmSurfTm( int nSurfTm1Id, int nSurfTm2Id, double dSafeDist) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, -1) + // recupero il riferimento della seconda superficie + Frame3d frSurf2 ; + if ( ! pGeomDB->GetGlobFrame( nSurfTm2Id, frSurf2)) + return -1 ; + // recupero la prima superficie in locale alla seconda + SurfLocal Surf1Loc( pGeomDB, nSurfTm1Id, frSurf2) ; + const ISurfTriMesh* pStm1 = GetSurfTriMesh( Surf1Loc) ; + if ( pStm1 == nullptr) + return -1 ; + // recupero la seconda superficie TriMesh + const ISurfTriMesh* pStm2 = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTm2Id)) ; + if ( pStm2 == nullptr) + return -1 ; + // verifico l'a collisione'interferenza + return ( TestSurfTmSurfTm( *pStm1, *pStm2, dSafeDist) ? 1 : 0) ; +} + +//---------------------------------------------------------------------------- +int +ExeTestSurfaceSurface( int nSurf1Id, int nSurf2Id, double dSafeDist) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + int nRes = -1 ; + if ( pGeomDB != nullptr) { + if ( pGeomDB->GetGeoType( nSurf1Id) == SRF_TRIMESH && pGeomDB->GetGeoType( nSurf2Id) == SRF_TRIMESH) + nRes = MyTestSurfTmSurfTm( nSurf1Id, nSurf2Id, dSafeDist) ; + // è da aggiungere il test con le superfici di Bezier + } + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtTestSurfaceSurface({" + IdToString( nSurf1Id) + "," + + IdToString( nSurf2Id) + "," + + ToString( dSafeDist) + ")" + + " -- Res=" + ToString( nRes) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nRes ; +} diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj index 682091e..95b8fc3 100644 --- a/EgtExecutor.vcxproj +++ b/EgtExecutor.vcxproj @@ -293,6 +293,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -316,6 +317,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters index aa188a7..f467eb3 100644 --- a/EgtExecutor.vcxproj.filters +++ b/EgtExecutor.vcxproj.filters @@ -401,6 +401,12 @@ File di origine\LUA + + File di origine\EXE + + + File di origine\LUA + diff --git a/LUA.h b/LUA.h index 9088f1f..a96f600 100644 --- a/LUA.h +++ b/LUA.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2014-2015 +// EgalTech 2014-2024 //---------------------------------------------------------------------------- -// File : LUA.h Data : 16.01.15 Versione : 1.6a3 +// File : LUA.h Data : 24.03.24 Versione : 2.6c2 // Contenuto : Dichiarazioni locali per moduli LUA. // // @@ -93,6 +93,9 @@ bool LuaInstallGeoInters( LuaMgr& luaMgr) ; //-------------------------- Collision Detection ----------------------------- bool LuaInstallCDeObjSolid( LuaMgr& luaMgr) ; +//-------------------------- Test Interference ------------------------------- +bool LuaInstallTestObjSurface( LuaMgr& luaMgr) ; + //-------------------------- MachMgr ----------------------------------------- bool LuaInstallMachMgr( LuaMgr& luaMgr) ; diff --git a/LUA_Base.cpp b/LUA_Base.cpp index 6846ca4..53472f2 100644 --- a/LUA_Base.cpp +++ b/LUA_Base.cpp @@ -130,6 +130,10 @@ LuaInstallEgtFunctions( LuaMgr& LuaMgr) LOG_ERROR( GetLogger(), "Error in LuaInstallCDeObjSolid (LuaInstallEgtFunctions)") return false ; } + if ( ! LuaInstallTestObjSurface( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallTestObjSurface (LuaInstallEgtFunctions)") + return false ; + } if ( ! LuaInstallMachMgr( LuaMgr)) { LOG_ERROR( GetLogger(), "Error in LuaInstallMachMgr (LuaInstallEgtFunctions)") return false ; diff --git a/LUA_TestObjSurface.cpp b/LUA_TestObjSurface.cpp new file mode 100644 index 0000000..d8b8148 --- /dev/null +++ b/LUA_TestObjSurface.cpp @@ -0,0 +1,202 @@ +//---------------------------------------------------------------------------- +// EgalTech 2024-2024 +//---------------------------------------------------------------------------- +// File : LUA_TestObjSurface.cpp Data : 24.03.24 Versione : 2.6c2 +// Contenuto : Funzioni di verifica intersezione tra oggetti e superfici. +// Oggetti = Box, Sfere, Cilindri, Coni, RectPrismoid, SurfTriMesh +// Superfici = SurfTriMesh, ( Bezier). +// +// Modifiche : 24.03.24 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 +LuaTestBoxSurface( lua_State* L) +{ + // 4 o 5 parametri : frBox, vtDiag, nSurfId, dSafeDist [, nRefType] + Frame3d frBox ; + LuaCheckParam( L, 1, frBox) + Vector3d vtDiag ; + LuaCheckParam( L, 2, vtDiag) + int nSurfId ; + LuaCheckParam( L, 3, nSurfId) + double dSafeDist ; + LuaCheckParam( L, 4, dSafeDist) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // eseguo verifica di collisione + int nRes = ExeTestBoxSurface( frBox, vtDiag, nSurfId, dSafeDist, nRefType) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTestRectPrismoidSurface( lua_State* L) +{ + // 8 o 9 parametri : frBox, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSurfId, 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 nSurfId ; + LuaCheckParam( L, 7, nSurfId) + double dSafeDist ; + LuaCheckParam( L, 8, dSafeDist) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 9, nRefType) ; + LuaClearStack( L) ; + // eseguo verifica di collisione + int nRes = ExeTestRectPrismoidSurface( frBox, dBaseLenX, dBaseLenY, dTopLenX, dTopLenY, dHeight, nSurfId, dSafeDist, nRefType) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTestCylSurface( lua_State* L) +{ + // 5 o 6 parametri : frCyl, dR, dH, nSurfId, dSafeDist [, nRefType] + Frame3d frCyl ; + LuaCheckParam( L, 1, frCyl) + double dR ; + LuaCheckParam( L, 2, dR) + double dH ; + LuaCheckParam( L, 3, dH) + int nSurfId ; + LuaCheckParam( L, 4, nSurfId) + double dSafeDist ; + LuaCheckParam( L, 5, dSafeDist) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // eseguo verifica di collisione + int nRes = ExeTestCylSurface( frCyl, dR, dH, nSurfId, dSafeDist, nRefType) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaTestConeSurface( lua_State* L) +{ + // 6 o 7 parametri : frCone, dR1, dR2, dH, nSurfId, 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 nSurfId ; + LuaCheckParam( L, 5, nSurfId) + double dSafeDist ; + LuaCheckParam( L, 6, dSafeDist) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 7, nRefType) ; + LuaClearStack( L) ; + // eseguo verifica di collisione + int nRes = ExeTestConeSurface( frCone, dR1, dR2, dH, nSurfId, dSafeDist, nRefType) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTestSpheSurface( lua_State* L) +{ + // 4 o 5 parametri : ptCen, dRad, nSurfId, dSafeDist [, nRefType] + Point3d ptCen ; + LuaCheckParam( L, 1, ptCen) + double dR ; + LuaCheckParam( L, 2, dR) + int nSurfId ; + LuaCheckParam( L, 3, nSurfId) + double dSafeDist ; + LuaCheckParam( L, 4, dSafeDist) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 5, nRefType) ; + LuaClearStack( L) ; + // eseguo verifica di collisione + int nRes = ExeTestSpheSurface( ptCen, dR, nSurfId, dSafeDist, nRefType) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +static int +LuaTestSurfaceSurface( lua_State* L) +{ + // 3 parametri : nSurf1Id, nSurf2Id, dSafeDist + int nSurf1Id ; + LuaCheckParam( L, 1, nSurf1Id) + int nSurf2Id ; + LuaCheckParam( L, 2, nSurf2Id) + double dSafeDist ; + LuaCheckParam( L, 3, dSafeDist) + LuaClearStack( L) ; + // eseguo verifica di interferenza + int nRes = ExeTestSurfaceSurface( nSurf1Id, nSurf2Id, dSafeDist) ; + // restituisco il risultato + if ( nRes >= 0) + LuaSetParam( L, ( nRes != 0)) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallTestObjSurface( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestBoxSurface", LuaTestBoxSurface) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestRectPrismoidSurface", LuaTestRectPrismoidSurface) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestCylSurface", LuaTestCylSurface) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestConeSurface", LuaTestConeSurface) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestSpheSurface", LuaTestSpheSurface) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtTestSurfaceSurface", LuaTestSurfaceSurface) ; + return bOk ; +}