171 lines
3.9 KiB
C++
171 lines
3.9 KiB
C++
#include "pch.h"
|
|
#include "TriggerBox.h"
|
|
#include "Layer.h"
|
|
#include "Player.h"
|
|
|
|
CTriggerBox::CTriggerBox(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
|
|
: CGameObject(pDevice, pContext)
|
|
{
|
|
}
|
|
|
|
CTriggerBox::CTriggerBox(const CTriggerBox& rhs)
|
|
: CGameObject(rhs)
|
|
{
|
|
}
|
|
|
|
HRESULT CTriggerBox::TryScanArea(_float fTimeDelta)
|
|
{
|
|
#ifdef _DEBUG
|
|
if (false == m_bRender) {
|
|
m_bRender = true;
|
|
m_pGameInstance->Add_RenderGroup(RENDER::NONLIGHT, this);
|
|
}
|
|
#endif // _DEBUG
|
|
m_vScanTimer.x += fTimeDelta;
|
|
if (m_vScanTimer.x > m_vScanTimer.y) {
|
|
m_vScanTimer.x = m_vScanTimer.y;
|
|
return Scan();
|
|
}
|
|
return E_FAIL;
|
|
}
|
|
|
|
HRESULT CTriggerBox::Render()
|
|
{
|
|
#ifdef _DEBUG
|
|
m_Batch->Begin();
|
|
|
|
_matrix ViewMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::VIEW);
|
|
_matrix ProjMatrix = m_pGameInstance->Get_Transform_Matrix(D3DTS::PROJ);
|
|
_vector vColor = CMyTools::ColorRGB_A_HEXtoVECTOR(0xff0f0f, CMyTools::Saturate(m_vScanTimer.x / m_vScanTimer.y + 0.1f));
|
|
m_pSubShape->Draw(m_pTransformCom->Get_XMWorldMatrix(), ViewMatrix, ProjMatrix, vColor, nullptr, true);
|
|
|
|
m_Batch->End();
|
|
m_bRender = false;
|
|
#endif // _DEBUG
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
HRESULT CTriggerBox::Initialize(TRIGGERBOX_DESC* pDesc)
|
|
{
|
|
CTransform::TRANSFORM_DESC Desc{};
|
|
Desc.fRadius = pDesc->vPosition_Radius.w;
|
|
Desc.fRotationPerSec = 0;
|
|
Desc.fSpeedPerSec = 0;
|
|
if (FAILED(__super::Ready_Components(&Desc))) {
|
|
return E_FAIL;
|
|
}
|
|
m_pTransformCom->Set_State(STATE::POSITION, XMVectorSetW(XMLoadFloat4(&pDesc->vPosition_Radius), 1.f));
|
|
|
|
#ifdef _DEBUG
|
|
m_pSubShape = (GeometricPrimitive::CreateSphere(m_pContext, m_pTransformCom->Get_Radius() * 2.f, 12, false, false));
|
|
m_Batch = make_unique<PrimitiveBatch<VertexPositionColor>>(m_pContext);
|
|
#endif // _DEBUG
|
|
|
|
|
|
_float3 vScale = { Desc.fRadius * 2.f, Desc.fRadius * 2.f, Desc.fRadius * 2.f };
|
|
m_pTransformCom->Set_Scale(vScale);
|
|
m_vScanTimer.y += m_pGameInstance->Real_Random_Float(0.f, 0.2f);
|
|
return S_OK;
|
|
}
|
|
|
|
HRESULT CTriggerBox::Scan()
|
|
{
|
|
_float fRadius = m_pTransformCom->Get_Radius();
|
|
|
|
PSX::PxOverlapBufferN<32> pxBuffer = {};
|
|
_bool bHit = m_pGameInstance->Overlap(fRadius, m_pTransformCom->Get_State(STATE::POSITION),
|
|
PSX::PxQueryFlag::eDYNAMIC | PSX::PxQueryFlag::eNO_BLOCK, pxBuffer);
|
|
|
|
|
|
PSX::PxOverlapHit & hit = pxBuffer.block;
|
|
PSX::PxRigidActor* pActor = hit.actor;
|
|
_uint iHitCount = pxBuffer.getNbTouches();
|
|
HRESULT hr = E_FAIL;
|
|
if (bHit) {
|
|
hr = CheckPlayerHit(pActor, hit.shape);
|
|
if (FAILED(hr)) {
|
|
for (_uint i = 0; i < iHitCount; ++i) {
|
|
PSX::PxOverlapHit* pHit = &pxBuffer.touches[i];
|
|
hr = CheckPlayerHit(pHit->actor, pHit->shape);
|
|
if (SUCCEEDED(hr)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return hr;
|
|
}
|
|
|
|
HRESULT CTriggerBox::CheckPlayerHit(PSX::PxActor* pActor, PSX::PxShape* pShape)
|
|
{
|
|
if (nullptr != pActor && nullptr != pActor->userData || nullptr != pShape && nullptr != pShape->userData)
|
|
{
|
|
PHYSX_USERDATA* pUserData = static_cast<PHYSX_USERDATA*>(pActor->userData);
|
|
if (nullptr == pUserData) {
|
|
pUserData = static_cast<PHYSX_USERDATA*>(pShape->userData);
|
|
}
|
|
switch (pUserData->eKind)
|
|
{
|
|
case PHYSX_KIND::BODY_DYNAMIC:
|
|
{
|
|
switch (PXOBJECT(pUserData->iSubKind))
|
|
{
|
|
case PXOBJECT::PLAYER:
|
|
{
|
|
return S_OK;
|
|
}break;
|
|
default:
|
|
break;
|
|
}
|
|
}break;
|
|
case PHYSX_KIND::CCTActor:
|
|
{
|
|
switch (PXOBJECT(pUserData->iSubKind))
|
|
{
|
|
case PXOBJECT::PLAYER: {
|
|
return S_OK;
|
|
} break;
|
|
default:
|
|
break;
|
|
}
|
|
} break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return E_FAIL;
|
|
}
|
|
|
|
CTriggerBox* CTriggerBox::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, TRIGGERBOX_DESC* Desc)
|
|
{
|
|
CTriggerBox* pInstance = new CTriggerBox(pDevice, pContext);
|
|
|
|
if (FAILED(pInstance->Initialize(Desc))) {
|
|
SAFE_RELEASE(pInstance);
|
|
}
|
|
return pInstance;
|
|
}
|
|
|
|
void CTriggerBox::Free()
|
|
{
|
|
__super::Free();
|
|
}
|
|
|
|
HRESULT CTriggerBox::Bind_ShaderResources()
|
|
{
|
|
return E_NOTIMPL;
|
|
}
|
|
|
|
CGameObject* CTriggerBox::Clone(void* pArg, CGameObject* pOwner)
|
|
{
|
|
return nullptr;
|
|
}
|
|
#ifdef _DEBUG
|
|
void CTriggerBox::Describe_Entity()
|
|
{
|
|
}
|
|
#endif // _DEBUG
|
|
|
|
|