From 5d54c0ad5411e2d0e050aae94a452caf74674804 Mon Sep 17 00:00:00 2001 From: StratiX0 Date: Wed, 3 Apr 2024 12:47:02 +0200 Subject: [PATCH] amelioration du frustum --- enginecustom/applicationclass.cpp | 4 +++- enginecustom/applicationclass.h | 1 + enginecustom/frustumclass.cpp | 11 ++++++++++- enginecustom/frustumclass.h | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) 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 c8cacbb..60609f1 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -87,6 +87,7 @@ private: PositionClass* m_Position; FrustumClass* m_Frustum; XMMATRIX m_baseViewMatrix; + 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);