amelioration du frustum

This commit is contained in:
StratiX0 2024-04-03 12:47:02 +02:00
parent 41161f3388
commit 5d54c0ad54
4 changed files with 15 additions and 3 deletions

View File

@ -51,6 +51,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
char fpsString[32]; char fpsString[32];
bool result; bool result;
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
// Create the Direct3D object. // Create the Direct3D object.
m_Direct3D = new D3DClass; m_Direct3D = new D3DClass;
@ -725,7 +727,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
} }
// Construct the frustum. // 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. // Get the number of models that will be rendered.
modelCount = m_ModelList->GetModelCount(); modelCount = m_ModelList->GetModelCount();

View File

@ -87,6 +87,7 @@ private:
PositionClass* m_Position; PositionClass* m_Position;
FrustumClass* m_Frustum; FrustumClass* m_Frustum;
XMMATRIX m_baseViewMatrix; XMMATRIX m_baseViewMatrix;
float m_screenWidth, m_screenHeight;
}; };
#endif #endif

View File

@ -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; XMMATRIX finalMatrix;
XMFLOAT4X4 projMatrix, matrix; XMFLOAT4X4 projMatrix, matrix;
float zMinimum, r, t; 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. // Load the projection matrix into a XMFLOAT4X4 structure.
XMStoreFloat4x4(&projMatrix, projectionMatrix); XMStoreFloat4x4(&projMatrix, projectionMatrix);

View File

@ -19,7 +19,7 @@ public:
FrustumClass(const FrustumClass&); FrustumClass(const FrustumClass&);
~FrustumClass(); ~FrustumClass();
void ConstructFrustum(XMMATRIX, XMMATRIX, float); void ConstructFrustum(XMMATRIX, XMMATRIX, float, float, float);
bool CheckPoint(float, float, float); bool CheckPoint(float, float, float);
bool CheckCube(float, float, float, float); bool CheckCube(float, float, float, float);