GL - camera movement working
This commit is contained in:
parent
f9a1aaf43c
commit
7a663b2e16
|
@ -39,6 +39,7 @@ HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
|
||||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
HRESULT Render(float deltaTime);
|
HRESULT Render(float deltaTime);
|
||||||
HRESULT Update(float deltaTime);
|
HRESULT Update(float deltaTime);
|
||||||
|
HRESULT InitDirect3D();
|
||||||
HRESULT InitGame();
|
HRESULT InitGame();
|
||||||
HRESULT CleanUp();
|
HRESULT CleanUp();
|
||||||
|
|
||||||
|
@ -78,16 +79,24 @@ void SetStdOutToNewConsole()
|
||||||
|
|
||||||
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
|
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");
|
BOOL success = SetDllDirectory(L"..\\..\\DLL");
|
||||||
if (success == 0)
|
if (success == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if( FAILED( InitDirect3D() ) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
if( FAILED( InitGame() ) )
|
if( FAILED( InitGame() ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -175,7 +184,19 @@ HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
|
||||||
return S_OK;
|
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()
|
HRESULT InitGame()
|
||||||
{
|
{
|
||||||
inputObj = new InputClass;
|
inputObj = new InputClass;
|
||||||
|
@ -184,18 +205,13 @@ HRESULT InitGame()
|
||||||
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
||||||
return false;
|
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 = new GameLogic::IGame();
|
||||||
game->Init();
|
game->Init();
|
||||||
game->StartGame();
|
game->StartGame();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT Update(float deltaTime)
|
HRESULT Update(float deltaTime)
|
||||||
{
|
{
|
||||||
inputObj->Update();
|
inputObj->Update();
|
||||||
|
@ -218,7 +234,17 @@ HRESULT Update(float deltaTime)
|
||||||
key = GameLogic::keyInput_D;
|
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;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
@ -232,18 +258,6 @@ HRESULT Render(float deltaTime)
|
||||||
//std::cout<<"test";
|
//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();
|
game->Render();
|
||||||
wchar_t title[255];
|
wchar_t title[255];
|
||||||
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
||||||
|
|
|
@ -117,7 +117,7 @@ Oyster::Math::Float4x4 Camera::ViewsProj()const
|
||||||
|
|
||||||
void Camera::Walk(float dist)
|
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)
|
void Camera::Strafe(float dist)
|
||||||
|
|
|
@ -3,7 +3,9 @@ using namespace GameLogic;
|
||||||
|
|
||||||
Game::Game(void)
|
Game::Game(void)
|
||||||
{
|
{
|
||||||
|
player = NULL;
|
||||||
|
level = NULL;
|
||||||
|
camera = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,21 +17,52 @@ Game::~Game(void)
|
||||||
delete player;
|
delete player;
|
||||||
player = NULL;
|
player = NULL;
|
||||||
}
|
}
|
||||||
|
if(camera)
|
||||||
|
{
|
||||||
|
delete camera;
|
||||||
|
camera = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Init()
|
void Game::Init()
|
||||||
{
|
{
|
||||||
player = new Player();
|
player = new Player();
|
||||||
|
camera = new Camera();
|
||||||
}
|
}
|
||||||
void Game::StartGame()
|
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()
|
void Game::Render()
|
||||||
{
|
{
|
||||||
|
Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj());
|
||||||
player->Render();
|
player->Render();
|
||||||
}
|
}
|
|
@ -4,11 +4,10 @@
|
||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "IGame.h"
|
#include "IGame.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -17,15 +16,13 @@ namespace GameLogic
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void StartGame();
|
void StartGame();
|
||||||
void Update(keyInput keyPressed);
|
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Level* level;
|
Level* level;
|
||||||
Player* player;
|
Player* player;
|
||||||
|
Camera* camera;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -176,6 +176,7 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="CollisionManager.h" />
|
<ClInclude Include="CollisionManager.h" />
|
||||||
<ClInclude Include="DynamicObject.h" />
|
<ClInclude Include="DynamicObject.h" />
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Game.h" />
|
||||||
|
@ -189,6 +190,7 @@
|
||||||
<ClInclude Include="Weapon.h" />
|
<ClInclude Include="Weapon.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Camera.cpp" />
|
||||||
<ClCompile Include="CollisionManager.cpp" />
|
<ClCompile Include="CollisionManager.cpp" />
|
||||||
<ClCompile Include="DynamicObject.cpp" />
|
<ClCompile Include="DynamicObject.cpp" />
|
||||||
<ClCompile Include="Game.cpp" />
|
<ClCompile Include="Game.cpp" />
|
||||||
|
|
|
@ -48,6 +48,9 @@
|
||||||
<ClInclude Include="CollisionManager.h">
|
<ClInclude Include="CollisionManager.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Camera.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Game.cpp">
|
<ClCompile Include="Game.cpp">
|
||||||
|
@ -86,5 +89,8 @@
|
||||||
<ClCompile Include="CollisionManager.cpp">
|
<ClCompile Include="CollisionManager.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Camera.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -29,9 +29,9 @@ void IGame::StartGame()
|
||||||
{
|
{
|
||||||
gameModule->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()
|
void IGame::Render()
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace GameLogic
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Get key input to update the player */
|
/* Get key input to update the player */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
void Update(keyInput keyPressed);
|
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||||
void Render();
|
void Render();
|
||||||
Game* getGameModule();
|
Game* getGameModule();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -228,8 +228,17 @@ HRESULT Update(float deltaTime)
|
||||||
key = GameLogic::keyInput_D;
|
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;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,18 +251,6 @@ HRESULT Render(float deltaTime)
|
||||||
//std::cout<<"test";
|
//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();
|
game->Render();
|
||||||
wchar_t title[255];
|
wchar_t title[255];
|
||||||
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
||||||
|
@ -266,7 +263,6 @@ HRESULT Render(float deltaTime)
|
||||||
|
|
||||||
HRESULT CleanUp()
|
HRESULT CleanUp()
|
||||||
{
|
{
|
||||||
|
|
||||||
SAFE_DELETE(game);
|
SAFE_DELETE(game);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,20 +172,17 @@ bool InputClass::ReadMouse()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputClass::MouseMove(float &Pitch, float &RotateY )
|
float InputClass::GetPitch( )
|
||||||
{
|
{
|
||||||
//if left mouse button is pressed
|
float dy = (static_cast<float>( m_mouseState.lY)/5);
|
||||||
if (m_mouseState.rgbButtons[0])
|
return -dy;
|
||||||
{
|
|
||||||
float dx = (static_cast<float>( m_mouseState.lX)/150);
|
|
||||||
float dy = (static_cast<float>( m_mouseState.lY)/150);
|
|
||||||
|
|
||||||
//
|
|
||||||
Pitch=dy;
|
|
||||||
RotateY=dx;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
float InputClass::GetYaw( )
|
||||||
|
{
|
||||||
|
float dX = (static_cast<float>( m_mouseState.lX)/5);
|
||||||
|
return -dX;
|
||||||
|
}
|
||||||
|
|
||||||
bool InputClass::IsMousePressed()
|
bool InputClass::IsMousePressed()
|
||||||
{
|
{
|
||||||
if (m_mouseState.rgbButtons[0])
|
if (m_mouseState.rgbButtons[0])
|
||||||
|
|
|
@ -44,7 +44,11 @@ public:
|
||||||
|
|
||||||
bool IsKeyPressed(int key);
|
bool IsKeyPressed(int key);
|
||||||
bool IsMousePressed();
|
bool IsMousePressed();
|
||||||
void MouseMove(float &Pitch, float &RoateY);
|
|
||||||
|
// Call if mouse is pressed
|
||||||
|
float GetYaw();
|
||||||
|
float GetPitch();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue