[add] Frustum to Pipeline
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "pch.h"
|
||||
#include "pch.h"
|
||||
#include "PipeLine.h"
|
||||
|
||||
CPipeLine::CPipeLine()
|
||||
@@ -30,6 +30,42 @@ const _vector CPipeLine::Get_CamXMPosition()
|
||||
return XMLoadFloat4(&m_vCamPosition);
|
||||
}
|
||||
|
||||
void CPipeLine::Transform_Frustum_ToLocalSpace(_fmatrix WorldMatrixInverse)
|
||||
{
|
||||
_float4 vLocalPoints[8] = {};
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
XMStoreFloat4(&vLocalPoints[i],
|
||||
XMVector3TransformCoord(XMLoadFloat4(&m_vWorldPoints[i]), WorldMatrixInverse));
|
||||
}
|
||||
|
||||
Make_Planes(vLocalPoints, m_vLocalPlanes);
|
||||
}
|
||||
|
||||
_bool CPipeLine::isIn_WorldFrustum(_fvector vWorldPos, _float fRadius)
|
||||
{
|
||||
return true;
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
{
|
||||
if (fRadius < XMVectorGetX(XMPlaneDotCoord(XMLoadFloat4(&m_vWorldPlanes[i]), vWorldPos)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_bool CPipeLine::isIn_LocalFrustum(_fvector vLocalPos, _float fRadius)
|
||||
{
|
||||
return true;
|
||||
for (size_t i = 0; i < 6; i++)
|
||||
{
|
||||
if (fRadius < XMVectorGetX(XMPlaneDotCoord(XMLoadFloat4(&m_vLocalPlanes[i]), vLocalPos)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPipeLine::Update()
|
||||
{
|
||||
for (_uint i = ENUM_CLASS(D3DTS::VIEW_INV); i < ENUM_CLASS(D3DTS::END); ++i)
|
||||
@@ -38,11 +74,53 @@ void CPipeLine::Update()
|
||||
}
|
||||
|
||||
memcpy(&m_vCamPosition, &m_TransformStateMatrices[ENUM_CLASS(D3DTS::VIEW_INV)].m[3], sizeof(_float4));
|
||||
_matrix ProjInvMatrix = XMLoadFloat4x4(&m_TransformStateMatrices[ENUM_CLASS(D3DTS::PROJ_INV)]);
|
||||
_matrix ViewInvMatrix = XMLoadFloat4x4(&m_TransformStateMatrices[ENUM_CLASS(D3DTS::VIEW_INV)]);
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
XMStoreFloat4(&m_vWorldPoints[i], XMVector3TransformCoord(XMLoadFloat4(&m_vOriginalPoints[i]), ProjInvMatrix));
|
||||
XMStoreFloat4(&m_vWorldPoints[i], XMVector3TransformCoord(XMLoadFloat4(&m_vWorldPoints[i]), ViewInvMatrix));
|
||||
}
|
||||
|
||||
Make_Planes(m_vWorldPoints, m_vWorldPlanes);
|
||||
}
|
||||
|
||||
HRESULT CPipeLine::Initialize()
|
||||
{
|
||||
m_vOriginalPoints[0] = _float4(-1.f, 1.f, 0.f, 1.f); // LT
|
||||
m_vOriginalPoints[1] = _float4(1.f, 1.f, 0.f, 1.f); // RT
|
||||
m_vOriginalPoints[2] = _float4(1.f, -1.f, 0.f, 1.f); // RB
|
||||
m_vOriginalPoints[3] = _float4(-1.f, -1.f, 0.f, 1.f); // LB
|
||||
|
||||
m_vOriginalPoints[4] = _float4(-1.f, 1.f, 1.f, 1.f); // LT
|
||||
m_vOriginalPoints[5] = _float4(1.f, 1.f, 1.f, 1.f); // RT
|
||||
m_vOriginalPoints[6] = _float4(1.f, -1.f, 1.f, 1.f); // RB
|
||||
m_vOriginalPoints[7] = _float4(-1.f, -1.f, 1.f, 1.f); // LB
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CPipeLine::Make_Planes(const _float4* pPoints, _float4* pPlanes)
|
||||
{
|
||||
XMStoreFloat4(&pPlanes[0], XMPlaneFromPoints(XMLoadFloat4(&pPoints[1]), XMLoadFloat4(&pPoints[5]), XMLoadFloat4(&pPoints[6])));
|
||||
XMStoreFloat4(&pPlanes[1], XMPlaneFromPoints(XMLoadFloat4(&pPoints[4]), XMLoadFloat4(&pPoints[0]), XMLoadFloat4(&pPoints[3])));
|
||||
XMStoreFloat4(&pPlanes[2], XMPlaneFromPoints(XMLoadFloat4(&pPoints[4]), XMLoadFloat4(&pPoints[5]), XMLoadFloat4(&pPoints[1])));
|
||||
XMStoreFloat4(&pPlanes[3], XMPlaneFromPoints(XMLoadFloat4(&pPoints[3]), XMLoadFloat4(&pPoints[2]), XMLoadFloat4(&pPoints[6])));
|
||||
XMStoreFloat4(&pPlanes[4], XMPlaneFromPoints(XMLoadFloat4(&pPoints[5]), XMLoadFloat4(&pPoints[4]), XMLoadFloat4(&pPoints[7])));
|
||||
XMStoreFloat4(&pPlanes[5], XMPlaneFromPoints(XMLoadFloat4(&pPoints[0]), XMLoadFloat4(&pPoints[1]), XMLoadFloat4(&pPoints[2])));
|
||||
}
|
||||
|
||||
CPipeLine* CPipeLine::Create()
|
||||
{
|
||||
return new CPipeLine();
|
||||
CPipeLine* pInstance = new CPipeLine();
|
||||
|
||||
if (FAILED(pInstance->Initialize()))
|
||||
{
|
||||
MSG_BOX("Failed to Created : CPipeLine");
|
||||
SAFE_RELEASE(pInstance);
|
||||
}
|
||||
|
||||
return pInstance;
|
||||
}
|
||||
void CPipeLine::Free()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user