diff --git a/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.cpp b/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.cpp new file mode 100644 index 000000000..cda868bfa --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.cpp @@ -0,0 +1,73 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CBBCollisionManager.h" +#include "CTriangleBB.h" + +namespace Skylicht +{ + CBBCollisionManager::CBBCollisionManager() + { + + } + + CBBCollisionManager::~CBBCollisionManager() + { + for (u32 i = 0, n = m_selector.size(); i < n; i++) + delete m_selector[i]; + m_selector.clear(); + } + + void CBBCollisionManager::addBBCollision(CGameObject* object, const core::aabbox3df& bbox) + { + m_selector.push_back(new CTriangleBB(object, bbox)); + } + + void CBBCollisionManager::removeBBCollision(CGameObject* object) + { + for (u32 i = 0, n = m_selector.size(); i < n; i++) + { + if (m_selector[i]->getGameObject() == object) + { + if (n >= 2) + { + // swap to last and delete + CTriangleSelector* t = m_selector[n - 1]; + m_selector[n - 1] = m_selector[i]; + m_selector[i] = t; + delete m_selector[n - 1]; + m_selector.erase(n - 1); + return; + } + else + { + delete m_selector[i]; + m_selector.erase(i); + return; + } + } + } + } +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.h b/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.h new file mode 100644 index 000000000..affd9dcec --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.h @@ -0,0 +1,47 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "CTriangleSelector.h" +#include "GameObject/CGameObject.h" +#include "Utils/CGameSingleton.h" + +namespace Skylicht +{ + class CBBCollisionManager + { + protected: + core::array m_selector; + + public: + CBBCollisionManager(); + + virtual ~CBBCollisionManager(); + + void addBBCollision(CGameObject* object, const core::aabbox3df& bbox); + + void removeBBCollision(CGameObject* object); + }; +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.cpp b/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.cpp new file mode 100644 index 000000000..8fd06b1cf --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.cpp @@ -0,0 +1,67 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CTriangleBB.h" + +namespace Skylicht +{ + CTriangleBB::CTriangleBB(CGameObject* gameObject, const core::aabbox3df& bbox) : + CTriangleSelector(gameObject), + m_bbox(bbox) + { + m_triangles.set_used(12); + } + + CTriangleBB::~CTriangleBB() + { + + } + + void CTriangleBB::getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount, const core::matrix4* transform) + { + core::vector3df edges[8]; + m_bbox.getEdges(edges); + + m_triangles[0].set(edges[3], edges[0], edges[2]); + m_triangles[1].set(edges[3], edges[1], edges[0]); + + m_triangles[2].set(edges[3], edges[2], edges[7]); + m_triangles[3].set(edges[7], edges[2], edges[6]); + + m_triangles[4].set(edges[7], edges[6], edges[4]); + m_triangles[5].set(edges[5], edges[7], edges[4]); + + m_triangles[6].set(edges[5], edges[4], edges[0]); + m_triangles[7].set(edges[5], edges[0], edges[1]); + + m_triangles[8].set(edges[1], edges[3], edges[7]); + m_triangles[9].set(edges[1], edges[7], edges[5]); + + m_triangles[10].set(edges[0], edges[6], edges[2]); + m_triangles[11].set(edges[0], edges[4], edges[6]); + + CTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount, transform); + } +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.h b/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.h new file mode 100644 index 000000000..d2c770ef9 --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CTriangleBB.h @@ -0,0 +1,43 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "CTriangleSelector.h" + +namespace Skylicht +{ + class CTriangleBB : public CTriangleSelector + { + protected: + core::aabbox3df m_bbox; + + public: + CTriangleBB(CGameObject* gameObject, const core::aabbox3df& bbox); + + virtual ~CTriangleBB(); + + virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount, const core::matrix4* transform); + }; +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp new file mode 100644 index 000000000..5d0f072ff --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp @@ -0,0 +1,60 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CTriangleSelector.h" + +namespace Skylicht +{ + CTriangleSelector::CTriangleSelector(CGameObject* gameObject) : + m_gameObject(gameObject) + { + + } + + CTriangleSelector::~CTriangleSelector() + { + + } + + void CTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount, const core::matrix4* transform) + { + u32 cnt = m_triangles.size(); + if (cnt > (u32)arraySize) + cnt = (u32)arraySize; + + core::matrix4 mat; + if (transform) + mat = *transform; + + for (u32 i = 0; i < cnt; ++i) + { + mat.transformVect(triangles[i].pointA, m_triangles[i].pointA); + mat.transformVect(triangles[i].pointB, m_triangles[i].pointB); + mat.transformVect(triangles[i].pointC, m_triangles[i].pointC); + } + + outTriangleCount = cnt; + } +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.h b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.h new file mode 100644 index 000000000..30a860645 --- /dev/null +++ b/Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.h @@ -0,0 +1,49 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "GameObject/CGameObject.h" + +namespace Skylicht +{ + class CTriangleSelector + { + protected: + core::array m_triangles; + CGameObject* m_gameObject; + + public: + CTriangleSelector(CGameObject* gameObject); + + virtual ~CTriangleSelector(); + + virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount, const core::matrix4* transform); + + inline CGameObject* getGameObject() + { + return m_gameObject; + } + }; +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/pch.h b/Projects/Skylicht/Collision/Source/pch.h index 5932e21f5..f25e52de5 100644 --- a/Projects/Skylicht/Collision/Source/pch.h +++ b/Projects/Skylicht/Collision/Source/pch.h @@ -49,10 +49,6 @@ using namespace irr; using namespace irr::scene; using namespace irr::video; -// SPARK ENGINE -// #include "SPK.h" -// #include "SPK_IRR.h" - // STL C++ #include diff --git a/Projects/Skylicht/Components/Source/pch.h b/Projects/Skylicht/Components/Source/pch.h index 5932e21f5..f25e52de5 100644 --- a/Projects/Skylicht/Components/Source/pch.h +++ b/Projects/Skylicht/Components/Source/pch.h @@ -49,10 +49,6 @@ using namespace irr; using namespace irr::scene; using namespace irr::video; -// SPARK ENGINE -// #include "SPK.h" -// #include "SPK_IRR.h" - // STL C++ #include diff --git a/Projects/Skylicht/Physics/Source/pch.h b/Projects/Skylicht/Physics/Source/pch.h index 5932e21f5..f25e52de5 100644 --- a/Projects/Skylicht/Physics/Source/pch.h +++ b/Projects/Skylicht/Physics/Source/pch.h @@ -49,10 +49,6 @@ using namespace irr; using namespace irr::scene; using namespace irr::video; -// SPARK ENGINE -// #include "SPK.h" -// #include "SPK_IRR.h" - // STL C++ #include