From f5554587bd20c8c4a075ab226ed1a9c7030746ea Mon Sep 17 00:00:00 2001
From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com>
Date: Fri, 29 Mar 2024 14:38:48 +0100
Subject: [PATCH] direct input fini
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Le code ne fonctionne pas encore, il doit être merge avec le tuto 14.
---
enginecustom/Systemclass.cpp | 39 ++---
enginecustom/applicationclass.cpp | 118 ++++++++++++-
enginecustom/applicationclass.h | 6 +-
enginecustom/enginecustom.vcxproj | 1 +
enginecustom/enginecustom.vcxproj.filters | 204 +++++-----------------
enginecustom/inputclass.cpp | 65 ++++---
enginecustom/inputclass.h | 4 +-
enginecustom/systemclass.h | 1 +
enginecustom/textclass.h | 1 +
9 files changed, 214 insertions(+), 225 deletions(-)
create mode 100644 enginecustom/textclass.h
diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp
index 287ca70..fe8abac 100644
--- a/enginecustom/Systemclass.cpp
+++ b/enginecustom/Systemclass.cpp
@@ -31,7 +31,11 @@ bool SystemClass::Initialize()
// Create and initialize the input object. This object will be used to handle reading the keyboard input from the user.
m_Input = new InputClass;
- m_Input->Initialize();
+ result = m_Input->Initialize(m_hinstance, m_hwnd, screenWidth, screenHeight);
+ if (!result)
+ {
+ return false;
+ }
// Create and initialize the application class object. This object will handle rendering all the graphics for this application.
m_Application = new ApplicationClass;
@@ -112,15 +116,15 @@ bool SystemClass::Frame()
{
bool result;
-
- // Check if the user pressed escape and wants to exit the application.
- if (m_Input->IsKeyDown(VK_ESCAPE))
+ // Do the input frame processing.
+ result = m_Input->Frame();
+ if (!result)
{
return false;
}
// Do the frame processing for the application class object.
- result = m_Application->Frame();
+ result = m_Application->Frame(m_Input);
if (!result)
{
return false;
@@ -131,30 +135,7 @@ bool SystemClass::Frame()
LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
- switch (umsg)
- {
- // Check if a key has been pressed on the keyboard.
- case WM_KEYDOWN:
- {
- // If a key is pressed send it to the input object so it can record that state.
- m_Input->KeyDown((unsigned int)wparam);
- return 0;
- }
-
- // Check if a key has been released on the keyboard.
- case WM_KEYUP:
- {
- // If a key is released then send it to the input object so it can unset the state for that key.
- m_Input->KeyUp((unsigned int)wparam);
- return 0;
- }
-
- // Any other messages send to the default message handler as our application won't make use of them.
- default:
- {
- return DefWindowProc(hwnd, umsg, wparam, lparam);
- }
- }
+ return DefWindowProc(hwnd, umsg, wparam, lparam);
}
void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp
index 3fc9803..7ae6c4e 100644
--- a/enginecustom/applicationclass.cpp
+++ b/enginecustom/applicationclass.cpp
@@ -12,6 +12,7 @@ ApplicationClass::ApplicationClass()
m_Bitmap = 0;
m_Sprite = 0;
m_Timer = 0;
+ m_MouseStrings = 0;
}
@@ -27,6 +28,7 @@ ApplicationClass::~ApplicationClass()
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
+ char mouseString1[32], mouseString2[32], mouseString3[32];
char modelFilename[128];
char textureFilename1[128], textureFilename2[128];
char bitmapFilename[128];
@@ -91,6 +93,32 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
return false;
}
+ // Set the initial mouse strings.
+ strcpy_s(mouseString1, "Mouse X: 0");
+ strcpy_s(mouseString2, "Mouse Y: 0");
+ strcpy_s(mouseString3, "Mouse Button: No");
+
+ // Create and initialize the text objects for the mouse strings.
+ m_MouseStrings = new TextClass[3];
+
+ result = m_MouseStrings[0].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 10, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
+ result = m_MouseStrings[1].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 35, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
+ result = m_MouseStrings[2].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 60, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
// Set the file name of the bitmap file.
strcpy_s(bitmapFilename, "stone01.tga");
@@ -156,6 +184,17 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
void ApplicationClass::Shutdown()
{
+ // Release the text objects for the mouse strings.
+ if (m_MouseStrings)
+ {
+ m_MouseStrings[0].Shutdown();
+ m_MouseStrings[1].Shutdown();
+ m_MouseStrings[2].Shutdown();
+
+ delete[] m_MouseStrings;
+ m_MouseStrings = 0;
+ }
+
// Release the timer object.
if (m_Timer)
{
@@ -244,8 +283,11 @@ void ApplicationClass::Shutdown()
}
-bool ApplicationClass::Frame()
+bool ApplicationClass::Frame(InputClass* Input)
{
+ int mouseX, mouseY;
+ bool result, mouseDown;
+
float frameTime;
static float rotation = 0.0f;
static float x = 2.f;
@@ -253,6 +295,12 @@ bool ApplicationClass::Frame()
static float z = 0.f;
bool result;
+ // Check if the user pressed escape and wants to exit the application.
+ if (Input->IsEscapePressed())
+ {
+ return false;
+ }
+
// Update the rotation variable each frame.
rotation -= 0.0174532925f * 0.1f;
if (rotation < 0.0f)
@@ -309,6 +357,19 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
// Turn off the Z buffer to begin all 2D rendering.
m_Direct3D->TurnZBufferOff();
+ // Render the mouse text strings using the font shader.
+ for (i = 0; i < 3; i++)
+ {
+ m_MouseStrings[i].Render(m_Direct3D->GetDeviceContext());
+
+ result = m_FontShader->Render(m_Direct3D->GetDeviceContext(), m_MouseStrings[i].GetIndexCount(), worldMatrix, viewMatrix, orthoMatrix,
+ m_Font->GetTexture(), m_MouseStrings[i].GetPixelColor());
+ if (!result)
+ {
+ return false;
+ }
+ }
+
// Put the sprite vertex and index buffers on the graphics pipeline to prepare them for drawing.
result = m_Sprite->Render(m_Direct3D->GetDeviceContext());
if (!result)
@@ -385,3 +446,58 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
return true;
}
+bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown)
+{
+ char tempString[16], finalString[32];
+ bool result;
+
+
+ // Convert the mouse X integer to string format.
+ sprintf_s(tempString, "%d", mouseX);
+
+ // Setup the mouse X string.
+ strcpy_s(finalString, "Mouse X: ");
+ strcat_s(finalString, tempString);
+
+ // Update the sentence vertex buffer with the new string information.
+ result = m_MouseStrings[0].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 10, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
+ // Convert the mouse Y integer to string format.
+ sprintf_s(tempString, "%d", mouseY);
+
+ // Setup the mouse Y string.
+ strcpy_s(finalString, "Mouse Y: ");
+ strcat_s(finalString, tempString);
+
+ // Update the sentence vertex buffer with the new string information.
+ result = m_MouseStrings[1].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 35, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
+ // Setup the mouse button string.
+ if (mouseDown)
+ {
+ strcpy_s(finalString, "Mouse Button: Yes");
+ }
+ else
+ {
+ strcpy_s(finalString, "Mouse Button: No");
+ }
+
+ // Update the sentence vertex buffer with the new string information.
+ result = m_MouseStrings[2].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 60, 1.0f, 1.0f, 1.0f);
+ if (!result)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+
diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h
index 9ceb351..9a8f23e 100644
--- a/enginecustom/applicationclass.h
+++ b/enginecustom/applicationclass.h
@@ -15,6 +15,7 @@
#include "textureshaderclass.h"
#include "spriteclass.h"
#include "timerclass.h"
+#include "textclass.h"
/////////////
// GLOBALS //
@@ -37,10 +38,12 @@ public:
bool Initialize(int, int, HWND);
void Shutdown();
- bool Frame();
+ bool Frame(InputClass*);
private:
bool Render(float, float, float, float);
+ bool UpdateMouseStrings(int, int, bool);
+
private:
D3DClass* m_Direct3D;
CameraClass* m_Camera;
@@ -52,6 +55,7 @@ private:
BitmapClass* m_Bitmap;
SpriteClass* m_Sprite;
TimerClass* m_Timer;
+ TextClass* m_MouseStrings;
};
#endif
diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj
index d299fd2..8acceff 100644
--- a/enginecustom/enginecustom.vcxproj
+++ b/enginecustom/enginecustom.vcxproj
@@ -50,6 +50,7 @@
+
diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters
index 1fb3790..85b670f 100644
--- a/enginecustom/enginecustom.vcxproj.filters
+++ b/enginecustom/enginecustom.vcxproj.filters
@@ -1,172 +1,60 @@
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
- {b016e481-576e-4d99-bdde-34cc10c55b1d}
-
-
- {f76f9761-bbbe-42a8-935d-01f1b9172c38}
-
-
- {741e1efe-db9b-48a7-9ecb-4c34a696f40e}
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
-
- Fichiers sources
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
-
- Fichiers d%27en-tête
-
+
+
+
+
-
-
- shader
-
-
- shader
-
-
- texture
-
-
- texture
-
-
+
+
-
- texture
-
-
- texture
-
-
- assets
-
+
+
+
+
+
+
-
- assets
-
-
- assets
-
-
- assets
-
-
- assets
-
-
-
-
- assets
-
+
+
\ No newline at end of file
diff --git a/enginecustom/inputclass.cpp b/enginecustom/inputclass.cpp
index ba0bf43..81bc72f 100644
--- a/enginecustom/inputclass.cpp
+++ b/enginecustom/inputclass.cpp
@@ -21,8 +21,17 @@ InputClass::~InputClass()
bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{
HRESULT result;
+ int i;
+ // Initialize all the keys to being released and not pressed.
+ for (i = 0; i < 256; i++)
+ {
+ m_keys[i] = false;
+ }
+
+ return;
+
// Store the screen size which will be used for positioning the mouse cursor.
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
@@ -97,42 +106,30 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
return true;
}
-//void InputClass::Initialize()
-//{
-// int i;
-//
-//
-// // Initialize all the keys to being released and not pressed.
-// for (i = 0; i < 256; i++)
-// {
-// m_keys[i] = false;
-// }
-//
-// return;
-//}
-//void InputClass::KeyDown(unsigned int input)
-//{
-// // If a key is pressed then save that state in the key array.
-// m_keys[input] = true;
-// return;
-//}
-//
-//
-//void InputClass::KeyUp(unsigned int input)
-//{
-// // If a key is released then clear that state in the key array.
-// m_keys[input] = false;
-// return;
-//}
-//
-//
-//bool InputClass::IsKeyDown(unsigned int key)
-//{
-// // Return what state the key is in (pressed/not pressed).
-// return m_keys[key];
-//}
+
+void InputClass::KeyDown(unsigned int input)
+{
+ // If a key is pressed then save that state in the key array.
+ m_keys[input] = true;
+ return;
+}
+
+
+void InputClass::KeyUp(unsigned int input)
+{
+ // If a key is released then clear that state in the key array.
+ m_keys[input] = false;
+ return;
+}
+
+
+bool InputClass::IsKeyDown(unsigned int key)
+{
+ // Return what state the key is in (pressed/not pressed).
+ return m_keys[key];
+}
void InputClass::Shutdown()
{
diff --git a/enginecustom/inputclass.h b/enginecustom/inputclass.h
index 68e0530..21d3c2b 100644
--- a/enginecustom/inputclass.h
+++ b/enginecustom/inputclass.h
@@ -34,10 +34,10 @@ public:
bool IsEscapePressed();
void GetMouseLocation(int&, int&);
bool IsMousePressed();
- /*void KeyDown(unsigned int);
+ void KeyDown(unsigned int);
void KeyUp(unsigned int);
- bool IsKeyDown(unsigned int);*/
+ bool IsKeyDown(unsigned int);
private:
bool m_keys[256];
diff --git a/enginecustom/systemclass.h b/enginecustom/systemclass.h
index 4eb1d8d..dbd21aa 100644
--- a/enginecustom/systemclass.h
+++ b/enginecustom/systemclass.h
@@ -1,5 +1,6 @@
#ifndef _SYSTEMCLASS_H_
#define _SYSTEMCLASS_H_
+
#define WIN32_LEAN_AND_MEAN
#include
diff --git a/enginecustom/textclass.h b/enginecustom/textclass.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/enginecustom/textclass.h
@@ -0,0 +1 @@
+#pragma once