diff --git a/Code/DanBiasGame/DanBiasMaincpp.cpp b/Code/DanBiasGame/DanBiasMaincpp.cpp index 688a916f..23c1a119 100644 --- a/Code/DanBiasGame/DanBiasMaincpp.cpp +++ b/Code/DanBiasGame/DanBiasMaincpp.cpp @@ -39,6 +39,7 @@ HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HRESULT Render(float deltaTime); HRESULT Update(float deltaTime); +HRESULT InitDirect3D(); HRESULT InitGame(); HRESULT CleanUp(); @@ -78,16 +79,24 @@ void SetStdOutToNewConsole() int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { + // for dynamic .dll loading + // path is relative to the .exe and .dll pos + // also change the VC directories - working dir is set to $(SolutionDir)..\Bin\Executable\Tester + // to fit with where the .obj files is + // linker/ input/ delayed load .dll - specify the .dll that should be loaded + BOOL success = SetDllDirectory(L"..\\..\\DLL"); if (success == 0) { return 0; } - if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) return 0; + if( FAILED( InitDirect3D() ) ) + return 0; + if( FAILED( InitGame() ) ) return 0; @@ -175,7 +184,19 @@ HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ) return S_OK; } +//-------------------------------------------------------------------------------------- +// Create Direct3D with Oyster Graphics +//-------------------------------------------------------------------------------------- +HRESULT InitDirect3D() +{ + if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess) + return E_FAIL; + return S_OK; +} +//-------------------------------------------------------------------------------------- +// Init the input and the game +//------------------------------------------------------------------------------------- HRESULT InitGame() { inputObj = new InputClass; @@ -184,18 +205,13 @@ HRESULT InitGame() MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); return false; } - if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess) - return E_FAIL; - - game = new GameLogic::IGame(); game->Init(); game->StartGame(); - - return S_OK; } + HRESULT Update(float deltaTime) { inputObj->Update(); @@ -218,7 +234,17 @@ HRESULT Update(float deltaTime) key = GameLogic::keyInput_D; } - game->Update(key); + float pitch = 0; + float yaw = 0; + + //if(inputObj->IsMousePressed()) + //{ + pitch = inputObj->GetPitch(); + yaw = inputObj->GetYaw(); + //} + + game->Update(key, pitch, yaw); + return S_OK; } @@ -232,18 +258,6 @@ HRESULT Render(float deltaTime) //std::cout<<"test"; } - // test view and projection matrix - Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1); - Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0); - Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100); - - Oyster::Math::Float4x4 view =Oyster::Math3D::OrientationMatrix_LookAtDirection(dir, up, pos); - view = view.GetInverse(); - - Oyster::Math::Float4x4 proj = Oyster::Math3D::ProjectionMatrix_Perspective(3.14f/2, 1024/768, 1, 1000); - - Oyster::Graphics::API::NewFrame(view, proj); - game->Render(); wchar_t title[255]; swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed)); diff --git a/Code/GameLogic/Camera.cpp b/Code/GameLogic/Camera.cpp index 6ebaa05e..b6546f19 100644 --- a/Code/GameLogic/Camera.cpp +++ b/Code/GameLogic/Camera.cpp @@ -117,7 +117,7 @@ Oyster::Math::Float4x4 Camera::ViewsProj()const void Camera::Walk(float dist) { - this->m_position += dist*Oyster::Math::Float3(1,0,0); + this->m_position += dist*this->mLook; } void Camera::Strafe(float dist) diff --git a/Code/GameLogic/Game.cpp b/Code/GameLogic/Game.cpp index 6d6d367d..b4095130 100644 --- a/Code/GameLogic/Game.cpp +++ b/Code/GameLogic/Game.cpp @@ -3,7 +3,9 @@ using namespace GameLogic; Game::Game(void) { - + player = NULL; + level = NULL; + camera = NULL; } @@ -15,21 +17,52 @@ Game::~Game(void) delete player; player = NULL; } + if(camera) + { + delete camera; + camera = NULL; + } } void Game::Init() { player = new Player(); + camera = new Camera(); } void Game::StartGame() { + Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1); + Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0); + Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100); + camera->LookAt(pos, dir, up); + camera->SetLens(3.14f/2, 1024/768, 1, 1000); } -void Game::Update(keyInput keyPressed) +void Game::Update(keyInput keyPressed, float pitch, float yaw) { - player->Update(keyPressed); + //player->Update(keyPressed); + camera->Yaw(yaw); + camera->Pitch(pitch); + if(keyPressed == keyInput_A) + { + camera->Strafe(-0.1); + } + if(keyPressed == keyInput_D) + { + camera->Strafe(0.1); + } + if(keyPressed == keyInput_S) + { + camera->Walk(-0.1); + } + if(keyPressed == keyInput_W) + { + camera->Walk(0.1); + } + camera->UpdateViewMatrix(); } void Game::Render() { + Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj()); player->Render(); } \ No newline at end of file diff --git a/Code/GameLogic/Game.h b/Code/GameLogic/Game.h index ab2e57e5..0a8a031a 100644 --- a/Code/GameLogic/Game.h +++ b/Code/GameLogic/Game.h @@ -4,11 +4,10 @@ #include "Level.h" #include "Player.h" #include "IGame.h" +#include "Camera.h" namespace GameLogic { - - class Game { public: @@ -17,15 +16,13 @@ namespace GameLogic void Init(); void StartGame(); - void Update(keyInput keyPressed); + void Update(keyInput keyPressed, float pitch, float yaw); void Render(); - private: Level* level; Player* player; - - + Camera* camera; }; } #endif \ No newline at end of file diff --git a/Code/GameLogic/GameLogic.vcxproj b/Code/GameLogic/GameLogic.vcxproj index b0733004..236258d2 100644 --- a/Code/GameLogic/GameLogic.vcxproj +++ b/Code/GameLogic/GameLogic.vcxproj @@ -176,6 +176,7 @@ + @@ -189,6 +190,7 @@ + diff --git a/Code/GameLogic/GameLogic.vcxproj.filters b/Code/GameLogic/GameLogic.vcxproj.filters index e0ed6161..f2c5e978 100644 --- a/Code/GameLogic/GameLogic.vcxproj.filters +++ b/Code/GameLogic/GameLogic.vcxproj.filters @@ -48,6 +48,9 @@ Header Files + + Header Files + @@ -86,5 +89,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Code/GameLogic/IGame.cpp b/Code/GameLogic/IGame.cpp index 0fe09345..dd07c9f8 100644 --- a/Code/GameLogic/IGame.cpp +++ b/Code/GameLogic/IGame.cpp @@ -29,9 +29,9 @@ void IGame::StartGame() { gameModule->StartGame(); } -void IGame::Update(keyInput keyPressed) +void IGame::Update(keyInput keyPressed, float pitch, float yaw) { - gameModule->Update(keyPressed); + gameModule->Update(keyPressed, pitch, yaw); } void IGame::Render() { diff --git a/Code/GameLogic/IGame.h b/Code/GameLogic/IGame.h index ce46b7d8..41b2e0d5 100644 --- a/Code/GameLogic/IGame.h +++ b/Code/GameLogic/IGame.h @@ -38,7 +38,7 @@ namespace GameLogic /************************************************************************/ /* Get key input to update the player */ /************************************************************************/ - void Update(keyInput keyPressed); + void Update(keyInput keyPressed, float pitch, float yaw); void Render(); Game* getGameModule(); private: diff --git a/Code/GameLogic/TestGLMain.cpp b/Code/GameLogic/TestGLMain.cpp index a03ba314..57392224 100644 --- a/Code/GameLogic/TestGLMain.cpp +++ b/Code/GameLogic/TestGLMain.cpp @@ -228,8 +228,17 @@ HRESULT Update(float deltaTime) key = GameLogic::keyInput_D; } - game->Update(key); - + float pitch = 0; + float yaw = 0; + + // move only when mouse is pressed + //if(inputObj->IsMousePressed()) + //{ + pitch = inputObj->GetPitch(); + yaw = inputObj->GetYaw(); + //} + + game->Update(key, pitch, yaw); return S_OK; } @@ -242,18 +251,6 @@ HRESULT Render(float deltaTime) //std::cout<<"test"; } - // test view and projection matrix - Oyster::Math::Float3 dir = Oyster::Math::Float3(0, 0, -1); - Oyster::Math::Float3 up = Oyster::Math::Float3(0, 1, 0); - Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100); - - Oyster::Math::Float4x4 view =Oyster::Math3D::OrientationMatrix_LookAtDirection(dir, up, pos); - view = view.GetInverse(); - - Oyster::Math::Float4x4 proj = Oyster::Math3D::ProjectionMatrix_Perspective(PI/2, 1024/768, 1, 1000); - - Oyster::Graphics::API::NewFrame(view, proj); - game->Render(); wchar_t title[255]; swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed)); @@ -266,7 +263,6 @@ HRESULT Render(float deltaTime) HRESULT CleanUp() { - SAFE_DELETE(game); return S_OK; } diff --git a/Code/Input/L_inputClass.cpp b/Code/Input/L_inputClass.cpp index e644b5dc..5fd15a54 100644 --- a/Code/Input/L_inputClass.cpp +++ b/Code/Input/L_inputClass.cpp @@ -172,20 +172,17 @@ bool InputClass::ReadMouse() return true; } -void InputClass::MouseMove(float &Pitch, float &RotateY ) +float InputClass::GetPitch( ) { - //if left mouse button is pressed - if (m_mouseState.rgbButtons[0]) - { - float dx = (static_cast( m_mouseState.lX)/150); - float dy = (static_cast( m_mouseState.lY)/150); - - // - Pitch=dy; - RotateY=dx; - - } + float dy = (static_cast( m_mouseState.lY)/5); + return -dy; } +float InputClass::GetYaw( ) +{ + float dX = (static_cast( m_mouseState.lX)/5); + return -dX; +} + bool InputClass::IsMousePressed() { if (m_mouseState.rgbButtons[0]) diff --git a/Code/Input/L_inputClass.h b/Code/Input/L_inputClass.h index 4b11c369..129024c2 100644 --- a/Code/Input/L_inputClass.h +++ b/Code/Input/L_inputClass.h @@ -44,7 +44,11 @@ public: bool IsKeyPressed(int key); bool IsMousePressed(); - void MouseMove(float &Pitch, float &RoateY); + + // Call if mouse is pressed + float GetYaw(); + float GetPitch(); + }; #endif \ No newline at end of file