GL: key input
This commit is contained in:
commit
fb3ae57bbe
|
@ -0,0 +1,47 @@
|
||||||
|
#include "CollisionManager.h"
|
||||||
|
|
||||||
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
CollisionManager::CollisionManager(void)
|
||||||
|
{
|
||||||
|
refManager = new RefManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CollisionManager::~CollisionManager(void)
|
||||||
|
{
|
||||||
|
SAFE_DELETE(refManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollisionManager::ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2)
|
||||||
|
{
|
||||||
|
Object *realObj1 = refManager->GetMap(obj1);
|
||||||
|
Object *realObj2 = refManager->GetMap(obj2);
|
||||||
|
|
||||||
|
|
||||||
|
switch(realObj1->GetType())
|
||||||
|
{
|
||||||
|
case Object::OBJECT_TYPE_PLAYER:
|
||||||
|
|
||||||
|
if (realObj2->GetType() == Object::OBJECT_TYPE_BOX )
|
||||||
|
{
|
||||||
|
PlayerVBox(*((Player*)realObj1),*((DynamicObject*)realObj2));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Object::OBJECT_TYPE_BOX:
|
||||||
|
|
||||||
|
if (realObj2->GetType() == Object::OBJECT_TYPE_PLAYER)
|
||||||
|
{
|
||||||
|
PlayerVBox(*((Player*)realObj2),*((DynamicObject*)realObj1));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollisionManager::PlayerVBox(Player &player, DynamicObject &box)
|
||||||
|
{
|
||||||
|
//spela ljud? ta skada? etc etc
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef COLLISIONMANAGER_H
|
||||||
|
#define COLLISIONMANAGER_H
|
||||||
|
|
||||||
|
#include "Object.h"
|
||||||
|
#include "PhysicsAPI.h"
|
||||||
|
#include "RefManager.h"
|
||||||
|
#include "DynamicObject.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
namespace GameLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
class CollisionManager
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
CollisionManager(void);
|
||||||
|
~CollisionManager(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2);
|
||||||
|
void PlayerVBox(Player &player, DynamicObject &box);
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefManager *refManager;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,9 +1,13 @@
|
||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
|
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
using namespace Oyster::Physics;
|
||||||
|
using namespace Utility::DynamicMemory;
|
||||||
|
|
||||||
DynamicObject::DynamicObject(void)
|
DynamicObject::DynamicObject(void)
|
||||||
{
|
{
|
||||||
|
rigidBody = API::Instance().CreateSimpleRigidBody();
|
||||||
|
API::Instance().AddObject(rigidBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class DynamicObject : public Object
|
class DynamicObject : public Object
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -8,21 +8,21 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
|
Game();
|
||||||
|
~Game();
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void StartGame();
|
||||||
|
void Update();
|
||||||
|
void Render();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Level* level;
|
Level* level;
|
||||||
Player* player;
|
Player* player;
|
||||||
|
|
||||||
public:
|
|
||||||
Game();
|
|
||||||
~Game();
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
void StartGame();
|
|
||||||
void Update();
|
|
||||||
void Render();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -59,3 +59,8 @@ void Object::Render()
|
||||||
model->info->Vertices.Apply(0);
|
model->info->Vertices.Apply(0);
|
||||||
Oyster::Graphics::Core::deviceContext->Draw(model->info->VertexCount,0);
|
Oyster::Graphics::Core::deviceContext->Draw(model->info->VertexCount,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object::OBJECT_TYPE Object::GetType()
|
||||||
|
{
|
||||||
|
return this->type;
|
||||||
|
}
|
||||||
|
|
|
@ -4,30 +4,40 @@
|
||||||
#include "Model/Model.h"
|
#include "Model/Model.h"
|
||||||
#include "Render/Rendering/Render.h"
|
#include "Render/Rendering/Render.h"
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
|
|
||||||
#include "PhysicsAPI.h"
|
#include "PhysicsAPI.h"
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Object(void);
|
Object(void);
|
||||||
virtual ~Object(void);
|
virtual ~Object(void);
|
||||||
|
|
||||||
Utility::DynamicMemory::UniquePointer<Oyster::Graphics::Render::Model> model;
|
enum OBJECT_TYPE
|
||||||
|
{
|
||||||
|
OBJECT_TYPE_PLAYER,
|
||||||
|
OBJECT_TYPE_BOX,
|
||||||
|
};
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
|
OBJECT_TYPE GetType();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
OBJECT_TYPE type;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//either a model pointer or an ID to an arraypos filled with models that are to be rendered
|
//either a model pointer or an ID to an arraypos filled with models that are to be rendered
|
||||||
//rigidBody
|
//rigidBody
|
||||||
unsigned int ref;
|
|
||||||
::Utility::DynamicMemory::UniquePointer<Oyster::Physics::ICustomBody> rigidBody;
|
|
||||||
|
|
||||||
|
Utility::DynamicMemory::UniquePointer<Oyster::Physics::ICustomBody> rigidBody;
|
||||||
|
Utility::DynamicMemory::UniquePointer<Oyster::Graphics::Render::Model> model;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,72 +7,15 @@ using namespace Oyster::Physics;
|
||||||
using namespace Utility::DynamicMemory;
|
using namespace Utility::DynamicMemory;
|
||||||
|
|
||||||
|
|
||||||
//void ColisionEvent(unsigned int obj1Ref, unsigned int obj2Ref)
|
|
||||||
//{
|
|
||||||
// const ICustomBody *body1 = &API::Instance().Peek( obj1Ref );
|
|
||||||
// const ICustomBody *body2 = &API::Instance().Peek( obj2Ref );
|
|
||||||
// if( body1 != &Error::nobody )
|
|
||||||
// {
|
|
||||||
// Object *obj1 = (Object*) const_cast<ICustomBody*>(body1);
|
|
||||||
//
|
|
||||||
// Object *obj2 = (Object*) const_cast<ICustomBody*>(body2);
|
|
||||||
//
|
|
||||||
// //switch( obj1->type )
|
|
||||||
// //{
|
|
||||||
// //case Player:
|
|
||||||
// // switch (obj2->type)
|
|
||||||
// // {
|
|
||||||
// // case låda:
|
|
||||||
// // //action
|
|
||||||
// // //soud
|
|
||||||
// // //particle effect
|
|
||||||
//
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// //case låda :
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //}
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer<ICustomBody> obj2)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Player::Player(void)
|
Player::Player(void)
|
||||||
:Object()
|
:Object()
|
||||||
{
|
{
|
||||||
life = 10;
|
life = 100;
|
||||||
|
|
||||||
UniquePointer<ICustomBody> rigidBody = API::Instance().CreateSimpleRigidBody();
|
rigidBody = API::Instance().CreateSimpleRigidBody();
|
||||||
API::Instance().AddObject(rigidBody);
|
API::Instance().AddObject(rigidBody);
|
||||||
////ref = API::Instance().AddObject(API::Instance().CreateSimpleRigidBody());
|
|
||||||
//const ICustomBody* rB;
|
|
||||||
|
|
||||||
////rB = &API::Instance().Peek(ref);
|
|
||||||
////if( rB == &Error::nobody)
|
|
||||||
////{
|
|
||||||
//// //error
|
|
||||||
////}
|
|
||||||
|
|
||||||
//API::Instance().SetCenter(ref, Oyster::Math::Float3::null);
|
|
||||||
//API::Instance().SetMass_KeepMomentum(ref, 20);
|
|
||||||
//// get Tensor matrix (tröghetsmonent)
|
|
||||||
////API::Instance().SetMomentOfInertiaTensor_KeepMomentum(ref, tensorMatrix )
|
|
||||||
//
|
|
||||||
////Oyster::Math::Float3 ve = rB->GetCenter();
|
|
||||||
//API::Instance().SetDeltaTime(0.01f);
|
|
||||||
|
|
||||||
////API::Instance().ApplyForceAt(ref, rB->GetCenter(), Oyster::Math::Float3::null);
|
|
||||||
//
|
|
||||||
////API::Instance().SetAction(ColisionEvent);
|
|
||||||
|
|
||||||
////API::Instance().Update();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,8 +25,7 @@ Player::~Player(void)
|
||||||
}
|
}
|
||||||
void Player::Update()
|
void Player::Update()
|
||||||
{
|
{
|
||||||
//API::Instance().API::Update();
|
|
||||||
//API::Instance().API::ApplyForceAt(ref, )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Move()
|
void Player::Move()
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
//void ColisionEvent(unsigned int obj1, unsigned int obj2);
|
|
||||||
void DestructionEvent(unsigned int obj1, ::Utility::DynamicMemory::UniquePointer<Oyster::Physics::ICustomBody> obj2);
|
|
||||||
|
|
||||||
class Player : public Object
|
class Player : public Object
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ RefManager::~RefManager(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* RefManager::GetMap(Oyster::Physics::ICustomBody *body)
|
Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body)
|
||||||
{
|
{
|
||||||
return mapper[body];
|
return mapper[&body];
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefManager::AddMapping(Oyster::Physics::ICustomBody *body, Object *obj)
|
void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj)
|
||||||
{
|
{
|
||||||
mapper.insert(mapData(body,obj));
|
mapper.insert(mapData(&body,&obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,20 +8,18 @@
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RefManager
|
class RefManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RefManager(void);
|
RefManager(void);
|
||||||
~RefManager(void);
|
~RefManager(void);
|
||||||
|
|
||||||
Object* GetMap(Oyster::Physics::ICustomBody *body);
|
Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
|
||||||
void AddMapping(Oyster::Physics::ICustomBody *body, Object *obj);
|
void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<Oyster::Physics::ICustomBody*,Object*> mapper; //shall be pointer from physics that map to an object
|
std::map<Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,16 @@
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Render\Preparations\Preparations.h"
|
#include "Render\Preparations\Preparations.h"
|
||||||
#include "IGame.h"
|
#include "IGame.h"
|
||||||
|
|
||||||
#include "L_inputClass.h"
|
#include "L_inputClass.h"
|
||||||
|
|
||||||
|
// debug window include
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <io.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -41,6 +49,34 @@ HRESULT CleanUp();
|
||||||
// Entry point to the program. Initializes everything and goes into a message processing
|
// Entry point to the program. Initializes everything and goes into a message processing
|
||||||
// loop. Idle time is used to render the scene.
|
// 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 )
|
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
|
||||||
{
|
{
|
||||||
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
||||||
|
@ -58,7 +94,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
|
||||||
|
|
||||||
__int64 prevTimeStamp = 0;
|
__int64 prevTimeStamp = 0;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||||
|
SetStdOutToNewConsole();
|
||||||
// Main message loop
|
// Main message loop
|
||||||
MSG msg = {0};
|
MSG msg = {0};
|
||||||
while(WM_QUIT != msg.message)
|
while(WM_QUIT != msg.message)
|
||||||
|
@ -194,8 +230,28 @@ HRESULT InitGame()
|
||||||
}
|
}
|
||||||
HRESULT Update(float deltaTime)
|
HRESULT Update(float deltaTime)
|
||||||
{
|
{
|
||||||
game->Update();
|
|
||||||
inputObj->Update();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
game->Update(key);
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +261,7 @@ HRESULT Render(float deltaTime)
|
||||||
if(inputObj->IsKeyPressed(DIK_A))
|
if(inputObj->IsKeyPressed(DIK_A))
|
||||||
{
|
{
|
||||||
isPressed = 1;
|
isPressed = 1;
|
||||||
|
std::cout<<"knon";
|
||||||
}
|
}
|
||||||
//Oyster::Graphics::Render::Rendering::Basic::NewFrame();
|
//Oyster::Graphics::Render::Rendering::Basic::NewFrame();
|
||||||
Oyster::Graphics::Render::Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));
|
Oyster::Graphics::Render::Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));
|
||||||
|
|
Loading…
Reference in New Issue