22#include " Core/Core.h"
33#include " Core/Renderer/ResourceManager.h"
44#include " Core/Renderer/DescriptorHeap.h"
5+ #include " Core/Scene/SceneManager.h"
6+
57
68Mesh::Mesh (std::string name, Transform& parentTransform) : Component::Component(name) {
79 this ->m_core = Core::GetInstance ();
10+ this ->m_sceneMgr = SceneManager::GetInstance ();
811
912 this ->m_dev = nullptr ;
1013 this ->m_list = nullptr ;
@@ -28,12 +31,19 @@ Mesh::Mesh(std::string name, Transform& parentTransform) : Component::Component(
2831 this ->m_wvp .World *= XMMatrixTranspose (XMMatrixRotationY (XMConvertToRadians (this ->m_transform .rotation .y )));
2932 this ->m_wvp .World *= XMMatrixTranspose (XMMatrixRotationZ (XMConvertToRadians (this ->m_transform .rotation .z )));
3033
31- this ->m_wvp .View = XMMatrixTranspose (XMMatrixIdentity () * XMMatrixTranslation ( 0 . f , 0 . f , 2 . f ) );
34+ this ->m_wvp .View = XMMatrixTranspose (XMMatrixIdentity ());
3235 this ->m_wvp .Projection = XMMatrixTranspose (XMMatrixPerspectiveFovLH (XMConvertToRadians (90 .f ), static_cast <float >(nWidth) / static_cast <float >(nHeight), 0 .01f , 3000 .f ));
3336}
3437
3538void Mesh::Init () {
3639 Component::Init ();
40+ Transform cameraTransform = this ->m_sceneMgr ->GetCurrentScene ()->GetCurrentCamera ()->transform ;
41+ this ->m_wvp .View = XMMatrixTranspose (XMMatrixIdentity ());
42+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixTranslation (cameraTransform.location .x , cameraTransform.location .y , cameraTransform.location .z ));
43+
44+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationX (XMConvertToRadians (cameraTransform.rotation .x )));
45+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationY (XMConvertToRadians (cameraTransform.rotation .y )));
46+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationZ (XMConvertToRadians (cameraTransform.rotation .z )));
3747
3848 if (D3D12* d3d12 = dynamic_cast <D3D12*>(this ->m_renderer )) {
3949 this ->D3D12Init (d3d12);
@@ -107,7 +117,14 @@ void Mesh::UpdateConstantBuffer() {
107117 this ->m_wvp .World *= XMMatrixTranspose (XMMatrixRotationY (XMConvertToRadians (this ->m_transform .rotation .y )));
108118 this ->m_wvp .World *= XMMatrixTranspose (XMMatrixRotationZ (XMConvertToRadians (this ->m_transform .rotation .z )));
109119
110- this ->m_wvp .View = XMMatrixTranspose (XMMatrixIdentity () * XMMatrixTranslation (0 .f , 0 .f , 2 .f ));
120+ Transform cameraTransform = this ->m_sceneMgr ->GetCurrentScene ()->GetCurrentCamera ()->transform ;
121+ this ->m_wvp .View = XMMatrixTranspose (XMMatrixIdentity ());
122+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixTranslation (cameraTransform.location .x , cameraTransform.location .y , cameraTransform.location .z ));
123+
124+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationX (XMConvertToRadians (cameraTransform.rotation .x )));
125+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationY (XMConvertToRadians (cameraTransform.rotation .y )));
126+ this ->m_wvp .View *= XMMatrixTranspose (XMMatrixRotationZ (XMConvertToRadians (cameraTransform.rotation .z )));
127+
111128 // this->m_wvp.Projection = XMMatrixTranspose(XMMatrixPerspectiveLH(XMConvertToRadians(90.f), static_cast<float>(nWidth) / static_cast<float>(nHeight), 0.01f, 3000.f));
112129
113130 PVOID pData;
0 commit comments