Files
Hogwarts_Legacy/Jusin154_Team3D/Client/Private/Wand.cpp
T
2025-11-25 22:07:18 +09:00

224 lines
4.7 KiB
C++

#include "pch.h"
#include "Wand.h"
#include "GameInstance.h"
#include "TrailObject.h"
#include "EffectParts.h"
CWand::CWand(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
: CPartObject(pDevice, pContext)
{
}
CWand::CWand(const CWand& Prototype)
: CPartObject(Prototype)
{
}
HRESULT CWand::Initialize_Prototype()
{
return S_OK;
}
HRESULT CWand::Initialize(void* pArg)
{
WAND_DESC* pDesc = static_cast<WAND_DESC*> (pArg);
m_pSocketMatrices = pDesc->pSocketMatrices;
if (FAILED(__super::Initialize(pArg)))
return E_FAIL;
if (FAILED(Ready_Components()))
return E_FAIL;
CPartObject::PARTOBJECT_DESC PartsDesc{};
PartsDesc.pParentTransform = m_pTransformCom;
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CTrailObject>(g_iStaticLevel, NEXT_LEVEL, TEXT("Layer_Trail"), &PartsDesc, this , &m_pTrail))) {
assert(false);
return E_FAIL;
}
if (FAILED(m_pTrail->Load_Trail("../Bin/Resources/Data/Effect/Trail/Bombard_Trail" , static_cast<LEVEL>(NEXT_LEVEL))))
return E_FAIL;
if (FAILED(m_pGameInstance->Add_GameObject_ToLayer<CEffectParts>(g_iStaticLevel, NEXT_LEVEL, TEXT("Layer_Trail"), &PartsDesc, this, &m_pEffectParts))) {
assert(false);
return E_FAIL;
}
m_pEffectParts->Load("../Bin/Resources/Data/Effect/Lumos/Lumos", static_cast<LEVEL>(NEXT_LEVEL));
m_pEffectParts->Set_Visible(true);
return S_OK;
}
void CWand::Priority_Update(_float fTimeDelta)
{
_matrix socketMatrix = {};
socketMatrix = XMLoadFloat4x4(m_pSocketMatrices);
for (int i = 0; i < 3; ++i) {
socketMatrix.r[i] = XMVector3Normalize(socketMatrix.r[i]);
}
m_pTransformCom->Set_WorldMatrix(socketMatrix * XMLoadFloat4x4(m_pParentTransformCom->Get_WorldMatrixPtr()));
Describe_Entity();
}
void CWand::Update(_float fTimeDelta)
{
//m_pTrail->Trail_Update(CombinedMat, fTimeDelta);
m_pModelCom->Combined_BoneMatrix();
_matrix BoneMatrix = XMLoadFloat4x4(m_pModelCom->Get_BoneMatrixPtr("Effect"));
BoneMatrix = BoneMatrix * m_pTransformCom->Get_XMWorldMatrix();
BoneMatrix.r[3] += XMVector3Normalize(BoneMatrix.r[0]) * m_vOffset.x;
BoneMatrix.r[3] += XMVector3Normalize(BoneMatrix.r[1]) * m_vOffset.y;
BoneMatrix.r[3] += XMVector3Normalize(BoneMatrix.r[2]) * m_vOffset.z;
m_pEffectParts->Get_Component<CTransform>()->Set_WorldMatrix(BoneMatrix);
}
void CWand::Late_Update(_float fTimeDelta)
{
m_pGameInstance->Add_RenderGroup(RENDER::BLEND, this);
}
HRESULT CWand::Render()
{
if (!m_pModelCom)
return S_OK;
if (FAILED(Bind_ShaderResources())) {
return E_FAIL;
}
_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->Begin(ENUM_CLASS(SHADER_PASS_ANIM::DEFAULT)))) {
return E_FAIL;
}
if (FAILED(m_pModelCom->Render(i))) {
return E_FAIL;
}
}
return S_OK;
}
HRESULT CWand::Ready_Components()
{
__super::Ready_Components(nullptr);
/* Com_Model */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, TEXT("Prototype_Component_Wand_Model"),
reinterpret_cast<CComponent**>(&m_pModelCom))))
return E_FAIL;
/* Com_Shader */
if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_MESH,
reinterpret_cast<CComponent**>(&m_pShaderCom))))
return E_FAIL;
return S_OK;
}
HRESULT CWand::Bind_ShaderResources()
{
if (FAILED(m_pShaderCom->Bind_Matrix("g_WorldMatrix", m_pTransformCom->Get_WorldMatrixPtr()))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrix("g_ViewMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::VIEW)))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_Matrix("g_ProjMatrix", m_pGameInstance->Get_Transform_Float4x4(D3DTS::PROJ)))) {
return E_FAIL;
}
if (FAILED(m_pShaderCom->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
return E_FAIL;
}
return S_OK;
}
CWand* CWand::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
{
CWand* pInstance = new CWand(pDevice, pContext);
if (FAILED(pInstance->Initialize_Prototype()))
{
MSG_BOX("Failed to Created : CWand");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
CGameObject* CWand::Clone(void* pArg, CGameObject* pOwner)
{
CWand* pInstance = new CWand(*this);
pInstance->m_pOwner = pOwner;
if (FAILED(pInstance->Initialize(pArg)))
{
MSG_BOX("Failed to Cloned : CWand");
SAFE_RELEASE(pInstance);
}
return pInstance;
}
void CWand::Free()
{
__super::Free();
SAFE_RELEASE(m_pShaderCom);
SAFE_RELEASE(m_pModelCom);
SAFE_RELEASE(m_pEffectParts);
SAFE_RELEASE(m_pTrail);
}
#ifdef _DEBUG
void CWand::Describe_Entity()
{
GUI::Begin("VALUE");
_float4 vValue = {};
if (GUI::InputFloat3("OFFSET", (_float*)&m_vOffset))
{
}
GUI::End();
}
#endif // _DEBUG