[add] 플레이어 다리 리지드본 추가

This commit is contained in:
kimnuri
2025-12-26 16:00:58 +09:00
parent 9cf54843b7
commit c6da7d680b
27 changed files with 505 additions and 182 deletions
+260 -41
View File
@@ -111,7 +111,9 @@ HRESULT CPlayer::Initialize(void* pArg)
m_BasicEffect->SetProjection(m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ));
m_Batch = make_unique<PrimitiveBatch<VertexPositionColor>>(m_pContext);
m_pBoneShape = (GeometricPrimitive::CreateSphere(m_pContext, 0.05f, 10, false, false));
m_pBoneShape = (GeometricPrimitive::CreateSphere(m_pContext, 0.05f, 22, false, false));
m_pSubShape = (GeometricPrimitive::CreateSphere(m_pContext, 0.05f, 22, false, false));
m_pMainShape = (GeometricPrimitive::CreateCylinder(m_pContext, 0.3f, 0.075f, 22, false));
D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {};
depthStencilDesc.DepthEnable = FALSE;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
@@ -218,6 +220,9 @@ void CPlayer::Late_Update(_float fTimeDelta)
m_pTransformCom->Set_State(STATE::POSITION, m_pCharacter_Controller->Get_FootPosition());
m_pGameInstance->Add_RenderGroup(RENDER::NONBLEND, this);
#ifdef _DEBUG
m_pGameInstance->Add_RenderGroup(RENDER::NONLIGHT, this);
#endif // _DEBUG
Set_Shadow(m_pGameInstance->IsIn_ShadowViewFrustum(m_pTransformCom->Get_State(STATE::POSITION), m_pTransformCom->Get_Radius()));
@@ -263,49 +268,50 @@ HRESULT CPlayer::Render()
if (FAILED(Bind_ShaderResources())) {
return E_FAIL;
}
RENDER eType = m_pGameInstance->Get_CurrentRenderPass();
if (RENDER::NONBLEND == eType) {
_uint iNumMeshes = m_pModelCom->Get_NumMeshes();
_uint iNumMeshes = m_pModelCom->Get_NumMeshes();
for (_uint i = 0; i < iNumMeshes; i++)
{
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrices(
"g_OffsetMatrix",
m_pModelCom->Get_OffsetMatrix(i).data(),
(_int)m_pModelCom->Get_OffsetMatrix(i).size()
)))
for (_uint i = 0; i < iNumMeshes; i++)
{
return E_FAIL;
}
if (FAILED(m_pModelCom->Begin(i, m_pShaderCom, false))) {
return E_FAIL;
}
if (FAILED(m_pModelCom->Bind_Material(i, m_pShaderCom))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrices(
"g_OffsetMatrix",
m_pModelCom->Get_OffsetMatrix(i).data(),
(_int)m_pModelCom->Get_OffsetMatrix(i).size()
)))
{
return E_FAIL;
}
if (FAILED(m_pModelCom->Begin(i, m_pShaderCom, false))) {
return E_FAIL;
}
m_pModelCom->Bind_OutPut_SRV_VS(26, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(27, 0);
if (FAILED(Bind_ShaderParameters(i))) {
return E_FAIL;
}
m_pModelCom->Bind_OutPut_SRV_VS(26, 0);
m_pModelCom->Bind_OutPut_SRV_VS_Prev(27, 0);
if (FAILED(Bind_ShaderParameters(i))) {
return E_FAIL;
}
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
}
}
}
#ifdef _DEBUG
//for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::END); ++i) {
// m_pRobeJointRoute[i]->Render();
//}
m_pCharacter_Controller->Render();
//m_pRigidBody->Render();
m_pLeftLeg->Render();
m_pRightLeg->Render();
Render_CameraCoordinateSystem();
Render_BonePhysX();
if (RENDER::NONLIGHT == eType) {
//for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::END); ++i) {
// m_pRobeJointRoute[i]->Render();
//}
//m_pCharacter_Controller->Render();
//m_pRigidBody->Render();
Render_CameraCoordinateSystem();
Render_BonePhysX();
}
#endif
return S_OK;
@@ -437,24 +443,135 @@ void CPlayer::Render_CameraCoordinateSystem()
);
m_Batch->End();
}
HRESULT CPlayer::Update_LegsPosition()
{
_matrix WorldMatrix = m_pTransformCom->Get_XMWorldMatrix();
_matrix FootMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("LeftFoot")) * WorldMatrix;
_matrix LegMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("LeftLeg")) * WorldMatrix;
m_pLeftLeg->Set_CenterTransform(WorldMatrix, FootMatrix.r[3], LegMatrix.r[3]);
#ifdef _DEBUG
{
_vector vCenterWorldPos = (FootMatrix.r[3] + LegMatrix.r[3]) * 0.5f;
_vector vRotQ = XMQuaternionIdentity();
_vector vDir = XMVectorSetW(LegMatrix.r[3] - FootMatrix.r[3], 0.f);
_float vLength = XMVectorGetX(XMVector3Length(vDir));
if (vLength > FLT_EPSILON5) {
vDir = XMVector3Normalize(vDir);
vRotQ = CMyTools::MakeQuaternionFromTo(XMVectorSet(0.f, 1.f, 0.f, 0.f), vDir);
}
XMStoreFloat4x4(&m_LeftLegMatrix, XMMatrixRotationQuaternion(vRotQ) * XMMatrixTranslationFromVector(vCenterWorldPos));
}
#endif // _DEBUG
FootMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("RightFoot")) * WorldMatrix;
LegMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("RightLeg")) * WorldMatrix;
m_pRightLeg->Set_CenterTransform(WorldMatrix, FootMatrix.r[3], LegMatrix.r[3]);
#ifdef _DEBUG
{
_vector vCenterWorldPos = (FootMatrix.r[3] + LegMatrix.r[3]) * 0.5f;
_vector vRotQ = XMQuaternionIdentity();
_vector vDir = XMVectorSetW(LegMatrix.r[3] - FootMatrix.r[3], 0.f);
_float vLength = XMVectorGetX(XMVector3Length(vDir));
if (vLength > FLT_EPSILON5) {
vDir = XMVector3Normalize(vDir);
vRotQ = CMyTools::MakeQuaternionFromTo(XMVectorSet(0.f, 1.f, 0.f, 0.f), vDir);
}
XMStoreFloat4x4(&m_RightLegMatrix, XMMatrixRotationQuaternion(vRotQ) * XMMatrixTranslationFromVector(vCenterWorldPos));
}
#endif // _DEBUG
return S_OK;
}
HRESULT CPlayer::Render_Legs()
{
_float fHeight = 0.25f;
_matrix WorldMatrix = XMLoadFloat4x4(&m_LeftLegMatrix);
_matrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
_matrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0xff0000, 1.f);
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
_matrix WorldUp = XMMatrixTranslationFromVector(WorldMatrix.r[1] * fHeight);
_matrix WorldDown = XMMatrixTranslationFromVector(WorldMatrix.r[1] * -fHeight);
m_pSubShape->Draw(WorldUp * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pSubShape->Draw(WorldDown * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
WorldMatrix = XMLoadFloat4x4(&m_RightLegMatrix);
m_pMainShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
WorldUp = XMMatrixTranslationFromVector(WorldMatrix.r[1] * fHeight);
WorldDown = XMMatrixTranslationFromVector(WorldMatrix.r[1] * -fHeight);
m_pSubShape->Draw(WorldUp * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pSubShape->Draw(WorldDown * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
return S_OK;
}
//HRESULT CPlayer::Helper_JointGenerater(CDynamic_Joint::DYNAMICJOINT_DESC& Desc, _uint iRoute0, _bool bUseHead0, _uint iRoute1, _bool bUseHead1, _uint iJoint)
//{
// Desc.pActor0 = m_pRobeJointRoute[iRoute0]->Get_Actor();
// if (true == bUseHead0) {
// Desc.pLocalFrame0 = m_pRobeJointRoute[iRoute0]->Get_HeadPositionPxTransform();
// }
// else {
// Desc.pLocalFrame0 = m_pRobeJointRoute[iRoute0]->Get_FootPositionPxTransform();
// }
//
// Desc.pActor1 = m_pRobeJointRoute[iRoute1]->Get_Actor();
// if (true == bUseHead1) {
// Desc.pLocalFrame1 = m_pRobeJointRoute[iRoute1]->Get_HeadPositionPxTransform();
// }
// else {
// Desc.pLocalFrame1 = m_pRobeJointRoute[iRoute1]->Get_FootPositionPxTransform();
// }
// if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("PHYSX_DynamicJoint"), (CComponent**)&m_pDynamicJoints[iJoint], &Desc))) {
// return E_FAIL;
// }
// return S_OK;
//}
HRESULT CPlayer::Render_BonePhysX()
{
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0xffffff, 1.f);
_fmatrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
_cmatrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x00ff00, 1.f);
_fmatrix OwnerMatrix = m_pTransformCom->Get_XMWorldMatrix();
_cmatrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
_matrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
ID3D11DepthStencilState* pPrevDSS = nullptr;
UINT iPrevStencilRef = 0;
m_pContext->OMGetDepthStencilState(&pPrevDSS, &iPrevStencilRef);
for (_uint iBoneIndex = 0; iBoneIndex < ENUM_CLASS(PLAYER_JOINT_ORDER::END); ++iBoneIndex)
{
_matrix WorldMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr(PLAYER_JOINT_BONE_NAMES[iBoneIndex]));
_matrix WorldMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr(PLAYER_JOINT_BONE_NAMES[iBoneIndex])) * OwnerMatrix;
m_pBoneShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
}
Render_Legs();
m_pContext->OMSetDepthStencilState(pPrevDSS, iPrevStencilRef);
if (pPrevDSS != nullptr){
pPrevDSS->Release();
@@ -558,6 +675,105 @@ HRESULT CPlayer::Ready_Components()
// }
// }
//}
//{
// CDynamic_Joint::DYNAMICJOINT_DESC Desc{}; // 조인트 실제 본이랑연결해야함
// Desc.eType = PHYSX_JOINT::D6;
// _uint iRoute0 = 0;
// _bool bHead0 = 0;
// _uint iRoute1 = 0;
// _bool bHead1 = 0;
// _uint iJoint = 0;
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::RIGHTUP);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::UP_R_T);
// bHead0 = false;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::UP_MIDDLE_R);
// bHead1 = false;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::LEFTUP);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::UP_T_L);
// bHead0 = false;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::UP_MIDDLE_L);
// bHead1 = false;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::RIGHT);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_R_T);
// bHead0 = false;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_TR);
// bHead1 = false;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::LEFT);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_T_L);
// bHead0 = false;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_TL);
// bHead1 = false;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::TAIL);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_TR);
// bHead0 = false;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_TL);
// bHead1 = false;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::RIGHTDOWNRIGHT);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_RR);
// bHead0 = true;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::DOWN_RR_TR);
// bHead1 = true;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::LEFTDOWNLEFT);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_LL);
// bHead0 = true;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::DOWN_TL_L);
// bHead1 = true;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::RIGHTDOWN);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_R);
// bHead0 = true;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::DOWN_R_RR);
// bHead1 = true;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
// {
// iJoint = ENUM_CLASS(PLAYER_JOINT_ORDER::LEFTDOWN);
// iRoute0 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::MIDDLE_DOWN_L);
// bHead0 = true;
// iRoute1 = ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::DOWN_L_LL);
// bHead1 = true;
// if (FAILED(Helper_JointGenerater(Desc, iRoute0, bHead0, iRoute1, bHead1, iJoint))) {
// return E_FAIL;
// }
// }
//}
return S_OK;
}
@@ -771,9 +987,12 @@ void CPlayer::Free()
#endif // _DEBUG
SAFE_RELEASE(m_pRightLeg);
SAFE_RELEASE(m_pLeftLeg);
//for (_uint i = 0; i < ENUM_CLASS(PXOBJECT::JOINT_ROUTE); ++i) {
//for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::END); ++i) {
// SAFE_RELEASE(m_pRobeJointRoute[i]);
//}
//for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_ORDER::END); ++i) {
// SAFE_RELEASE(m_pDynamicJoints[i]);
//}
SAFE_RELEASE(m_pGrapInteractive);
if (nullptr != m_pInfoInstance) {