diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index ce93324..5466f30 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -51,6 +51,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) char fpsString[32]; bool result; + m_screenWidth = screenWidth; + m_screenHeight = screenHeight; // Create the Direct3D object. m_Direct3D = new D3DClass; @@ -725,7 +727,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) } // Construct the frustum. - m_Frustum->ConstructFrustum(viewMatrix, projectionMatrix, SCREEN_DEPTH); + m_Frustum->ConstructFrustum(viewMatrix, projectionMatrix, SCREEN_DEPTH, m_screenWidth, m_screenHeight); // Get the number of models that will be rendered. modelCount = m_ModelList->GetModelCount(); diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index f1eeca8..d3e0599 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -93,6 +93,7 @@ private: XMMATRIX m_baseViewMatrix; RenderTextureClass* m_RenderTexture; DisplayPlaneClass* m_DisplayPlane; + float m_screenWidth, m_screenHeight; }; #endif diff --git a/enginecustom/frustumclass.cpp b/enginecustom/frustumclass.cpp index 4f69feb..042ca36 100644 --- a/enginecustom/frustumclass.cpp +++ b/enginecustom/frustumclass.cpp @@ -15,12 +15,21 @@ FrustumClass::~FrustumClass() { } -void FrustumClass::ConstructFrustum(XMMATRIX viewMatrix, XMMATRIX projectionMatrix, float screenDepth) +void FrustumClass::ConstructFrustum(XMMATRIX viewMatrix, XMMATRIX projectionMatrix, float screenDepth, float screenWidth, float screenHeight) { XMMATRIX finalMatrix; XMFLOAT4X4 projMatrix, matrix; float zMinimum, r, t; + // Augmenter la taille de la zone de frustum en fonction de la taille de l'écran + float fov = XM_PI / 4.0f; // Champ de vision, généralement pi/4 + float aspect = screenWidth / screenHeight; // Rapport d'aspect, généralement largeur/hauteur + float znear = screenDepth / 2.0f; // Plan proche, généralement la moitié de la profondeur de l'écran + float zfar = screenDepth * 2.0f; // Plan éloigné, généralement deux fois la profondeur de l'écran + + // Créer une nouvelle matrice de projection avec les nouvelles valeurs + XMMATRIX newProjectionMatrix = XMMatrixPerspectiveFovLH(fov, aspect, znear, zfar); + // Load the projection matrix into a XMFLOAT4X4 structure. XMStoreFloat4x4(&projMatrix, projectionMatrix); diff --git a/enginecustom/frustumclass.h b/enginecustom/frustumclass.h index 6d3e3d0..1730ffd 100644 --- a/enginecustom/frustumclass.h +++ b/enginecustom/frustumclass.h @@ -19,7 +19,7 @@ public: FrustumClass(const FrustumClass&); ~FrustumClass(); - void ConstructFrustum(XMMATRIX, XMMATRIX, float); + void ConstructFrustum(XMMATRIX, XMMATRIX, float, float, float); bool CheckPoint(float, float, float); bool CheckCube(float, float, float, float);