-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd2be2b
commit 30cad5a
Showing
9 changed files
with
339 additions
and
12 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Projects/Skylicht/Collision/Source/Collision/CBBCollisionManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CTriangleSelector*> m_selector; | ||
|
||
public: | ||
CBBCollisionManager(); | ||
|
||
virtual ~CBBCollisionManager(); | ||
|
||
void addBBCollision(CGameObject* object, const core::aabbox3df& bbox); | ||
|
||
void removeBBCollision(CGameObject* object); | ||
}; | ||
} |
67 changes: 67 additions & 0 deletions
67
Projects/Skylicht/Collision/Source/Collision/CTriangleBB.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Projects/Skylicht/Collision/Source/Collision/CTriangleBB.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
} |
60 changes: 60 additions & 0 deletions
60
Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Projects/Skylicht/Collision/Source/Collision/CTriangleSelector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<core::triangle3df> 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; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters