direct input fini

Le code ne fonctionne pas encore, il doit être merge avec le tuto 14.
This commit is contained in:
GolfOcean334 2024-03-29 14:38:48 +01:00
parent 41b2b9e024
commit f5554587bd
9 changed files with 214 additions and 225 deletions

@ -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)

@ -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;
}

@ -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

@ -50,6 +50,7 @@
<ClInclude Include="Multitextureshaderclass.h" />
<ClInclude Include="Spriteclass.h" />
<ClInclude Include="systemclass.h" />
<ClInclude Include="textclass.h" />
<ClInclude Include="textureclass.h" />
<ClInclude Include="textureshaderclass.h" />
<ClInclude Include="Timerclass.h" />

@ -1,172 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Fichiers sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Fichiers d%27en-tête">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Fichiers de ressources">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="shader">
<UniqueIdentifier>{b016e481-576e-4d99-bdde-34cc10c55b1d}</UniqueIdentifier>
</Filter>
<Filter Include="texture">
<UniqueIdentifier>{f76f9761-bbbe-42a8-935d-01f1b9172c38}</UniqueIdentifier>
</Filter>
<Filter Include="assets">
<UniqueIdentifier>{741e1efe-db9b-48a7-9ecb-4c34a696f40e}</UniqueIdentifier>
</Filter>
<ClCompile Include="applicationclass.cpp" />
<ClCompile Include="bitmapclass.cpp" />
<ClCompile Include="Cameraclass.cpp" />
<ClCompile Include="Colorshaderclass.cpp" />
<ClCompile Include="d3dclass.cpp" />
<ClCompile Include="inputclass.cpp" />
<ClCompile Include="Lightclass.cpp" />
<ClCompile Include="Lightshaderclass.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="modelclass.cpp" />
<ClCompile Include="Multitextureshaderclass.cpp" />
<ClCompile Include="Spriteclass.cpp" />
<ClCompile Include="Systemclass.cpp" />
<ClCompile Include="textureclass.cpp" />
<ClCompile Include="textureshaderclass.cpp" />
<ClCompile Include="Timerclass.cpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Systemclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="inputclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="applicationclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="d3dclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Colorshaderclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="modelclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Cameraclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="textureclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="lightshaderclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="lightclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Multitextureshaderclass.cpp">
<ClCompile Include="bitmapclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="textureshaderclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Spriteclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="Timerclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClInclude Include="applicationclass.h" />
<ClInclude Include="bitmapclass.h" />
<ClInclude Include="Cameraclass.h" />
<ClInclude Include="Colorshaderclass.h" />
<ClInclude Include="d3dclass.h" />
<ClInclude Include="inputclass.h" />
<ClInclude Include="lightclass.h" />
<ClInclude Include="lightshaderclass.h" />
<ClInclude Include="modelclass.h" />
<ClInclude Include="Multitextureshaderclass.h" />
<ClInclude Include="Spriteclass.h" />
<ClInclude Include="systemclass.h" />
<ClInclude Include="textureclass.h" />
<ClInclude Include="textureshaderclass.h" />
<ClInclude Include="Timerclass.h" />
<ClInclude Include="textclass.h" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="systemclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="inputclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="applicationclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="d3dclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Colorshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="modelclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Cameraclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="textureclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="lightshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Multitextureshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="lightclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Lightshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Lightclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="bitmapclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="textureshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Spriteclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="Timerclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<Image Include="moss01.tga" />
<Image Include="papier.tga" />
<Image Include="stone01.tga" />
<Image Include="wall.tga" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Color.ps">
<Filter>shader</Filter>
</None>
<None Include="Color.vs">
<Filter>shader</Filter>
</None>
<None Include="light.vs">
<Filter>texture</Filter>
</None>
<None Include="light.ps">
<Filter>texture</Filter>
</None>
<None Include="Multitexture.vs" />
<None Include="light.ps" />
<None Include="light.vs" />
<None Include="Multitexture.ps" />
<None Include="texture.ps">
<Filter>texture</Filter>
</None>
<None Include="texture.vs">
<Filter>texture</Filter>
</None>
<None Include="sphere.obj">
<Filter>assets</Filter>
</None>
<None Include="Multitexture.vs" />
<None Include="packages.config" />
<None Include="texture.ps" />
<None Include="texture.vs" />
<None Include="Color.ps" />
<None Include="Color.vs" />
</ItemGroup>
<ItemGroup>
<Image Include="wall.tga">
<Filter>assets</Filter>
</Image>
<Image Include="stone01.tga">
<Filter>assets</Filter>
</Image>
<Image Include="papier.tga">
<Filter>assets</Filter>
</Image>
<Image Include="moss01.tga">
<Filter>assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Text Include="cube.txt">
<Filter>assets</Filter>
</Text>
<Text Include="cube.txt" />
<Text Include="sphere.txt" />
</ItemGroup>
</Project>

@ -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()
{

@ -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];

@ -1,5 +1,6 @@
#ifndef _SYSTEMCLASS_H_
#define _SYSTEMCLASS_H_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

1
enginecustom/textclass.h Normal file

@ -0,0 +1 @@
#pragma once