[add] Basic] Collider Player

This commit is contained in:
kimnuri
2026-01-02 17:26:36 +09:00
parent 916ffb8d9a
commit 33386049e4
3 changed files with 151 additions and 102 deletions
+2 -2
View File
@@ -198,7 +198,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
g_hWnd = hWnd;
#endif // _DEBUG
#ifdef Bin
//#ifdef Bin
#ifndef _DEBUG
int screenX = GetSystemMetrics(SM_CXSCREEN);
int screenY = GetSystemMetrics(SM_CYSCREEN);
@@ -224,7 +224,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
UpdateWindow(hWnd);
#endif // !_DEBUG
#endif // Bin
//#endif // Bin
return TRUE;
}
+138 -98
View File
@@ -44,7 +44,12 @@ HRESULT CPlayerRobe::Render()
{
#ifdef _DEBUG
#ifdef 기무리
//Render_BonePhysX();
if (m_pGameInstance->Key_Up(DIK_8)) {
m_bRenderDebug = !m_bRenderDebug;
}
if (m_bRenderDebug) {
Render_BonePhysX();
}
#endif // 기무리
#endif // _DEBUG
return S_OK;
@@ -56,12 +61,6 @@ HRESULT CPlayerRobe::Update_RobeSocketPosition()
PSX::PxTransform pxTransform = {};
_matrix WorldMatrix = {};
_matrix OwnerInvWorldMatrix = m_pParentTransformCom->Get_WorldMatrixInv();
//{
// pxTransform = m_pRobeMainAnchor->Get_GlobalPosition();
// WorldMatrix = XMMatrixAffineTransformation(XMVectorSet(1.f, 1.f, 1.f, 0.f), XMVectorZero(), XMLoadFloat4((_float4*)&pxTransform.q), XMVectorSetW(XMLoadFloat3((_float3*)&pxTransform.p), 1.f));
// _fmatrix LocalMatrix = WorldMatrix * OwnerInvWorldMatrix;
// m_pModelCom->Set_BoneCombinedTransformation("Hips_Cloth", LocalMatrix);
//}
for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END); ++i) {
pxTransform = m_pRobeJointAnchor[i]->Get_GlobalPosition();
WorldMatrix = XMMatrixAffineTransformation(XMVectorSet(1.f, 1.f, 1.f, 0.f), XMVectorZero(), XMLoadFloat4((_float4*)&pxTransform.q), XMVectorSetW(XMLoadFloat3((_float3*)&pxTransform.p), 1.f));
@@ -137,62 +136,122 @@ HRESULT CPlayerRobe::Update_LegsPosition()
}
#endif // _DEBUG
}
m_pLower0Bound->Move_Kinematic(m_pParentTransformCom->Get_XMWorldMatrix(), false);
m_pLower1Bound->Move_Kinematic(m_pParentTransformCom->Get_XMWorldMatrix(), false);
{
_vector vLegPos = XMVector4Transform(XMLoadFloat4((_float4*)&m_pLeftLegLocalMatrix->m[3][0]), WorldMatrix);
_vector vLegUp = XMVector4Transform(XMLoadFloat4((_float4*)&m_pLeftLegUpLocalMatrix->m[3][0]), WorldMatrix);
m_pLeftThigh->Set_CenterTransform(vLegPos, vLegUp, false);
#ifdef _DEBUG
{
_vector vCenterWorldPos = (vLegPos + vLegUp ) * 0.5f;
_vector vRotQ = XMQuaternionIdentity();
_vector vDir = XMVectorSetW(vLegUp - vLegPos, 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_LeftThighMatrix, XMMatrixRotationQuaternion(vRotQ) * XMMatrixTranslationFromVector(vCenterWorldPos));
}
#endif // _DEBUG
vLegPos = XMVector4Transform(XMLoadFloat4((_float4*)&m_pRightLegLocalMatrix->m[3][0]), WorldMatrix);
vLegUp = XMVector4Transform(XMLoadFloat4((_float4*)&m_pRightLegUpLocalMatrix->m[3][0]), WorldMatrix);
m_pRightThigh->Set_CenterTransform(vLegPos, vLegUp, false);
#ifdef _DEBUG
{
_vector vCenterWorldPos = (vLegPos + vLegUp) * 0.5f;
_vector vRotQ = XMQuaternionIdentity();
_vector vDir = XMVectorSetW(vLegUp - vLegPos, 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_RightThighMatrix, XMMatrixRotationQuaternion(vRotQ) * XMMatrixTranslationFromVector(vCenterWorldPos));
}
#endif // _DEBUG
}
m_pLower0Bound->Move_Kinematic(XMMatrixTranslationFromVector(XMVectorSet(0.f, -0.2f, 0.f, 0.f)) * XMLoadFloat4x4(m_pLower0BoundMatrix) * WorldMatrix, false);
m_pLower1Bound->Move_Kinematic(XMMatrixTranslationFromVector(XMVectorSet(0.f, -0.7f, 0.f, 0.f)) * XMLoadFloat4x4(m_pLower1BoundMatrix) * WorldMatrix, false);
return S_OK;
}
#ifdef _DEBUG
HRESULT CPlayerRobe::Render_Legs()
HRESULT CPlayerRobe::Render_Legs(_fmatrix LowerMatrix)
{
_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,
m_pMainShape->Draw(LowerMatrix, 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,
_matrix WorldUp = XMMatrixTranslationFromVector(LowerMatrix.r[1] * fHeight);
_matrix WorldDown = XMMatrixTranslationFromVector(LowerMatrix.r[1] * -fHeight);
m_pSubShape->Draw(WorldUp * LowerMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pSubShape->Draw(WorldDown * WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
m_pSubShape->Draw(WorldDown * LowerMatrix, 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);
});
m_pLower0Bound->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pLower1Bound->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
return S_OK;
}
HRESULT CPlayerRobe::Render_BonePhysX()
{
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x00ff00, 1.f);
_fmatrix OwnerMatrix = m_pParentTransformCom->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_BONE_ORDER::END); ++iBoneIndex)
{
_matrix WorldMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr(PLAYER_JOINT_BONE_NAMES[iBoneIndex])) * OwnerMatrix;
m_pSubShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
}
_matrix MainAnchorMatrix = /*XMMatrixRotationZ(XM_PIDIV2) * */XMLoadFloat4x4(m_pSocketMatrix) * OwnerMatrix;
m_pSubShape->Draw(MainAnchorMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pRobeMainAnchor->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
Render_Legs(XMLoadFloat4x4(&m_LeftLegMatrix));
Render_Legs(XMLoadFloat4x4(&m_RightLegMatrix));
Render_Legs(XMLoadFloat4x4(&m_LeftThighMatrix));
Render_Legs(XMLoadFloat4x4(&m_RightThighMatrix));
_vector vRouteColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x0000ff, 1.f);
for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END); ++i) {
m_pRobeJointAnchor[i]->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
}
m_pContext->OMSetDepthStencilState(pPrevDSS, iPrevStencilRef);
if (pPrevDSS != nullptr) {
pPrevDSS->Release();
}
m_pLower0Bound->Render();
m_pLower1Bound->Render();
return S_OK;
}
#endif // _DEBUG
HRESULT CPlayerRobe::Update_RobeJoints()
{
for (_uint i = ENUM_CLASS(PLAYER_JOINT_ORDER::ORIGIN_TO_RUP_START); i < ENUM_CLASS(PLAYER_JOINT_ORDER::END); ++i) {
@@ -203,22 +262,22 @@ HRESULT CPlayerRobe::Update_RobeJoints()
case PLAYER_JOINT_ORDER::ORIGIN_TO_RUP_START:
case PLAYER_JOINT_ORDER::ORIGIN_TO_TUP_START:
case PLAYER_JOINT_ORDER::ORIGIN_TO_LUP_START:
m_JointDescriptions[i].iMotionTwist = 0;
m_JointDescriptions[i].iMotionSwing1 = 0;
m_JointDescriptions[i].iMotionSwing2 = 0;
m_JointDescriptions[i].iMotionTwist = 1;
m_JointDescriptions[i].iMotionSwing1 = 1;
m_JointDescriptions[i].iMotionSwing2 = 1;
m_JointDescriptions[i].fLinearLimit = 0.f;
m_JointDescriptions[i].fTwistAbsDeg = 0.f;
m_JointDescriptions[i].fSwingDeg = 5.f;
m_JointDescriptions[i].fSwingDeg = 40.f;
break;
case PLAYER_JOINT_ORDER::ORIGIN_TO_RUP_END:
case PLAYER_JOINT_ORDER::ORIGIN_TO_TUP_END:
case PLAYER_JOINT_ORDER::ORIGIN_TO_LUP_END:
m_JointDescriptions[i].iMotionTwist = 0;
m_JointDescriptions[i].iMotionSwing1 = 0;
m_JointDescriptions[i].iMotionSwing2 = 0;
m_JointDescriptions[i].iMotionTwist = 1;
m_JointDescriptions[i].iMotionSwing1 = 1;
m_JointDescriptions[i].iMotionSwing2 = 1;
m_JointDescriptions[i].fLinearLimit = 0.f;
m_JointDescriptions[i].fTwistAbsDeg = 0.f;
m_JointDescriptions[i].fSwingDeg = 5.f;
m_JointDescriptions[i].fSwingDeg = 40.f;
break;
@@ -299,48 +358,6 @@ HRESULT CPlayerRobe::Update_RobeJoints()
}
return S_OK;
}
HRESULT CPlayerRobe::Render_BonePhysX()
{
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x00ff00, 1.f);
_fmatrix OwnerMatrix = m_pParentTransformCom->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_BONE_ORDER::END); ++iBoneIndex)
{
_matrix WorldMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr(PLAYER_JOINT_BONE_NAMES[iBoneIndex])) * OwnerMatrix;
m_pSubShape->Draw(WorldMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
}
_matrix MainAnchorMatrix = /*XMMatrixRotationZ(XM_PIDIV2) * */XMLoadFloat4x4(m_pSocketMatrix) * OwnerMatrix;
m_pSubShape->Draw(MainAnchorMatrix, ViewMatrix, ProjMatrix, vColor, nullptr, true,
[this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
m_pRobeMainAnchor->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
Render_Legs();
_vector vRouteColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0x0000ff, 1.f);
for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END); ++i) {
m_pRobeJointAnchor[i]->Render([this]() {
m_pContext->OMSetDepthStencilState(m_pDepthStencilStateNone, 0);
});
}
m_pContext->OMSetDepthStencilState(pPrevDSS, iPrevStencilRef);
if (pPrevDSS != nullptr) {
pPrevDSS->Release();
}
return S_OK;
}
#endif // _DEBUG
HRESULT CPlayerRobe::Ready_Components()
{
__super::Ready_Components(nullptr);
@@ -367,6 +384,23 @@ HRESULT CPlayerRobe::Ready_Components()
return E_FAIL;
}
}
{ //
CRigidBody_Dynamic::RIGIDBODY_DYNAMIC_DESC Desc{};
Desc.iSubKind = ENUM_CLASS(PXOBJECT::LEG);
Desc.bAutoOwnerTranslation = false;
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("PHYSX_Player_Leg"), (CComponent**)&m_pLeftThigh, &Desc))) {
return E_FAIL;
}
}
{ //
CRigidBody_Dynamic::RIGIDBODY_DYNAMIC_DESC Desc{};
Desc.iSubKind = ENUM_CLASS(PXOBJECT::LEG);
Desc.bAutoOwnerTranslation = false;
if (FAILED(Add_Asset_Component(g_iStaticLevel, TEXT("PHYSX_Player_Leg"), (CComponent**)&m_pRightThigh, &Desc))) {
return E_FAIL;
}
}
{ //
CRigidBody_Dynamic::RIGIDBODY_DYNAMIC_DESC Desc{};
Desc.iSubKind = ENUM_CLASS(PXOBJECT::LEG);
@@ -587,7 +621,7 @@ HRESULT CPlayerRobe::Initialize(void* pArg)
PlayerRobe_DESC* pDesc = static_cast<PlayerRobe_DESC*> (pArg);
m_pSocketMatrix = pDesc->pSocketMatrix;
m_pModelCom = pDesc->pModel;
m_ReconstructedJointAnchorMatirces.resize(ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END));
m_iBoneNum = m_pModelCom->Get_MeshInfluencedBoneNum(ENUM_CLASS(PLAYER_MESH_ORDER::ROBE_CLOTH));
@@ -596,13 +630,16 @@ HRESULT CPlayerRobe::Initialize(void* pArg)
return E_FAIL;
}
m_pLeftFootLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("LeftFoot");
m_pLeftLegLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("LeftLeg");
m_pRightFootLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("RightFoot");
m_pRightLegLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("RightLeg");
XMStoreFloat4x4(&m_PreTransformMatrix, XMLoadFloat4x4(m_pModelCom->Get_PreTransformMatrixPtr()));
m_pLeftFootLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("LeftFoot");
m_pLeftLegLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("LeftLeg");
m_pRightFootLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("RightFoot");
m_pRightLegLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("RightLeg");
m_pLeftLegUpLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("LeftUpLeg");
m_pRightLegUpLocalMatrix = m_pModelCom->Get_BoneMatrixPtr("RightUpLeg");
m_pLower1BoundMatrix = m_pLower0BoundMatrix = m_pModelCom->Get_BoneMatrixPtr("Hips");
XMStoreFloat4x4(&m_PreTransformMatrix, XMLoadFloat4x4(m_pModelCom->Get_PreTransformMatrixPtr()));
for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END); ++i) {
m_RobeJointAnchorMatrices[i] = m_pModelCom->Get_BoneLocalMatrixPtr(PLAYER_JOINT_BONE_NAMES[i]);
}
@@ -672,6 +709,7 @@ HRESULT CPlayerRobe::Initialize(void* pArg)
JointDesc.ApplyToJoint(*m_pDynamicJoints[i]);
m_JointDescriptions[i] = JointDesc;
}
Update_LegsPosition();
Update_RobeJoints();
#ifdef _DEBUG
@@ -724,9 +762,11 @@ void CPlayerRobe::Free()
SAFE_RELEASE(m_pDepthStencilStateNone);
#endif // _DEBUG
SAFE_RELEASE(m_pRightLeg);
SAFE_RELEASE(m_pLeftLeg);
SAFE_RELEASE(m_pRightThigh);
SAFE_RELEASE(m_pLeftThigh);
SAFE_RELEASE(m_pLower0Bound);
SAFE_RELEASE(m_pLower1Bound);
SAFE_RELEASE(m_pLeftLeg);
SAFE_RELEASE(m_pRobeMainAnchor);
for (_uint i = 0; i < ENUM_CLASS(PLAYER_JOINT_ROUTE_ORDER::END); ++i) {
SAFE_RELEASE(m_pRobeJointRoute[i]);
+11 -2
View File
@@ -40,8 +40,12 @@ class CPlayerRobe final : public CPartObject
const _float4x4* m_pSocketMatrix = { nullptr };
const _float4x4* m_pLeftFootLocalMatrix = { nullptr };
const _float4x4* m_pLeftLegLocalMatrix = { nullptr };
const _float4x4* m_pLeftLegUpLocalMatrix = { nullptr };
const _float4x4* m_pRightFootLocalMatrix = { nullptr };
const _float4x4* m_pRightLegLocalMatrix = { nullptr };
const _float4x4* m_pRightLegUpLocalMatrix = { nullptr };
const _float4x4* m_pLower0BoundMatrix = { nullptr };
const _float4x4* m_pLower1BoundMatrix = { nullptr };
const _float4x4* m_RobeJointAnchorMatrices[ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END)] = { nullptr };
vector<_float4x4> m_ReconstructedJointAnchorMatirces = { };
//_float4x4 m_ReconstructedJointAnchorMatirces[ENUM_CLASS(PLAYER_JOINT_BONE_ORDER::END)] = { };
@@ -50,6 +54,8 @@ class CPlayerRobe final : public CPartObject
_int m_iBoneNum = -1;
CRigidBody_Dynamic* m_pRightLeg = { nullptr };
CRigidBody_Dynamic* m_pLeftLeg = { nullptr };
CRigidBody_Dynamic* m_pLeftThigh = { nullptr };
CRigidBody_Dynamic* m_pRightThigh = { nullptr };
CRigidBody_Dynamic* m_pLower0Bound = { nullptr };
CRigidBody_Dynamic* m_pLower1Bound = { nullptr };
CRigidBody_Dynamic* m_pRobeMainAnchor = { nullptr };
@@ -65,6 +71,9 @@ class CPlayerRobe final : public CPartObject
ID3D11DepthStencilState* m_pDepthStencilStateNone = { nullptr };
_float4x4 m_LeftLegMatrix = {};
_float4x4 m_RightLegMatrix = {};
_float4x4 m_LeftThighMatrix = {};
_float4x4 m_RightThighMatrix = {};
_bool m_bRenderDebug = { true };
#endif // _DEBUG
private:
virtual HRESULT Initialize_Prototype() override;
@@ -74,10 +83,10 @@ class CPlayerRobe final : public CPartObject
HRESULT Update_LegsPosition();
HRESULT Helper_RouteJointGenerater(CRigidBody_Dynamic::RIGIDBODY_DYNAMIC_DESC& Desc_Body, ROUTE_DESC& Desc_Route, _matrix* xmAnchorMatricesWorld);
HRESULT Update_RobeJoints();
#ifdef _DEBUG
HRESULT Render_BonePhysX();
HRESULT Render_Legs();
HRESULT Update_RobeJoints();
HRESULT Render_Legs(_fmatrix LowerMatrix);
#endif // _DEBUG
public:
static CPlayerRobe* Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext);