[add] 리지드 바디 상속구조로 변경

This commit is contained in:
kimnuri
2025-11-14 21:28:17 +09:00
parent 1589fae77b
commit ccfe282df1
17 changed files with 419 additions and 295 deletions
@@ -86,7 +86,7 @@ HRESULT CDummy_PhysXBox::Ready_Components(void* pArg)
{ // RIGID_BODY
CRigidBody::RIGIDBODY_DESC Desc{};
CRigidBody_Dynamic::RIGIDBODY_DYNAMIC_DESC Desc{};
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("PHYSX_DYNAMIC_BOX"), (CComponent**)&m_pRigidBody, &Desc))) {
return E_FAIL;
@@ -95,8 +95,9 @@ HRESULT CDummy_PhysXBox::Ready_Components(void* pArg)
/* Com_Shader */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_MESH,
reinterpret_cast<CComponent**>(&m_pShaderCom))))
reinterpret_cast<CComponent**>(&m_pShaderCom)))){
return E_FAIL;
}
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_Box"), (CComponent**)&m_pModelCom))) {
return E_FAIL;
+6 -6
View File
@@ -521,7 +521,7 @@ HRESULT CLoader::Loading_For_PhysXLevel()
m_strMessage = TEXT("PhysX Bodies Loading..");
{
CRigidBody::RIGIDBODY_PROTOTYPEDESC Desc{};
CRigidBody_Dynamic::RIGIDBODY_PROTOTYPE_DYNAMIC_DESC Desc{};
{
Desc.eType = ACTOR::BOX;
Desc.ePxRigidBodyFlags = {};
@@ -532,7 +532,7 @@ HRESULT CLoader::Loading_For_PhysXLevel()
Desc.vhalfGeometryInfo = { 1.f, 1.f, 1.f };
Desc.fDensity = 10.f;
}
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("PHYSX_DYNAMIC_BOX"), CRigidBody::Create(m_pDevice, m_pContext, Desc)))) {
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, TEXT("PHYSX_DYNAMIC_BOX"), CRigidBody_Dynamic::Create(m_pDevice, m_pContext, Desc)))) {
return E_FAIL;
}
}
@@ -596,7 +596,7 @@ HRESULT CLoader::Loading_For_PhysXLevel()
_uint iNumMesh = pModel->Get_NumMeshes();
CRigidBody::RIGIDBODY_PROTOTYPEDESC Desc{};
CRigidBody_Static::RIGIDBODY_STATIC_PROTOTYPEDESC Desc{};
for (_uint i = 0; i < iNumMesh; ++i) {
_string strDestName = pModel->Get_MeshName(i) + to_string(i);
{ // basic static RIGIDBODY
@@ -607,7 +607,7 @@ HRESULT CLoader::Loading_For_PhysXLevel()
Desc.vMatInfo = _float3(0.5f, 0.5f, 0.6f);
Desc.fContactOffset = 0.f;
}
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, CMyTools::ToWstring(strDestName).c_str(), CRigidBody::Create(m_pDevice, m_pContext, Desc)))) {
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, CMyTools::ToWstring(strDestName).c_str(), CRigidBody_Static::Create(m_pDevice, m_pContext, Desc)))) {
return E_FAIL;
}
}
@@ -872,7 +872,7 @@ HRESULT CLoader::Loading_For_MapViewer()
_uint iNumMesh = pModel->Get_NumMeshes();
CRigidBody::RIGIDBODY_PROTOTYPEDESC Desc{};
CRigidBody_Static::RIGIDBODY_STATIC_PROTOTYPEDESC Desc{};
for (_uint i = 0; i < iNumMesh; ++i) {
_string strDestName = pModel->Get_MeshName(i) + to_string(i);
{
@@ -883,7 +883,7 @@ HRESULT CLoader::Loading_For_MapViewer()
Desc.vMatInfo = _float3(0.5f, 0.5f, 0.6f);
Desc.fContactOffset = 0.f;
}
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, CMyTools::ToWstring(strDestName).c_str(), CRigidBody::Create(m_pDevice, m_pContext, Desc)))) {
if (FAILED(m_pGameInstance->Add_Asset_Prototype(g_iStaticLevel, CMyTools::ToWstring(strDestName).c_str(), CRigidBody_Static::Create(m_pDevice, m_pContext, Desc)))) {
return E_FAIL;
}
}
@@ -284,21 +284,21 @@ void CMapObject_LOD::Describe_Entity()
GUI::SameLine();
if (GUI::Button("Bake!!!")) {
CMapObject_Manager* pManager = m_pGameInstance->Get_Layer(CURRENT_LEVEL, LAYER_MAPOBJECTMANAGER)->Get_Object<CMapObject_Manager>();
for (_uint i = 0; i < (_uint)m_ModelPathIndices.size(); ++i) {
filesystem::path filePath = pManager->Get_PrototypePath(m_ModelPathIndices[i]);
for (_uint iModelIndex = 0; iModelIndex < (_uint)m_ModelPathIndices.size(); ++iModelIndex) {
filesystem::path filePath = pManager->Get_PrototypePath(m_ModelPathIndices[iModelIndex]);
CModel* pModel = m_pModelComs[i];
CModel* pModel = m_pModelComs[iModelIndex];
_uint iNumMesh = pModel->Get_NumMeshes();
pModel->Save_PhysXTriMeshes(filePath.string().c_str());
CRigidBody::RIGIDBODY_DESC Desc{};
CRigidBody_Static::RIGIDBODY_STATIC_DESC Desc{};
for (_uint i = 0; i < iNumMesh; ++i)
for (_uint iMeshIndex = 0; iMeshIndex < iNumMesh; ++iMeshIndex)
{ // RIGID_BODY
_string strDestName = pModel->Get_MeshName(i) + to_string(i);
Desc.szMeshName = strDestName.c_str();
_wstring dest = CMyTools::ToWstring(m_pModelComs[iModelIndex]->Get_MeshName(iMeshIndex) + to_string(iMeshIndex)).c_str();
Desc.pMeshName = dest.c_str();
if (FAILED(Add_Asset_Component(g_iStaticLevel, CMyTools::ToWstring(strDestName).c_str(), nullptr, &Desc))) {
if (FAILED(Add_Asset_Component(g_iStaticLevel, Desc.pMeshName, nullptr, &Desc))) {
assert(false);
}
}
@@ -309,4 +309,4 @@ void CMapObject_LOD::Describe_Entity()
}
m_bSelected = true;
}
}
@@ -253,12 +253,12 @@ void CMapObject_Static::Describe_Entity()
m_pModelCom->Save_PhysXTriMeshes(CMyTools::ToString(pManager->Get_PrototypePath(m_iModelPathIndex)).c_str());
_uint iNumMesh = m_pModelCom->Get_NumMeshes();
CRigidBody::RIGIDBODY_DESC Desc{};
CRigidBody_Static::RIGIDBODY_STATIC_DESC Desc{};
for (_uint i = 0; i < iNumMesh; ++i)
{ // RIGID_BODY
Desc.szMeshName = _string(m_pModelCom->Get_MeshName(i) + to_string(i)).c_str();
Desc.pMeshName = CMyTools::ToWstring(m_pModelCom->Get_MeshName(i) + to_string(i)).c_str();
if (FAILED(Add_Asset_Component(g_iStaticLevel, CMyTools::ToWstring(Desc.szMeshName).c_str(), nullptr, &Desc))) {
if (FAILED(Add_Asset_Component(g_iStaticLevel, Desc.pMeshName, nullptr, &Desc))) {
assert(false);
}
}
@@ -268,4 +268,4 @@ void CMapObject_Static::Describe_Entity()
}
m_bSelected = true;
}
}
@@ -287,6 +287,8 @@ call Update_Lib.bat
<ClCompile Include="..\Private\RenderTarget.cpp" />
<ClCompile Include="..\Private\RenderTarget_Manager.cpp" />
<ClCompile Include="..\Private\RigidBody.cpp" />
<ClCompile Include="..\Private\RigidBody_Dynamic.cpp" />
<ClCompile Include="..\Private\RigidBody_Static.cpp" />
<ClCompile Include="..\Private\Shader.cpp" />
<ClCompile Include="..\Private\Shadow.cpp" />
<ClCompile Include="..\Private\SoundSrc.cpp" />
@@ -503,6 +505,8 @@ call Update_Lib.bat
<ClInclude Include="..\Public\RenderTarget.h" />
<ClInclude Include="..\Public\RenderTarget_Manager.h" />
<ClInclude Include="..\Public\RigidBody.h" />
<ClInclude Include="..\Public\RigidBody_Dynamic.h" />
<ClInclude Include="..\Public\RigidBody_Static.h" />
<ClInclude Include="..\Public\Shader.h" />
<ClInclude Include="..\Public\Shadow.h" />
<ClInclude Include="..\Public\SoundSrc.h" />
@@ -250,9 +250,6 @@
<Filter Include="02.Element\02.Component\07.RigidBody\10.Dynamic">
<UniqueIdentifier>{bed0de44-4e62-4b5f-9767-65cfc8a933a3}</UniqueIdentifier>
</Filter>
<Filter Include="02.Element\02.Component\07.RigidBody\11.Kinematic">
<UniqueIdentifier>{33ac85a2-be8e-4ad9-a179-1239d818dc9c}</UniqueIdentifier>
</Filter>
<Filter Include="02.Element\02.Component\07.RigidBody\00.Static">
<UniqueIdentifier>{fda41884-634b-4dd4-8bd2-f6f7ad68ab1f}</UniqueIdentifier>
</Filter>
@@ -438,9 +435,6 @@
<ClCompile Include="..\Private\PhysX_Manager.cpp">
<Filter>03.Management\21.PhysX_Manager</Filter>
</ClCompile>
<ClCompile Include="..\Private\RigidBody.cpp">
<Filter>02.Element\02.Component\07.RigidBody</Filter>
</ClCompile>
<ClCompile Include="..\private\UIComponent.cpp">
<Filter>02.Element\02.Component\50.UI</Filter>
</ClCompile>
@@ -480,6 +474,15 @@
<ClCompile Include="..\Private\Collision_Callback.cpp">
<Filter>02.Element\02.Component\08.Character_Controller\Collision_Callback</Filter>
</ClCompile>
<ClCompile Include="..\Private\RigidBody_Static.cpp">
<Filter>02.Element\02.Component\07.RigidBody\00.Static</Filter>
</ClCompile>
<ClCompile Include="..\Private\RigidBody_Dynamic.cpp">
<Filter>02.Element\02.Component\07.RigidBody\10.Dynamic</Filter>
</ClCompile>
<ClCompile Include="..\Private\RigidBody.cpp">
<Filter>02.Element\02.Component\07.RigidBody</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Public\Base.h">
@@ -1064,6 +1067,12 @@
<ClInclude Include="..\Public\Collision_Callback.h">
<Filter>02.Element\02.Component\08.Character_Controller\Collision_Callback</Filter>
</ClInclude>
<ClInclude Include="..\Public\RigidBody_Static.h">
<Filter>02.Element\02.Component\07.RigidBody\00.Static</Filter>
</ClInclude>
<ClInclude Include="..\Public\RigidBody_Dynamic.h">
<Filter>02.Element\02.Component\07.RigidBody\10.Dynamic</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\Public\Assimp\color4.inl">
@@ -581,11 +581,11 @@ void CGameInstance::RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTr
return m_pPhysX_Manager->RegistTriMesh(pName, pPxTriMesh);
}
PSX::PxRigidDynamic* CGameInstance::Add_DynamicActor(CRigidBody& RigidBody)
PSX::PxRigidDynamic* CGameInstance::Add_DynamicActor(CRigidBody_Dynamic& RigidBody)
{
return m_pPhysX_Manager->Add_DynamicActor(RigidBody);
}
PSX::PxRigidStatic* CGameInstance::Add_StaticActor(CRigidBody& RigidBody)
PSX::PxRigidStatic* CGameInstance::Add_StaticActor(CRigidBody_Static& RigidBody)
{
return m_pPhysX_Manager->Add_StaticActor(RigidBody);
}
@@ -748,7 +748,7 @@ void CGameInstance::Release_Engine()
SAFE_RELEASE(m_pPhysX_Manager);
SAFE_RELEASE(m_pLevel_Manager);
SAFE_RELEASE(m_pPrototype_Manager);
SAFE_RELEASE(m_pLight_Manager); // Light Manager는 m_pObject_Manager 보다 빨리 불려야함
SAFE_RELEASE(m_pLight_Manager); // Light Manager�� m_pObject_Manager ���� ���� �ҷ�����
SAFE_RELEASE(m_pGraphic_Device);
}
@@ -2,7 +2,8 @@
#include "PhysX_Manager.h"
#include "GameObject.h"
#include "GameInstance.h"
#include "RigidBody.h"
#include "RigidBody_Dynamic.h"
#include "RigidBody_Static.h"
#include "Mesh.h"
CPhysX_Manager::CPhysX_Manager(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) :
@@ -15,7 +16,7 @@ CPhysX_Manager::CPhysX_Manager(ID3D11Device* pDevice, ID3D11DeviceContext* pCont
SAFE_ADDREF(m_pGameInstance);
}
PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody& RigidBody)
PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody_Dynamic& RigidBody)
{
_matrix WorldMatrix = RigidBody.Get_TransformPtr()->Get_XMWorldMatrix();
PSX::PxTransform pxWorldMatrix = XMWorldToPx_NoScale(WorldMatrix);
@@ -68,7 +69,7 @@ PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody& RigidBody)
return pActorDynamic;
}
PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody& RigidBody)
PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody_Static& RigidBody)
{
_matrix WorldMatrix = RigidBody.Get_TransformPtr()->Get_XMWorldMatrix();
PSX::PxTransform pxWorldMatrix = XMWorldToPx_NoScale(WorldMatrix);
@@ -260,9 +261,9 @@ HRESULT CPhysX_Manager::LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangle
// return true;
//}
PSX::PxTriangleMesh* CPhysX_Manager::Find_TriangleMesh(const _wstring& wstrMeshKey)
PSX::PxTriangleMesh* CPhysX_Manager::Find_TriangleMesh(const _tchar* pMeshName)
{
map<_wstring, PSX::PxTriangleMesh*>::iterator iter = m_TriangleMeshes.find(wstrMeshKey);
map<_wstring, PSX::PxTriangleMesh*>::iterator iter = m_TriangleMeshes.find(pMeshName);
if (iter != m_TriangleMeshes.end()) {
return iter->second;
}
@@ -11,80 +11,12 @@ CRigidBody::CRigidBody(ID3D11Device* pDevice, ID3D11DeviceContext* pContext):
CRigidBody::CRigidBody(const CRigidBody& rhs) :
CComponent(rhs),
m_eActorType(rhs.m_eActorType),
m_vhalfGeometryInfo(rhs.m_vhalfGeometryInfo),
m_wstrMeshKey(rhs.m_wstrMeshKey),
m_vMatInfo(rhs.m_vMatInfo),
m_ePxRigidBodyFlags(rhs.m_ePxRigidBodyFlags),
m_ePxShapeFlags(rhs.m_ePxShapeFlags),
m_eMatType(rhs.m_eMatType),
m_fContactOffset(rhs.m_fContactOffset)
{
}
#ifdef _DEBUG
HRESULT CRigidBody::Render()
{
_matrix WorldMatrix = m_pTransform->Get_XMWorldMatrix();
_matrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
_matrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x2fc48000, 1.f);
switch (m_eActorType)
{
case ACTOR::BOX:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
case ACTOR::CAPSULE:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
_matrix WorldUp = XMMatrixTranslationFromVector(m_pTransform->Get_State(STATE::UP) * m_vhalfGeometryInfo.y);
_matrix WorldDown = XMMatrixTranslationFromVector(m_pTransform->Get_State(STATE::UP) * -m_vhalfGeometryInfo.y);
m_pSubShape->Draw(WorldUp * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
m_pSubShape->Draw(WorldDown * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
case ACTOR::SPHERE:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
default:
break;
}
return S_OK;
}
#endif // _DEBUG
void CRigidBody::Set_Kinematic(_bool bKinematic)
{
static_cast<PSX::PxRigidDynamic*>(m_pRigidBody)->setRigidBodyFlag(PSX::PxRigidBodyFlag::eKINEMATIC, bKinematic);
}
void CRigidBody::Add_Force(_fvector vForce, PSX::PxForceMode::Enum eType)
{
PSX::PxVec3 vPxForce = {};
XMStoreFloat3((_float3*)&vPxForce, vForce);
static_cast<PSX::PxRigidDynamic*>(m_pRigidBody)->addForce(vPxForce, eType);
}
void CRigidBody::Add_Torque(_fvector vDirection, PSX::PxForceMode::Enum eType)
{
PSX::PxVec3 vPxTorque = {};
XMStoreFloat3((_float3*)&vPxTorque, vDirection);
static_cast<PSX::PxRigidDynamic*>(m_pRigidBody)->addForce(vPxTorque, eType);
}
HRESULT CRigidBody::Initialize_Prototype(RIGIDBODY_PROTOTYPEDESC& Desc)
{
m_eActorType = Desc.eType;
m_ePxRigidBodyFlags = Desc.ePxRigidBodyFlags;
m_ePxShapeFlags = Desc.ePxShapeFlags;
m_eMatType = Desc.ePxMaterialTypes;
m_vMatInfo = Desc.vMatInfo;
m_fContactOffset = Desc.fContactOffset;
m_vhalfGeometryInfo = Desc.vhalfGeometryInfo;
m_fDensity = Desc.fDensity;
return S_OK;
}
HRESULT CRigidBody::Initialize(void* pArg)
{
@@ -97,136 +29,11 @@ HRESULT CRigidBody::Initialize(void* pArg)
m_pTransform = m_pOwner->Get_Component<CTransform>();
SAFE_ADDREF(m_pTransform);
switch (m_eActorType)
{
case Engine::ACTOR::BOX:
case Engine::ACTOR::CAPSULE:
case Engine::ACTOR::SPHERE:
m_pRigidBody = m_pGameInstance->Add_DynamicActor(*this);
break;
case Engine::ACTOR::PLANE:
break;
case Engine::ACTOR::TRIANGLEMESH:
m_pRigidBody = m_pGameInstance->Add_StaticActor(*this);
break;
case Engine::ACTOR::HEIGHTFIELD:
break;
case Engine::ACTOR::END:
break;
default:
break;
}
Initialize_UserData();
m_pRigidBody->userData = &m_tagData;
#ifdef _DEBUG
if (FAILED(Add_DebugShape())) {
return E_FAIL;
}
#endif // _DEBUG
return S_OK;
}
HRESULT CRigidBody::Initialize_UserData()
{
switch (m_eActorType)
{
case Engine::ACTOR::BOX:
m_tagData.eKind = PHYSX_KIND::BODY_DYNAMIC;
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
break;
case Engine::ACTOR::CAPSULE:
m_tagData.eKind = PHYSX_KIND::BODY_DYNAMIC;
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
break;
case Engine::ACTOR::SPHERE:
m_tagData.eKind = PHYSX_KIND::BODY_DYNAMIC;
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
break;
case Engine::ACTOR::PLANE:
break;
case Engine::ACTOR::TRIANGLEMESH:
m_tagData.eKind = PHYSX_KIND::BODY_STATIC;
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
break;
case Engine::ACTOR::HEIGHTFIELD:
break;
case Engine::ACTOR::END:
break;
default:
break;
}
return S_OK;
}
#ifdef _DEBUG
HRESULT CRigidBody::Add_DebugShape()
{
switch (m_eActorType)
{
case ACTOR::BOX:
m_pMainShape = (GeometricPrimitive::CreateBox(m_pContext, m_vhalfGeometryInfo, false, false));
break;
case ACTOR::CAPSULE:
m_pSubShape = (GeometricPrimitive::CreateSphere(m_pContext, m_vhalfGeometryInfo.x, 10, false, false));
m_pMainShape = (GeometricPrimitive::CreateCylinder(m_pContext, m_vhalfGeometryInfo.y, m_vhalfGeometryInfo.x, 10, false));
break;
case ACTOR::SPHERE:
m_pMainShape = (GeometricPrimitive::CreateSphere(m_pContext, m_vhalfGeometryInfo.x, 10, false, false));
break;
case ACTOR::PLANE:
case ACTOR::TRIANGLEMESH:
case ACTOR::HEIGHTFIELD:
break;
default:
break;
}
return S_OK;
}
#endif // _DEBUG
CRigidBody* CRigidBody::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_PROTOTYPEDESC& Desc)
{
CRigidBody* pInstance = new CRigidBody(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(Desc))) {
MSG_BOX("CRigidBody Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CComponent* CRigidBody::Clone(void* pArg, CGameObject* pOwner)
{
CRigidBody* pInstance = new CRigidBody(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg))) {
MSG_BOX("CRigidBody Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CRigidBody::Free()
{
if (nullptr != m_pRigidBody) {
m_pRigidBody = nullptr;
}
__super::Free();
SAFE_RELEASE(m_pTransform);
@@ -0,0 +1,159 @@
#include "pch.h"
#include "RigidBody_Dynamic.h"
#include "GameInstance.h"
CRigidBody_Dynamic::CRigidBody_Dynamic(ID3D11Device* pDevice, ID3D11DeviceContext* pContext):
CRigidBody(pDevice, pContext)
{
}
CRigidBody_Dynamic::CRigidBody_Dynamic(const CRigidBody_Dynamic& rhs) :
CRigidBody(rhs),
m_vMatInfo(rhs.m_vMatInfo),
m_vhalfGeometryInfo(rhs.m_vhalfGeometryInfo)
{
}
#ifdef _DEBUG
HRESULT CRigidBody_Dynamic::Render()
{
_matrix WorldMatrix = m_pTransform->Get_XMWorldMatrix();
_matrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
_matrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x2fc48000, 1.f);
switch (m_eActorType)
{
case ACTOR::BOX:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
case ACTOR::CAPSULE:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
_matrix WorldUp = XMMatrixTranslationFromVector(m_pTransform->Get_State(STATE::UP) * m_vhalfGeometryInfo.y);
_matrix WorldDown = XMMatrixTranslationFromVector(m_pTransform->Get_State(STATE::UP) * -m_vhalfGeometryInfo.y);
m_pSubShape->Draw(WorldUp * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
m_pSubShape->Draw(WorldDown * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
case ACTOR::SPHERE:
{
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true);
} break;
default:
break;
}
return S_OK;
}
#endif // _DEBUG
void CRigidBody_Dynamic::Add_Force(_fvector vForce, PSX::PxForceMode::Enum eType)
{
PSX::PxVec3 vPxForce = {};
XMStoreFloat3((_float3*)&vPxForce, vForce);
m_pRigidBody->addForce(vPxForce, eType);
}
void CRigidBody_Dynamic::Add_Torque(_fvector vDirection, PSX::PxForceMode::Enum eType)
{
PSX::PxVec3 vPxTorque = {};
XMStoreFloat3((_float3*)&vPxTorque, vDirection);
m_pRigidBody->addForce(vPxTorque, eType);
}
void CRigidBody_Dynamic::Set_Kinematic(_bool bKinematic)
{
m_pRigidBody->setRigidBodyFlag(PSX::PxRigidBodyFlag::eKINEMATIC, bKinematic);
}
HRESULT CRigidBody_Dynamic::Initialize_Prototype(RIGIDBODY_PROTOTYPE_DYNAMIC_DESC& Desc)
{
m_eActorType = Desc.eType;
m_ePxRigidBodyFlags = Desc.ePxRigidBodyFlags;
m_ePxShapeFlags = Desc.ePxShapeFlags;
m_eMatType = Desc.ePxMaterialTypes;
m_vMatInfo = Desc.vMatInfo;
m_fContactOffset = Desc.fContactOffset;
m_vhalfGeometryInfo = Desc.vhalfGeometryInfo;
m_fDensity = Desc.fDensity;
m_vMassCenter = Desc.vMassCenter;
return S_OK;
}
HRESULT CRigidBody_Dynamic::Initialize(void* pArg)
{
m_tagData.eKind = PHYSX_KIND::BODY_DYNAMIC;
if (FAILED(__super::Initialize(pArg))) {
return E_FAIL;
}
#ifdef _DEBUG
if (FAILED(Add_DebugShape())) {
return E_FAIL;
}
#endif // _DEBUG
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
m_pRigidBody = m_pGameInstance->Add_DynamicActor(*this);
m_pRigidBody->userData = &m_tagData;
return S_OK;
}
#ifdef _DEBUG
HRESULT CRigidBody_Dynamic::Add_DebugShape()
{
switch (m_eActorType)
{
case ACTOR::BOX:
m_pMainShape = (GeometricPrimitive::CreateBox(m_pContext, m_vhalfGeometryInfo, false, false));
break;
case ACTOR::CAPSULE:
m_pSubShape = (GeometricPrimitive::CreateSphere(m_pContext, m_vhalfGeometryInfo.x, 10, false, false));
m_pMainShape = (GeometricPrimitive::CreateCylinder(m_pContext, m_vhalfGeometryInfo.y, m_vhalfGeometryInfo.x, 10, false));
break;
case ACTOR::SPHERE:
m_pMainShape = (GeometricPrimitive::CreateSphere(m_pContext, m_vhalfGeometryInfo.x, 10, false, false));
break;
default:
break;
}
return S_OK;
}
#endif // _DEBUG
CRigidBody_Dynamic* CRigidBody_Dynamic::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_PROTOTYPE_DYNAMIC_DESC& Desc)
{
CRigidBody_Dynamic* pInstance = new CRigidBody_Dynamic(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(Desc))) {
MSG_BOX("CRigidBody_Dynamic Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CComponent* CRigidBody_Dynamic::Clone(void* pArg, CGameObject* pOwner)
{
CRigidBody_Dynamic* pInstance = new CRigidBody_Dynamic(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg))) {
MSG_BOX("CRigidBody_Dynamic Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CRigidBody_Dynamic::Free()
{
__super::Free();
if (nullptr != m_pRigidBody) {
m_pRigidBody = nullptr;
}
}
void CRigidBody_Dynamic::Describe_Entity()
{
}
@@ -0,0 +1,76 @@
#include "pch.h"
#include "RigidBody_Static.h"
#include "GameInstance.h"
CRigidBody_Static::CRigidBody_Static(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) :
CRigidBody(pDevice, pContext)
{
}
CRigidBody_Static::CRigidBody_Static(const CRigidBody_Static& rhs) :
CRigidBody(rhs),
m_pMeshName(rhs.m_pMeshName)
{
}
HRESULT CRigidBody_Static::Initialize_Prototype(RIGIDBODY_STATIC_PROTOTYPEDESC& Desc)
{
m_eActorType = Desc.eType;
m_ePxRigidBodyFlags = Desc.ePxRigidBodyFlags;
m_ePxShapeFlags = Desc.ePxShapeFlags;
m_eMatType = Desc.ePxMaterialTypes;
m_fContactOffset = Desc.fContactOffset;
return S_OK;
}
HRESULT CRigidBody_Static::Initialize(void* pArg)
{
m_tagData.eKind = PHYSX_KIND::BODY_STATIC;
if (FAILED(__super::Initialize(pArg))) {
return E_FAIL;
}
m_tagData.pOwner = m_pOwner;
XMStoreFloat4x4(&m_tagData.m_BeforeMatrix, m_pTransform->Get_XMWorldMatrix());
m_tagData.pBody = this;
m_pRigidBody = m_pGameInstance->Add_StaticActor(*this);
m_pRigidBody->userData = &m_tagData;
return S_OK;
}
CRigidBody_Static* CRigidBody_Static::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_STATIC_PROTOTYPEDESC& Desc)
{
CRigidBody_Static* pInstance = new CRigidBody_Static(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype(Desc))) {
MSG_BOX("CRigidBody_Static Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CComponent* CRigidBody_Static::Clone(void* pArg, CGameObject* pOwner)
{
CRigidBody_Static* pInstance = new CRigidBody_Static(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg))) {
MSG_BOX("CRigidBody_Static Prototype Created Failed");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CRigidBody_Static::Free()
{
__super::Free();
if (nullptr != m_pRigidBody) {
m_pRigidBody = nullptr;
}
}
void CRigidBody_Static::Describe_Entity()
{
}
+2 -3
View File
@@ -182,9 +182,8 @@ class ENGINE_DLL CGameInstance final : public CBase
#pragma region PhysX_Manager
PSX::PxMaterial* Create_Material(_float3* vMatInfo);
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody& RigidBody);
PSX::PxRigidStatic* Add_StaticActor(CRigidBody& RigidBody);
PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody_Dynamic& RigidBody);
PSX::PxRigidStatic* Add_StaticActor(CRigidBody_Static& RigidBody);
PSX::PxController* Add_CapsuleController(PSX::PxCapsuleControllerDesc& Desc);
PSX::PxController* Add_BoxController(PSX::PxBoxControllerDesc& Desc);
@@ -4,6 +4,8 @@
NS_BEGIN(Engine)
class CRigidBody;
class CRigidBody_Dynamic;
class CRigidBody_Static;
class CTransform;
class CMesh;
@@ -20,8 +22,8 @@ class CPhysX_Manager final : public CBase
// HRESULT Update_RegionOfInterest(); ( 충돌 컬링, 필터링도 검색해야함 )
// Aggregate ( 충돌 그룹, 이 그룹끼리는 서로 충돌검사를 하지 않음, 지형, 레그돌 등 )
PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody& RigidBody);
PSX::PxRigidStatic* Add_StaticActor(CRigidBody& RigidBody);
PSX::PxRigidDynamic* Add_DynamicActor(CRigidBody_Dynamic& RigidBody);
PSX::PxRigidStatic* Add_StaticActor(CRigidBody_Static& RigidBody);
void RegistTriMesh(const _char* pName, PSX::PxTriangleMesh* pPxTriMesh);
PSX::PxMaterial* Create_Material(const _float3* vMatInfo);
@@ -30,7 +32,7 @@ class CPhysX_Manager final : public CBase
HRESULT SaveTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
HRESULT LoadTriMeshes(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
//HRESULT LoadTriMeshes_Binary(const _char* pPath, vector<PSX::PxTriangleMesh*>& TriMeshes);
PSX::PxTriangleMesh* Find_TriangleMesh(const _wstring& wstrMeshKey);
PSX::PxTriangleMesh* Find_TriangleMesh(const _tchar* pMeshName);
void Update(_float fTimeDelta);
void ClearScene();
@@ -5,7 +5,8 @@
#include "VIBuffer_Cell.h"
#include "Shader.h"
#include "Navigation.h"
#include "RigidBody.h"
#include "RigidBody_Dynamic.h"
#include "RigidBody_Static.h"
#include "Texture.h"
#include "Cell.h"
#include "Model.h"
+10 -60
View File
@@ -10,9 +10,9 @@ NS_BEGIN(Engine)
class CTransform;
class CMesh;
class ENGINE_DLL CRigidBody final : public CComponent
class ENGINE_DLL CRigidBody abstract : public CComponent
{
public: // MORE INFO ON ENGINE_ENUM
protected: // MORE INFO ON ENGINE_ENUM
typedef struct tagRigidBody_PrototypeDesc // 다 채우세요 NONE 빼고, 목적에 안맞는거 빼고
{
ACTOR eType;
@@ -22,91 +22,41 @@ class ENGINE_DLL CRigidBody final : public CComponent
_float3 vMatInfo = { 0.5f, 0.5f, 0.6f }; // 피직스 객체의 속성 등
_float fContactOffset = { 0.05f }; // 접촉 유격 오프셋
#pragma region DYNAMIC
_float3 vhalfGeometryInfo; // 박스는 vSize, 캡슐은 radius, height로 씀
_float fDensity = { 1000.f }; // 밀도, 실제 무게는 부피에 따라 달라짐
#pragma endregion
#pragma region STATIC
#pragma endregion
}RIGIDBODY_PROTOTYPEDESC;
typedef struct tagRigidBody_Desc
{
#pragma region DYNAMIC
#pragma endregion
#pragma region STATIC
const _char* szMeshName = { };
#pragma endregion
}RIGIDBODY_DESC;
private:
protected:
CRigidBody(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
CRigidBody(const CRigidBody& rhs);
virtual ~CRigidBody() = default;
public:
#ifdef _DEBUG
virtual HRESULT Render()override;
#endif // _DEBUG
ACTOR Get_Type() const { return m_eActorType; }
PSX::PxActor* Get_Actor() const { return m_pRigidBody; }
virtual PSX::PxActor* Get_Actor()PURE;
CTransform* Get_TransformPtr() const { return m_pTransform; }
const _tchar* Get_PxMeshKey() const { return m_wstrMeshKey.c_str(); }
PXMATERIAL Get_MaterialType() const { return m_eMatType; }
_float Get_ContactOffset() const { return m_fContactOffset; }
_float Get_Density() const { return m_fDensity; }
PSX::PxShapeFlags Get_ShapeFlags() const { return m_ePxShapeFlags; }
PSX::PxRigidBodyFlags Get_RigidBodyFlags() const { return m_ePxRigidBodyFlags; }
_float3 Get_HalfGeometryInfo() const { return m_vhalfGeometryInfo; }
// 키네마틱은 transform으로 이동 ( simulate 전에 이동함 )
// 키네마틱이 아닌 dynamic은 토크와 포스로 이동 ( simulate 후에 이동함 )
void Set_Kinematic(_bool bKinematic);
void Add_Force(_fvector vForce, PSX::PxForceMode::Enum eType = PSX::PxForceMode::Enum::eFORCE); // 속도 + 방향
void Add_Torque(_fvector vDirection, PSX::PxForceMode::Enum eType = PSX::PxForceMode::Enum::eFORCE); // 방향
private:
protected:
ACTOR m_eActorType = ACTOR::END;
PSX::PxRigidBodyFlags m_ePxRigidBodyFlags = {};
PSX::PxRigidBodyFlags m_ePxRigidBodyFlags = { };
PSX::PxShapeFlags m_ePxShapeFlags = { PSX::PxShapeFlag::eVISUALIZATION | PSX::PxShapeFlag::eSCENE_QUERY_SHAPE | PSX::PxShapeFlag::eSIMULATION_SHAPE };
PXMATERIAL m_eMatType = { PXMATERIAL::END };
_float m_fContactOffset = { 0.05f };
PSX::PxActor* m_pRigidBody = { nullptr }; // 실제 시뮬레이션을 도는 본체
CTransform* m_pTransform = { nullptr };
PhsXUserData m_tagData = {};
#pragma region DYNAMIC
PSX::PxShapeFlags m_ePxShapeFlags = { PSX::PxShapeFlag::eVISUALIZATION | PSX::PxShapeFlag::eSCENE_QUERY_SHAPE | PSX::PxShapeFlag::eSIMULATION_SHAPE };
_float3 m_vMatInfo = {};
_float3 m_vhalfGeometryInfo = {};
_float3 m_vCenterOfMess = {}; // 회전축
_float m_fDensity = { 1000.f };
#pragma endregion
#pragma region STATIC
_wstring m_wstrMeshKey = { }; // 짝꿍 스태틱 메시의 triangleMesh 키
#pragma endregion
#ifdef _DEBUG
unique_ptr<GeometricPrimitive> m_pMainShape = { nullptr };
unique_ptr<GeometricPrimitive> m_pSubShape = { nullptr };
#endif // _DEBUG
private:
HRESULT Initialize_Prototype(RIGIDBODY_PROTOTYPEDESC& Desc);
HRESULT Initialize(void* pArg);
HRESULT Initialize_UserData();
#ifdef _DEBUG
HRESULT Add_DebugShape();
#endif
protected:
virtual HRESULT Initialize(void* pArg);
public:
static CRigidBody* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_PROTOTYPEDESC& Desc);
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
virtual void Free() override;
virtual void Describe_Entity() override;
};
@@ -0,0 +1,68 @@
#pragma once
#include "RigidBody.h"
NS_BEGIN(Engine)
class CTransform;
class CMesh;
class ENGINE_DLL CRigidBody_Dynamic : public CRigidBody
{
public:
typedef struct tagRigidBody_Prototype_DYNAMIC_Desc : public CRigidBody::RIGIDBODY_PROTOTYPEDESC
{
_float3 vhalfGeometryInfo; // 박스는 vSize, 캡슐은 radius, height로 씀
_float fDensity = { 1000.f }; // 밀도, 실제 무게는 부피에 따라 달라짐
_float3 vMassCenter = {};
}RIGIDBODY_PROTOTYPE_DYNAMIC_DESC;
typedef struct tagRigidBody_DYNAMIC_Desc : public CRigidBody::RIGIDBODY_DESC
{
}RIGIDBODY_DYNAMIC_DESC;
private:
CRigidBody_Dynamic(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
CRigidBody_Dynamic(const CRigidBody_Dynamic& rhs);
virtual ~CRigidBody_Dynamic() = default;
public:
#ifdef _DEBUG
virtual HRESULT Render()override;
#endif // _DEBUG
virtual PSX::PxRigidDynamic* Get_Actor() override { return m_pRigidBody; };
_float3 Get_HalfGeometryInfo() const { return m_vhalfGeometryInfo; }
_float Get_Density() const { return m_fDensity; }
virtual void Add_Force(_fvector vForce, PSX::PxForceMode::Enum eType = PSX::PxForceMode::Enum::eFORCE); // 속도 + 방향
virtual void Add_Torque(_fvector vDirection, PSX::PxForceMode::Enum eType = PSX::PxForceMode::Enum::eFORCE); // 방향 ( 회전축은 MassCenter )
void Set_Kinematic(_bool bKinematic);
private:
PSX::PxRigidDynamic* m_pRigidBody = { nullptr }; // 실제 시뮬레이션을 도는 본체
_float3 m_vMatInfo = {};
_float3 m_vhalfGeometryInfo = {};
_float3 m_vMassCenter = {}; // 회전축
_float m_fDensity = { 1000.f };
#ifdef _DEBUG
unique_ptr<GeometricPrimitive> m_pMainShape = { nullptr };
unique_ptr<GeometricPrimitive> m_pSubShape = { nullptr };
#endif // _DEBUG
private:
HRESULT Initialize_Prototype(RIGIDBODY_PROTOTYPE_DYNAMIC_DESC& Desc);
virtual HRESULT Initialize(void* pArg) override;
#ifdef _DEBUG
HRESULT Add_DebugShape();
#endif
public:
static CRigidBody_Dynamic* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_PROTOTYPE_DYNAMIC_DESC& Desc);
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
virtual void Free() override;
virtual void Describe_Entity() override;
};
NS_END
@@ -0,0 +1,47 @@
#pragma once
#include "RigidBody.h"
NS_BEGIN(Engine)
class CTransform;
class CMesh;
class ENGINE_DLL CRigidBody_Static : public CRigidBody
{
public:
typedef struct tagRigidBody_Prototype_STATIC_Desc : public CRigidBody::RIGIDBODY_PROTOTYPEDESC
{
}RIGIDBODY_STATIC_PROTOTYPEDESC;
typedef struct tagRigidBody_STATIC_Desc : public CRigidBody::RIGIDBODY_PROTOTYPEDESC
{
const _tchar* pMeshName = { nullptr };
}RIGIDBODY_STATIC_DESC;
private:
CRigidBody_Static(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);
CRigidBody_Static(const CRigidBody_Static& rhs);
virtual ~CRigidBody_Static() = default;
public:
PSX::PxRigidStatic* Get_Actor() override { return m_pRigidBody; }
const _tchar* Get_PxMeshKey() const { return m_pMeshName; }
private:
PSX::PxRigidStatic* m_pRigidBody = { nullptr }; // 실제 시뮬레이션을 도는 본체
const _tchar* m_pMeshName = { nullptr }; // 짝꿍 스태틱 메시의 triangleMesh 키
private:
HRESULT Initialize_Prototype(RIGIDBODY_STATIC_PROTOTYPEDESC& Desc);
virtual HRESULT Initialize(void* pArg) override;
public:
static CRigidBody_Static* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, RIGIDBODY_STATIC_PROTOTYPEDESC& Desc);
virtual CComponent* Clone(void* pArg, class CGameObject* pOwner = nullptr) override;
virtual void Free() override;
virtual void Describe_Entity() override;
};
NS_END