GameLogic - Cleanup after erik ;)
This commit is contained in:
parent
33d045de1a
commit
92b3525587
|
@ -1,185 +0,0 @@
|
|||
#include "Camera.h"
|
||||
|
||||
Camera::Camera()
|
||||
{
|
||||
this->m_position = Oyster::Math::Float3(0, 50, 0);
|
||||
this->mRight = Oyster::Math::Float3(1, 0, 0);
|
||||
this->mUp = Oyster::Math::Float3(0, 1, 0);
|
||||
this->mLook = Oyster::Math::Float3(0, 0, 1);
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
}
|
||||
|
||||
void Camera::SetPosition(const Oyster::Math::Float3& v)
|
||||
{
|
||||
this->m_position = v;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetPosition()const
|
||||
{
|
||||
return this->m_position;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetRight()const
|
||||
{
|
||||
return this->mRight;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetUp()const
|
||||
{
|
||||
return this->mUp;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetLook()const
|
||||
{
|
||||
return this->mLook;
|
||||
}
|
||||
|
||||
float Camera::GetNearZ()const
|
||||
{
|
||||
return this->mNearZ;
|
||||
}
|
||||
|
||||
float Camera::GetFarZ()const
|
||||
{
|
||||
return this->mFarZ;
|
||||
}
|
||||
|
||||
float Camera::GetAspect()const
|
||||
{
|
||||
return this->mAspect;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::CrossMatrix(const Oyster::Math::Float3& vector, const Oyster::Math::Float4x4& matrix)
|
||||
{
|
||||
Oyster::Math::Float3 vec;
|
||||
vec.x = matrix.m11*vector.x + matrix.m12*vector.y + matrix.m13*vector.z;
|
||||
vec.y = matrix.m21*vector.x + matrix.m22*vector.y + matrix.m23*vector.z;
|
||||
vec.z = matrix.m31*vector.x + matrix.m32*vector.y + matrix.m33*vector.z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
void Camera::SetLens(float fovY, float aspect, float zn, float zf)
|
||||
{
|
||||
this->mFovY = fovY;
|
||||
this->mAspect = aspect;
|
||||
this->mNearZ = zn;
|
||||
this->mFarZ = zf;
|
||||
|
||||
float yScale = tan((Oyster::Math::pi*0.5f) - (mFovY*0.5f));
|
||||
float xScale = yScale/this->mAspect;
|
||||
|
||||
mProj = Oyster::Math::Float4x4(xScale, 0, 0, 0,
|
||||
0, yScale, 0, 0,
|
||||
0, 0, zf/(zf-zn), 1,
|
||||
0, 0, -zn*zf/(zf-zn), 0);
|
||||
mProj.Transpose();
|
||||
}
|
||||
|
||||
void Camera::LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp)
|
||||
{
|
||||
Oyster::Math::Float3 L;
|
||||
|
||||
L = target - pos;
|
||||
L.Normalize();
|
||||
|
||||
Oyster::Math::Float3 R;
|
||||
R = worldUp.Cross(L);
|
||||
R.Normalize();
|
||||
|
||||
Oyster::Math::Float3 U;
|
||||
U = L.Cross(R);
|
||||
|
||||
this->m_position = pos;
|
||||
this->mLook = L;
|
||||
this->mRight = R;
|
||||
this->mUp = U;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::View()const
|
||||
{
|
||||
return this->mView;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::Proj()const
|
||||
{
|
||||
return this->mProj;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::ViewsProj()const
|
||||
{
|
||||
Oyster::Math::Float4x4 M;
|
||||
M = mView * mProj;
|
||||
return M;
|
||||
}
|
||||
|
||||
void Camera::Walk(float dist)
|
||||
{
|
||||
this->m_position += dist*this->mLook;
|
||||
}
|
||||
|
||||
void Camera::Strafe(float dist)
|
||||
{
|
||||
this->m_position += dist*this->mRight;
|
||||
}
|
||||
|
||||
void Camera::Pitch(float angle)
|
||||
{
|
||||
float radians = angle * 0.0174532925f;
|
||||
|
||||
Oyster::Math::Float4x4 R;
|
||||
|
||||
Oyster::Math3D::RotationMatrix(radians,-mRight,R);
|
||||
this->mUp = CrossMatrix(this->mUp, R);
|
||||
this->mLook = CrossMatrix(this->mLook, R);
|
||||
}
|
||||
|
||||
void Camera::Yaw(float angle)
|
||||
{
|
||||
float radians = angle * 0.0174532925f;
|
||||
|
||||
Oyster::Math::Float4x4 R;
|
||||
|
||||
Oyster::Math::Float3 up(0,1,0);
|
||||
Oyster::Math3D::RotationMatrix(radians,-up,R);
|
||||
|
||||
this->mRight = CrossMatrix(this->mRight, R);
|
||||
this->mUp = CrossMatrix(mUp, R);
|
||||
this->mLook = CrossMatrix(this->mLook, R);
|
||||
}
|
||||
|
||||
void Camera::UpdateViewMatrix()
|
||||
{
|
||||
mLook.Normalize();
|
||||
mUp = mLook.Cross(mRight);
|
||||
mUp.Normalize();
|
||||
mRight = mUp.Cross(mLook);
|
||||
|
||||
float x = -m_position.Dot(mRight);
|
||||
float y = -m_position.Dot(mUp);
|
||||
float z = -m_position.Dot(mLook);
|
||||
|
||||
mView.m11 = mRight.x;
|
||||
mView.m21 = mRight.y;
|
||||
mView.m31 = mRight.z;
|
||||
mView.m41 = x;
|
||||
|
||||
mView.m12 = mUp.x;
|
||||
mView.m22 = mUp.y;
|
||||
mView.m32 = mUp.z;
|
||||
mView.m42 = y;
|
||||
|
||||
mView.m13 = mLook.x;
|
||||
mView.m23 = mLook.y;
|
||||
mView.m33 = mLook.z;
|
||||
mView.m43 = z;
|
||||
|
||||
mView.m14 = 0.0f;
|
||||
mView.m24 = 0.0f;
|
||||
mView.m34 = 0.0f;
|
||||
mView.m44 = 1.0f;
|
||||
|
||||
mView.Transpose();
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#ifndef CAMERA__H
|
||||
#define CAMERA__H
|
||||
|
||||
#include "OysterMath.h"
|
||||
|
||||
class Camera
|
||||
{
|
||||
private:
|
||||
|
||||
Oyster::Math::Float3 m_position;
|
||||
Oyster::Math::Float3 mRight;
|
||||
Oyster::Math::Float3 mUp;
|
||||
Oyster::Math::Float3 mLook;
|
||||
|
||||
|
||||
|
||||
float mNearZ;
|
||||
float mFarZ;
|
||||
float mAspect;
|
||||
float mFovY;
|
||||
|
||||
Oyster::Math::Float4x4 mView;
|
||||
Oyster::Math::Float4x4 mProj;
|
||||
|
||||
public:
|
||||
Camera();
|
||||
virtual ~Camera();
|
||||
|
||||
void SetPosition(const Oyster::Math::Float3& v);
|
||||
|
||||
Oyster::Math::Float3 GetPosition()const;
|
||||
|
||||
Oyster::Math::Float3 GetRight()const;
|
||||
Oyster::Math::Float3 GetUp()const;
|
||||
Oyster::Math::Float3 GetLook()const;
|
||||
|
||||
float GetNearZ()const;
|
||||
float GetFarZ()const;
|
||||
float GetAspect()const;
|
||||
|
||||
Oyster::Math::Float3 CrossMatrix(const Oyster::Math::Float3& v, const Oyster::Math::Float4x4& m);
|
||||
|
||||
void SetLens(float fovY, float aspect, float zn, float zf);
|
||||
|
||||
void LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp);
|
||||
|
||||
void setLook(Oyster::Math::Float3 look) { mLook = look; }
|
||||
void setUp(Oyster::Math::Float3 up) { mUp = up; }
|
||||
void setRight(Oyster::Math::Float3 right) { mRight = right; }
|
||||
|
||||
Oyster::Math::Float4x4 View()const;
|
||||
Oyster::Math::Float4x4 Proj()const;
|
||||
Oyster::Math::Float4x4 ViewsProj()const;
|
||||
|
||||
void Walk(float dist);
|
||||
void Strafe(float dist);
|
||||
|
||||
void Pitch(float angle);
|
||||
void Yaw(float angle);
|
||||
|
||||
void UpdateViewMatrix();
|
||||
};
|
||||
#endif
|
|
@ -1,79 +0,0 @@
|
|||
#include "Game.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
Game::Game(void)
|
||||
{
|
||||
player = NULL;
|
||||
level = NULL;
|
||||
camera = NULL;
|
||||
}
|
||||
|
||||
|
||||
Game::~Game(void)
|
||||
{
|
||||
//SAFE_DELETE(player);
|
||||
if(player)
|
||||
{
|
||||
delete player;
|
||||
player = NULL;
|
||||
}
|
||||
if(camera)
|
||||
{
|
||||
delete camera;
|
||||
camera = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::Init()
|
||||
{
|
||||
//Oyster::Physics::API::SetSubscription("remove object");
|
||||
|
||||
player = new Player(L"worldDummy");
|
||||
|
||||
box = new DynamicObject(L"crate");
|
||||
//poi
|
||||
//box = new physcTestObj("box");
|
||||
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, float pitch, float yaw)
|
||||
{
|
||||
//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();
|
||||
//poi Oyster::Physics::API::Update();
|
||||
}
|
||||
void Game::Render()
|
||||
{
|
||||
Oyster::Graphics::API::SetView(camera->View());
|
||||
Oyster::Graphics::API::SetProjection(camera->Proj());
|
||||
Oyster::Graphics::API::NewFrame();
|
||||
player->Render();
|
||||
box->Render();
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include "Level.h"
|
||||
#include "Player.h"
|
||||
#include "IGame.h"
|
||||
#include "Camera.h"
|
||||
#include "DynamicObject.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
~Game();
|
||||
|
||||
void Init();
|
||||
void StartGame();
|
||||
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||
void Render();
|
||||
|
||||
private:
|
||||
Level* level;
|
||||
DynamicObject* box;
|
||||
Player* player;
|
||||
Camera* camera;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -1,43 +0,0 @@
|
|||
#include "IGame.h"
|
||||
#include "Game.h"
|
||||
#include <windows.h>
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
_In_ HINSTANCE hinstDLL,
|
||||
_In_ DWORD fdwReason,
|
||||
_In_ LPVOID lpvReserved
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
using namespace GameLogic;
|
||||
|
||||
IGame::IGame()
|
||||
{
|
||||
gameModule = new Game();
|
||||
}
|
||||
IGame::~IGame()
|
||||
{
|
||||
delete gameModule;
|
||||
}
|
||||
|
||||
void IGame::Init()
|
||||
{
|
||||
gameModule->Init();
|
||||
}
|
||||
void IGame::StartGame()
|
||||
{
|
||||
gameModule->StartGame();
|
||||
}
|
||||
void IGame::Update(keyInput keyPressed, float pitch, float yaw)
|
||||
{
|
||||
gameModule->Update(keyPressed, pitch, yaw);
|
||||
}
|
||||
void IGame::Render()
|
||||
{
|
||||
gameModule->Render();
|
||||
}
|
||||
Game* IGame::getGameModule()
|
||||
{
|
||||
return gameModule;
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#ifndef IGAME_H
|
||||
#define IGAME_H
|
||||
|
||||
#if defined GAME_DLL_EXPORT
|
||||
#define GAME_DLL_USAGE __declspec(dllexport)
|
||||
#else
|
||||
#define GAME_DLL_USAGE __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Game;
|
||||
|
||||
enum keyInput
|
||||
{
|
||||
keyInput_W,
|
||||
keyInput_A,
|
||||
keyInput_S,
|
||||
keyInput_D,
|
||||
keyInput_none
|
||||
};
|
||||
|
||||
class GAME_DLL_USAGE IGame
|
||||
{
|
||||
private:
|
||||
Game* gameModule;
|
||||
public:
|
||||
IGame();
|
||||
~IGame();
|
||||
|
||||
|
||||
void Init();
|
||||
void StartGame();
|
||||
/************************************************************************/
|
||||
/* Get key input to update the player */
|
||||
/************************************************************************/
|
||||
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||
void Render();
|
||||
Game* getGameModule();
|
||||
private:
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -1,47 +0,0 @@
|
|||
#include "RefManager.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
typedef std::pair<const Oyster::Physics::ICustomBody*, Object*> mapData;
|
||||
|
||||
RefManager* RefManager::instance = 0;
|
||||
|
||||
RefManager::RefManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RefManager::~RefManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RefManager::Release()
|
||||
{
|
||||
if (instance)
|
||||
{
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RefManager* RefManager::getInstance( )
|
||||
{
|
||||
if (!instance)
|
||||
{
|
||||
instance = new RefManager();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
|
||||
Object* RefManager::GetMap(const Oyster::Physics::ICustomBody &body)
|
||||
{
|
||||
return mapper[&body];
|
||||
}
|
||||
|
||||
void RefManager::AddMapping( const Oyster::Physics::ICustomBody &body, Object &obj)
|
||||
{
|
||||
mapper.insert(mapData(&body,&obj));
|
||||
}
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef REFMANAGER_H
|
||||
#define REFMANAGER_H
|
||||
|
||||
#include<map>
|
||||
#include "Object.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class RefManager
|
||||
{
|
||||
public:
|
||||
RefManager(void);
|
||||
~RefManager(void);
|
||||
|
||||
static RefManager* getInstance( );
|
||||
void Release();
|
||||
|
||||
|
||||
Object* GetMap(const Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
|
||||
void AddMapping(const Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
|
||||
|
||||
|
||||
private:
|
||||
static RefManager* instance;
|
||||
std::map<const Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -1,304 +0,0 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
// File: TemplateMain.cpp
|
||||
//
|
||||
// BTH-D3D-Template
|
||||
//
|
||||
// Copyright (c) Stefan Petersson 2011. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test main function for game logic when .exe
|
||||
// Doesn't run when Game logic is compiled as a .dll
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include "Core/Core.h"
|
||||
#include "DllInterfaces/GFXAPI.h"
|
||||
#include "IGame.h"
|
||||
|
||||
#include "L_inputClass.h"
|
||||
|
||||
// debug window include
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
//--------------------------------------------------------------------------------------
|
||||
HINSTANCE g_hInst = NULL;
|
||||
HWND g_hWnd = NULL;
|
||||
|
||||
GameLogic::IGame *game;
|
||||
InputClass *inputObj;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//--------------------------------------------------------------------------------------
|
||||
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();
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Entry point to the program. Initializes everything and goes into a message processing
|
||||
// loop. Idle time is used to render the scene.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
void SetStdOutToNewConsole()
|
||||
{
|
||||
// allocate a console for this app
|
||||
AllocConsole();
|
||||
|
||||
// redirect unbuffered STDOUT to the console
|
||||
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
|
||||
FILE *fp = _fdopen( fileDescriptor, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
|
||||
// give the console window a nicer title
|
||||
|
||||
SetConsoleTitle(L"Debug Output");
|
||||
|
||||
// give the console window a bigger buffer size
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) )
|
||||
{
|
||||
COORD bufferSize;
|
||||
bufferSize.X = csbi.dwSize.X;
|
||||
bufferSize.Y = 50;
|
||||
SetConsoleScreenBufferSize(consoleHandle, bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
|
||||
{
|
||||
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitDirect3D() ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitGame() ) )
|
||||
return 0;
|
||||
|
||||
__int64 cntsPerSec = 0;
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
|
||||
float secsPerCnt = 1.0f / (float)cntsPerSec;
|
||||
|
||||
__int64 prevTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||
|
||||
//Init debug window
|
||||
//SetStdOutToNewConsole();
|
||||
|
||||
// Main message loop
|
||||
MSG msg = {0};
|
||||
while(WM_QUIT != msg.message)
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
__int64 currTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
|
||||
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
|
||||
|
||||
//render
|
||||
Update(dt);
|
||||
Render(dt);
|
||||
|
||||
prevTimeStamp = currTimeStamp;
|
||||
}
|
||||
}
|
||||
CleanUp();
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Register class and create window
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
|
||||
{
|
||||
// Register class
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = 0;
|
||||
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = NULL;
|
||||
wcex.lpszClassName = L"BTH_D3D_Template";
|
||||
wcex.hIconSm = 0;
|
||||
if( !RegisterClassEx(&wcex) )
|
||||
return E_FAIL;
|
||||
|
||||
// Adjust and create window
|
||||
g_hInst = hInstance;
|
||||
RECT rc = { 0, 0, 1024, 768 };
|
||||
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
|
||||
|
||||
if(!(g_hWnd = CreateWindow(
|
||||
L"BTH_D3D_Template",
|
||||
L"BTH - Direct3D 11.0 Template",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL)))
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ShowWindow( g_hWnd, 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;
|
||||
if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
|
||||
{
|
||||
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
game = new GameLogic::IGame();
|
||||
game->Init();
|
||||
game->StartGame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Update(float deltaTime)
|
||||
{
|
||||
inputObj->Update();
|
||||
GameLogic::keyInput key = GameLogic::keyInput_none;
|
||||
|
||||
if(inputObj->IsKeyPressed(DIK_W))
|
||||
{
|
||||
key = GameLogic::keyInput_W;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
key = GameLogic::keyInput_A;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_S))
|
||||
{
|
||||
key = GameLogic::keyInput_S;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_D))
|
||||
{
|
||||
key = GameLogic::keyInput_D;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT Render(float deltaTime)
|
||||
{
|
||||
int isPressed = 0;
|
||||
if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
isPressed = 1;
|
||||
//std::cout<<"test";
|
||||
}
|
||||
|
||||
game->Render();
|
||||
wchar_t title[255];
|
||||
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
||||
SetWindowText(g_hWnd, title);
|
||||
|
||||
Oyster::Graphics::API::EndFrame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CleanUp()
|
||||
{
|
||||
SAFE_DELETE(game);
|
||||
return S_OK;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Called every time the application receives a message
|
||||
//--------------------------------------------------------------------------------------
|
||||
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
|
||||
switch(wParam)
|
||||
{
|
||||
case VK_ESCAPE:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue