Merge branch 'PhysicsLAB' into Develope
This commit is contained in:
@@ -5,19 +5,6 @@
|
||||
#include "RigidBody.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
static PSX::PxTransform XMWorldToPx_NoScale(const _matrix& WorldMatrix)
|
||||
{
|
||||
_vector vPos, vRotq, vScale;
|
||||
XMMatrixDecompose(&vScale, &vRotq, &vPos, WorldMatrix);
|
||||
|
||||
vRotq = XMQuaternionNormalize(vRotq);
|
||||
|
||||
PSX::PxTransform out;
|
||||
XMStoreFloat3((_float3*)&out.p, vPos);
|
||||
XMStoreFloat4((_float4*)&out.q, vRotq);
|
||||
return out;
|
||||
}
|
||||
|
||||
CPhysX_Manager::CPhysX_Manager(ID3D11Device* pDevice, ID3D11DeviceContext* pContext) :
|
||||
m_pDevice(pDevice),
|
||||
m_pContext(pContext),
|
||||
@@ -28,15 +15,13 @@ CPhysX_Manager::CPhysX_Manager(ID3D11Device* pDevice, ID3D11DeviceContext* pCont
|
||||
SAFE_ADDREF(m_pGameInstance);
|
||||
}
|
||||
|
||||
const PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody& RigidBody)
|
||||
PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody& RigidBody)
|
||||
{
|
||||
_matrix WorldMatrix = RigidBody.Get_TransformPtr()->Get_XMWorldMatrix();
|
||||
PSX::PxTransform pxWorldMatrix = XMWorldToPx_NoScale(WorldMatrix);
|
||||
|
||||
// PxRigidDynamic 씬의 동적 바디 인터페이스
|
||||
PSX::PxRigidDynamic* pActorDynamic = m_pPhysics->createRigidDynamic(pxWorldMatrix);
|
||||
pActorDynamic->userData = &RigidBody;
|
||||
|
||||
PSX::PxShape* pShape = nullptr;
|
||||
PSX::PxGeometryHolder geoHolder = {};
|
||||
|
||||
@@ -78,21 +63,18 @@ const PSX::PxRigidDynamic* CPhysX_Manager::Add_DynamicActor(CRigidBody& RigidBod
|
||||
PSX::PxRigidBodyExt::updateMassAndInertia(*pActorDynamic, (PSX::PxReal)RigidBody.Get_Density());
|
||||
}
|
||||
|
||||
m_RigidBodys.emplace_back(&RigidBody, pActorDynamic);
|
||||
m_pScene->addActor(*pActorDynamic);
|
||||
Attach_Actor(RigidBody, *pActorDynamic);
|
||||
|
||||
return pActorDynamic;
|
||||
}
|
||||
|
||||
const PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody& RigidBody)
|
||||
PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody& RigidBody)
|
||||
{
|
||||
_matrix WorldMatrix = RigidBody.Get_TransformPtr()->Get_XMWorldMatrix();
|
||||
PSX::PxTransform pxWorldMatrix = XMWorldToPx_NoScale(WorldMatrix);
|
||||
|
||||
// PxRigidStatic 씬의 정적 바디 인터페이스
|
||||
PSX::PxRigidStatic* pActor = m_pPhysics->createRigidStatic(pxWorldMatrix);
|
||||
pActor->userData = &RigidBody;
|
||||
|
||||
PSX::PxShape* pShape = { nullptr };
|
||||
PSX::PxTriangleMesh* pPxMesh = Find_TriangleMesh(RigidBody.Get_PxMeshKey());
|
||||
PSX::PxTriangleMeshGeometry* pPxMeshGeometry = { nullptr };
|
||||
@@ -136,8 +118,8 @@ const PSX::PxRigidStatic* CPhysX_Manager::Add_StaticActor(CRigidBody& RigidBody)
|
||||
pShape->setContactOffset(RigidBody.Get_ContactOffset());
|
||||
pShape->setRestOffset(0.f);
|
||||
|
||||
m_RigidBodys.emplace_back(&RigidBody, pActor);
|
||||
m_pScene->addActor(*pActor);
|
||||
|
||||
Attach_Actor(RigidBody, *pActor);
|
||||
|
||||
return pActor;
|
||||
}
|
||||
@@ -330,15 +312,18 @@ void CPhysX_Manager::Update_Dynamic_ActiveActors()
|
||||
PSX::PxActor** ppActiveActors = m_pScene->getActiveActors(iNumActiveActor);
|
||||
|
||||
for (PSX::PxU32 i = 0; i < iNumActiveActor; ++i) {
|
||||
PhsXUserData* pUserData = (PhsXUserData*)ppActiveActors[i]->userData;
|
||||
PSX::PxRigidDynamic* pActorDynamic = ppActiveActors[i]->is<PSX::PxRigidDynamic>();
|
||||
|
||||
if (nullptr != pActorDynamic) {
|
||||
if (nullptr == ppActiveActors[i]->userData) {
|
||||
continue;
|
||||
}
|
||||
CTransform* pTransform = ((CRigidBody*)ppActiveActors[i]->userData)->Get_TransformPtr();
|
||||
CTransform* pTransform = pUserData->pOwner->Get_Component<CTransform>();
|
||||
|
||||
|
||||
// PSX::PxTransform pPrevPxTransform = pUserData->m_BeforeMatrix;
|
||||
// XMMatrixDecompose(nullptr, (_vector*)&pPrevPxTransform.q, (_vector*)&pPrevPxTransform.p, XMLoadFloat4x4(&pUserData->m_BeforeMatrix));
|
||||
|
||||
PSX::PxTransform pPrevPxTransform;
|
||||
PSX::PxTransform pPxTransform = pActorDynamic->getGlobalPose();
|
||||
_float3 vOriginalScale = pTransform->Get_Scale();
|
||||
_matrix WorldMatrix = {};
|
||||
@@ -354,21 +339,21 @@ void CPhysX_Manager::Update_Dynamic_ActiveActors()
|
||||
//}
|
||||
}
|
||||
|
||||
void CPhysX_Manager::Update_Dynamic_AllActors()
|
||||
{
|
||||
for (pair<CRigidBody*, PSX::PxActor*>& pairActors : m_RigidBodys) {
|
||||
PSX::PxRigidDynamic* pActorDynamic = pairActors.second->is<PSX::PxRigidDynamic>();
|
||||
if (nullptr != pActorDynamic) {
|
||||
CTransform* pTransform = ((CRigidBody*)(pActorDynamic->userData))->Get_TransformPtr();
|
||||
|
||||
PSX::PxTransform pxTransform = pActorDynamic->getGlobalPose();
|
||||
_float3 vOriginalScale = pTransform->Get_Scale();
|
||||
_matrix WorldMatrix = {};
|
||||
WorldMatrix = XMMatrixAffineTransformation(XMLoadFloat3(&vOriginalScale), XMVectorZero(), XMLoadFloat4((_float4*)&pxTransform.q), XMLoadFloat3((_float3*)&pxTransform.p));
|
||||
pTransform->Set_WorldMatrix(WorldMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
//void CPhysX_Manager::Update_Dynamic_AllActors()
|
||||
//{
|
||||
// for (pair<CRigidBody*, PSX::PxActor*>& pairActors : m_RigidBodys) {
|
||||
// PSX::PxRigidDynamic* pActorDynamic = pairActors.second->is<PSX::PxRigidDynamic>();
|
||||
// if (nullptr != pActorDynamic) {
|
||||
// CTransform* pTransform = ((CRigidBody*)(pActorDynamic->userData))->Get_TransformPtr();
|
||||
//
|
||||
// PSX::PxTransform pxTransform = pActorDynamic->getGlobalPose();
|
||||
// _float3 vOriginalScale = pTransform->Get_Scale();
|
||||
// _matrix WorldMatrix = {};
|
||||
// WorldMatrix = XMMatrixAffineTransformation(XMLoadFloat3(&vOriginalScale), XMVectorZero(), XMLoadFloat4((_float4*)&pxTransform.q), XMLoadFloat3((_float3*)&pxTransform.p));
|
||||
// pTransform->Set_WorldMatrix(WorldMatrix);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
void CPhysX_Manager::ClearScene()
|
||||
{
|
||||
@@ -376,6 +361,32 @@ void CPhysX_Manager::ClearScene()
|
||||
pObject.second->release();
|
||||
} m_RigidBodys.clear();
|
||||
}
|
||||
void CPhysX_Manager::Attach_Actor(CRigidBody& RigidBody, PSX::PxActor& Actor)
|
||||
{
|
||||
if (m_pScene == nullptr){
|
||||
return;
|
||||
}
|
||||
|
||||
m_RigidBodys.emplace_back(&RigidBody, &Actor);
|
||||
m_pScene->addActor(Actor);
|
||||
}
|
||||
|
||||
void CPhysX_Manager::Detach_Actor(CRigidBody& RigidBody, PSX::PxActor*& pActor)
|
||||
{
|
||||
if (m_pScene == nullptr){
|
||||
return;
|
||||
}
|
||||
|
||||
list<pair<CRigidBody*, PSX::PxActor*>>::iterator iter = m_RigidBodys.begin();
|
||||
for (; iter != m_RigidBodys.end(); ++iter){
|
||||
if ((*iter).second == pActor) {
|
||||
m_RigidBodys.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_pScene->removeActor(*pActor);
|
||||
}
|
||||
|
||||
PSX::PxController* CPhysX_Manager::Add_CapsuleController(PSX::PxCapsuleControllerDesc& Desc)
|
||||
{
|
||||
@@ -433,7 +444,6 @@ HRESULT CPhysX_Manager::Initialize()
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
||||
{ // 씬 세팅
|
||||
m_ToleranceScale.length = 1.f; // 1 meter
|
||||
m_ToleranceScale.speed = GRAVITY; //
|
||||
@@ -453,17 +463,42 @@ HRESULT CPhysX_Manager::Initialize()
|
||||
return E_FAIL;
|
||||
}
|
||||
sceneDesc.cpuDispatcher = m_pDispatcher;
|
||||
//sceneDesc.simulationEventCallback = ; // fetchResults 때 불림. 아래 필터랑, pair랑 같이 짝꿍임. 좀 더 공부해야 쓸 수 있을듯;;
|
||||
sceneDesc.filterShader = PSX::PxDefaultSimulationFilterShader; // 레이어 충돌, 오브젝트에 속성을 주고 복잡한 필터링 충돌 식
|
||||
sceneDesc.flags =
|
||||
PSX::PxSceneFlag::eENABLE_PCM // 기본 true, 현대적인 충돌시스템 적용
|
||||
| PSX::PxSceneFlag::eENABLE_ACTIVE_ACTORS // 현재 움직임이 있는 액터만 가져옴
|
||||
| PSX::PxSceneFlag::eEXCLUDE_KINEMATICS_FROM_ACTIVE_ACTORS // 그중에 키네틱은 뺌
|
||||
| PSX::PxSceneFlag::eENABLE_CCD // CCD 기본플래그, 키면 비쌈. 단일오브젝트만 켤 수 있으니 선택적으로 고려
|
||||
| PSX::PxSceneFlag::eDISABLE_CCD_RESWEEP // CCD 옵션플래그, 정확도 낮추고 비용 아낌
|
||||
//| PSX::PxSceneFlag::eDISABLE_CONTACT_REPORT_BUFFER_RESIZE // 접촉 리포트버퍼 리사이즈 금지 -> 보통 끔
|
||||
//| PSX::PxSceneFlag::eDISABLE_CONTACT_CACHE // 접촉 캐시를 금지 -> 그냥 켜두자, 캐시 있는게 보통 더 낫다
|
||||
//| PSX::PxSceneFlag::eREQUIRE_RW_LOCK // 멀티스레딩 환경에서 혹시라도 락 걸고 접근하지 않아 발생할 일을 제거,
|
||||
//| PSX::PxSceneFlag::eENABLE_STABILIZATION // 물체가 얽힌 상황에서 불안정한걸 방지. 추가비용인듯
|
||||
//| PSX::PxSceneFlag::eENABLE_AVERAGE_POINT // 이해 못하겠음
|
||||
//| PSX::PxSceneFlag::eEnable_GPU_Dynamics // 피직스 그래픽가속 설정. 여기선 세팅 안돼서 비활성화ㅏ
|
||||
//| PSX::PxSceneFlag::eEnable_Direct_GPU_API // 직접 그래픽버퍼를 다루게끔 설정
|
||||
//| PSX::PxSceneFlag::eEnable_Enhanced_Determinism // 중간에 액터 추가해도 결과가 바뀌지 않는 결정론 수준 향상, 리플레이기능 ㅇㅇ
|
||||
//| PSX::PxSceneFlag::eENABLE_FRICTION_EVERY_ITERATION // 마찰 꼐산 추가
|
||||
//| PSX::PxSceneFlag::eENABLE_EXTERNAL_FORCES_EVERY_ITERATION_TGS // 중력 나눠서 여러번 적용
|
||||
//| PSX::PxSceneFlag::eENABLE_PCM // 기본 true
|
||||
//| PSX::PxSceneFlag::eENABLE_BODY_ACCELERATIONS // 선형 각가속도 값을 쿼리가능하도록 설정
|
||||
//| PSX::PxSceneFlag::eEnable_solver_residual_reporting // 고급 디버깅, 연구 용
|
||||
//| PSX::PxSceneFlag::eSOLVE_ARTICULATION_CONTACT_LAST 물리 관절 처리 시나리오 순서 변경
|
||||
;
|
||||
|
||||
sceneDesc.filterShader = PSX::PxDefaultSimulationFilterShader;
|
||||
|
||||
sceneDesc.flags = PSX::PxSceneFlag::eENABLE_PCM | PSX::PxSceneFlag::eENABLE_CCD| PSX::PxSceneFlag::eENABLE_ACTIVE_ACTORS | PSX::PxSceneFlag::eEXCLUDE_KINEMATICS_FROM_ACTIVE_ACTORS;
|
||||
if (false == sceneDesc.isValid()) {
|
||||
assert(false);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
m_pScene = m_pPhysics->createScene(sceneDesc);
|
||||
|
||||
// CCT
|
||||
m_pCCTManager = PxCreateControllerManager(*m_pScene);
|
||||
m_pCCTManager->setOverlapRecoveryModule(false);
|
||||
m_pCCTManager->setOverlapRecoveryModule(true); // 복구모듈은 하이트필드에는 적용되지 않음, 오직 스태틱만 대상
|
||||
m_pCCTManager->setPreciseSweeps(true); // 정밀 스윕
|
||||
m_pCCTManager->setPreventVerticalSlidingAgainstCeiling(false); // 천장타고 슬라이딩 허용 비허용
|
||||
}
|
||||
|
||||
// 디버그서버의 클라 세팅
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "pch.h"
|
||||
#include "pch.h"
|
||||
#include "Picking.h"
|
||||
#include "GameInstance.h"
|
||||
|
||||
@@ -7,9 +7,9 @@ CPicking::CPicking(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
, m_pContext{ pContext }
|
||||
, m_pGameInstance{ CGameInstance::GetInstance() }
|
||||
{
|
||||
Safe_AddRef(m_pDevice);
|
||||
Safe_AddRef(m_pContext);
|
||||
Safe_AddRef(m_pGameInstance);
|
||||
SAFE_ADDREF(m_pDevice);
|
||||
SAFE_ADDREF(m_pContext);
|
||||
SAFE_ADDREF(m_pGameInstance);
|
||||
}
|
||||
|
||||
HRESULT CPicking::Initialize(HWND hWnd, _uint iSizeX, _uint iSizeY)
|
||||
@@ -90,7 +90,7 @@ CPicking* CPicking::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext,
|
||||
if (FAILED(pInstance->Initialize(hWnd, iSizeX, iSizeY)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CPicking");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -100,9 +100,9 @@ void CPicking::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Release(m_pDevice);
|
||||
Safe_Release(m_pContext);
|
||||
Safe_Release(m_pTexture2D);
|
||||
Safe_Release(m_pGameInstance);
|
||||
SAFE_RELEASE(m_pDevice);
|
||||
SAFE_RELEASE(m_pContext);
|
||||
SAFE_RELEASE(m_pTexture2D);
|
||||
SAFE_RELEASE(m_pGameInstance);
|
||||
Safe_Delete_Array(m_pPixels);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "pch.h"
|
||||
#include "pch.h"
|
||||
#include "Shader.h"
|
||||
|
||||
CShader::CShader(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
||||
@@ -19,10 +19,10 @@ CShader::CShader(const CShader& rhs)
|
||||
, m_iNumElements{ rhs.m_iNumElements }
|
||||
#endif
|
||||
{
|
||||
Safe_AddRef(m_pEffect);
|
||||
SAFE_ADDREF(m_pEffect);
|
||||
|
||||
for (auto& pInputLayout : m_InputLayouts)
|
||||
Safe_AddRef(pInputLayout);
|
||||
SAFE_ADDREF(pInputLayout);
|
||||
}
|
||||
|
||||
HRESULT CShader::Initialize_Prototype(const _tchar* pShaderFilePath, const D3D11_INPUT_ELEMENT_DESC* pElements, _uint iNumElements)
|
||||
@@ -153,8 +153,8 @@ HRESULT CShader::CreateShader(const _tchar* pShaderFilePath, const D3D11_INPUT_E
|
||||
if (FAILED(m_pDevice->CreateInputLayout(
|
||||
pElements,
|
||||
iNumElements,
|
||||
PassDesc.pIAInputSignature/*쉐이더에서 받아줄수 있는 정점의 정보*/,
|
||||
PassDesc.IAInputSignatureSize/*쉐이더에서 받아줄수 있는 정점의 멤버변수갯수*/,
|
||||
PassDesc.pIAInputSignature/*���̴����� ���ټ� �ִ� ������ ����*/,
|
||||
PassDesc.IAInputSignatureSize/*���̴����� ���ټ� �ִ� ������ �����������*/,
|
||||
&pInputLayout)))
|
||||
return E_FAIL;
|
||||
|
||||
@@ -167,7 +167,7 @@ HRESULT CShader::CreateShader(const _tchar* pShaderFilePath, const D3D11_INPUT_E
|
||||
|
||||
HRESULT CShader::Shader_Refresh()
|
||||
{
|
||||
// 내 인풋 레이아웃 이펙트 소멸시키고
|
||||
// �� ��Dz ���̾ƿ� ����Ʈ �Ҹ��Ű��
|
||||
Safe_Release(m_pEffect);
|
||||
|
||||
for (auto& pInputLayout : m_InputLayouts)
|
||||
@@ -176,7 +176,7 @@ HRESULT CShader::Shader_Refresh()
|
||||
m_InputLayouts.clear();
|
||||
|
||||
|
||||
//그 경로로 재 생성한다.
|
||||
//�� ��η� �� �����Ѵ�.
|
||||
if (FAILED(CreateShader(m_strShaderPath.c_str(), m_pElements, m_iNumElements)))
|
||||
return E_FAIL;
|
||||
|
||||
@@ -193,8 +193,8 @@ HRESULT CShader::Begin(_uint iPassIndex)
|
||||
|
||||
m_pContext->IASetInputLayout(m_InputLayouts[iPassIndex]);
|
||||
|
||||
/* Apply를 반드시 호출해야만 쉐이더로 그려진다. */
|
||||
/* Apply이전에 쉐이더에 전달할 모든 데이터들을 다 던져놓아야한다. */
|
||||
/* Apply�� �ݵ�� ȣ���ؾ߸� ���̴��� ������. */
|
||||
/* Apply������ ���̴��� ������ ��� �����͵��� �� �������ƾ��Ѵ�. */
|
||||
m_pEffect->GetTechniqueByIndex(0)->GetPassByIndex(iPassIndex)->Apply(0, m_pContext);
|
||||
|
||||
return S_OK;
|
||||
@@ -207,7 +207,7 @@ CShader* CShader::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, c
|
||||
if (FAILED(pInstance->Initialize_Prototype(pShaderFilePath, pElements, iNumElements)))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CShader");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -220,7 +220,7 @@ CComponent* CShader::Clone(void* pArg, class CGameObject* pOwner)
|
||||
if (FAILED(pInstance->Initialize(pArg)))
|
||||
{
|
||||
MSG_BOX("Failed to Cloned : CShader");
|
||||
Safe_Release(pInstance);
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
@@ -230,10 +230,10 @@ void CShader::Free()
|
||||
{
|
||||
__super::Free();
|
||||
|
||||
Safe_Release(m_pEffect);
|
||||
SAFE_RELEASE(m_pEffect);
|
||||
|
||||
for (auto& pInputLayout : m_InputLayouts)
|
||||
Safe_Release(pInputLayout);
|
||||
SAFE_RELEASE(pInputLayout);
|
||||
|
||||
m_InputLayouts.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user