-
-
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.
#80 Add BBox builder for dynamic transform object collision
- Loading branch information
1 parent
71bf04a
commit bc06879
Showing
9 changed files
with
282 additions
and
112 deletions.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.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,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 | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "CBBoxPatchBuilder.h" | ||
|
||
namespace Skylicht | ||
{ | ||
CBBoxPatchBuilder::CBBoxPatchBuilder() | ||
{ | ||
|
||
} | ||
|
||
CBBoxPatchBuilder::~CBBoxPatchBuilder() | ||
{ | ||
clear(); | ||
} | ||
|
||
void CBBoxPatchBuilder::clear() | ||
{ | ||
CCollisionBuilder::clear(); | ||
} | ||
|
||
void CBBoxPatchBuilder::build() | ||
{ | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.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,42 @@ | ||
/* | ||
!@ | ||
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 "CCollisionBuilder.h" | ||
|
||
namespace Skylicht | ||
{ | ||
class CBBoxPatchBuilder : public CCollisionBuilder | ||
{ | ||
public: | ||
CBBoxPatchBuilder(); | ||
|
||
virtual ~CBBoxPatchBuilder(); | ||
|
||
virtual void clear(); | ||
|
||
virtual void build(); | ||
}; | ||
} |
123 changes: 123 additions & 0 deletions
123
Projects/Skylicht/Collision/Source/Collision/CCollisionBuilder.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,123 @@ | ||
/* | ||
!@ | ||
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 "CCollisionBuilder.h" | ||
|
||
#include "GameObject/CGameObject.h" | ||
|
||
namespace Skylicht | ||
{ | ||
CCollisionBuilder::CCollisionBuilder() | ||
{ | ||
|
||
} | ||
|
||
CCollisionBuilder::~CCollisionBuilder() | ||
{ | ||
|
||
} | ||
|
||
void CCollisionBuilder::removeCollision(CGameObject* object) | ||
{ | ||
for (u32 i = 0, n = m_nodes.size(); i < n; i++) | ||
{ | ||
if (m_nodes[i]->GameObject == object) | ||
{ | ||
if (n >= 2) | ||
{ | ||
// swap to last and delete | ||
CCollisionNode* t = m_nodes[n - 1]; | ||
m_nodes[n - 1] = m_nodes[i]; | ||
m_nodes[i] = t; | ||
delete m_nodes[n - 1]; | ||
m_nodes.erase(n - 1); | ||
return; | ||
} | ||
else | ||
{ | ||
delete m_nodes[i]; | ||
m_nodes.erase(i); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
build(); | ||
} | ||
|
||
void CCollisionBuilder::removeCollision(CCollisionNode** nodes, int count) | ||
{ | ||
for (u32 i = 0, n = m_nodes.size(); i < n; i++) | ||
{ | ||
int id = findNode(m_nodes[i], nodes, count); | ||
if (id >= 0) | ||
{ | ||
nodes[id] = NULL; | ||
|
||
if (n >= 2) | ||
{ | ||
// swap to last and delete | ||
CCollisionNode* t = m_nodes[n - 1]; | ||
m_nodes[n - 1] = m_nodes[i]; | ||
m_nodes[i] = t; | ||
delete m_nodes[n - 1]; | ||
m_nodes.erase(n - 1); | ||
return; | ||
} | ||
else | ||
{ | ||
delete m_nodes[i]; | ||
m_nodes.erase(i); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
build(); | ||
} | ||
|
||
void CCollisionBuilder::clear() | ||
{ | ||
for (u32 i = 0, n = m_nodes.size(); i < n; i++) | ||
{ | ||
delete m_nodes[i]->Selector; | ||
delete m_nodes[i]; | ||
} | ||
m_nodes.clear(); | ||
} | ||
|
||
int CCollisionBuilder::findNode(CCollisionNode* node, CCollisionNode** nodes, int count) | ||
{ | ||
for (int i = 0; i < count; i++) | ||
{ | ||
if (nodes[i] == node) | ||
{ | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Projects/Skylicht/Collision/Source/Collision/CCollisionBuilder.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,51 @@ | ||
/* | ||
!@ | ||
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 "COctreeNode.h" | ||
|
||
namespace Skylicht | ||
{ | ||
class CCollisionBuilder | ||
{ | ||
protected: | ||
core::array<CCollisionNode*> m_nodes; | ||
|
||
public: | ||
CCollisionBuilder(); | ||
|
||
virtual ~CCollisionBuilder(); | ||
|
||
void removeCollision(CGameObject* object); | ||
|
||
void removeCollision(CCollisionNode** nodes, int count); | ||
|
||
virtual void clear(); | ||
|
||
int findNode(CCollisionNode* node, CCollisionNode** nodes, int count); | ||
|
||
virtual void build() = 0; | ||
}; | ||
} |
Oops, something went wrong.