#include "pch.h" #include "Wand.h" #include "GameInstance.h" #include "TrailObject.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 (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(g_iStaticLevel, NEXT_LEVEL, TEXT("Layer_Trail"), &PartsDesc, this , &pTrail))) { assert(false); return E_FAIL; } if (FAILED(pTrail->Load_Trail("../Bin/Resources/Data/Effect/Decendo/Proj_Trail" , static_cast(NEXT_LEVEL)))) return E_FAIL; pTrail->Set_Target(m_pModelCom->Get_BoneMatrixPtr("root" ), XMVectorSet(0.f, 1.f, 0.f , 0.f)); 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())); //_float3 Scale = _float3(10.f, 10.f, 10.f); //m_pTransformCom->Set_Scale(Scale); } void CWand::Update(_float fTimeDelta) { } 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(&m_pModelCom)))) return E_FAIL; /* Com_Shader */ if (FAILED(__super::Add_Asset_Component(g_iStaticLevel, FX_MESH, reinterpret_cast(&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); } #ifdef _DEBUG void CWand::Describe_Entity() { } #endif // _DEBUG