GL: key input

This commit is contained in:
Linda Andersson 2013-11-27 12:00:44 +01:00
commit fb3ae57bbe
12 changed files with 181 additions and 88 deletions

View File

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

View File

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

View File

@ -1,9 +1,13 @@
#include "DynamicObject.h"
using namespace GameLogic;
using namespace Oyster::Physics;
using namespace Utility::DynamicMemory;
DynamicObject::DynamicObject(void)
{
rigidBody = API::Instance().CreateSimpleRigidBody();
API::Instance().AddObject(rigidBody);
}

View File

@ -6,6 +6,7 @@
namespace GameLogic
{
class DynamicObject : public Object
{

View File

@ -8,13 +8,6 @@ namespace GameLogic
{
class Game
{
private:
private:
Level* level;
Player* player;
public:
Game();
~Game();
@ -23,6 +16,13 @@ namespace GameLogic
void StartGame();
void Update();
void Render();
private:
Level* level;
Player* player;
};
}
#endif

View File

@ -59,3 +59,8 @@ void Object::Render()
model->info->Vertices.Apply(0);
Oyster::Graphics::Core::deviceContext->Draw(model->info->VertexCount,0);
}
Object::OBJECT_TYPE Object::GetType()
{
return this->type;
}

View File

@ -4,30 +4,40 @@
#include "Model/Model.h"
#include "Render/Rendering/Render.h"
#include "Utilities.h"
#include "PhysicsAPI.h"
namespace GameLogic
{
class Object
{
public:
Object(void);
virtual ~Object(void);
Utility::DynamicMemory::UniquePointer<Oyster::Graphics::Render::Model> model;
enum OBJECT_TYPE
{
OBJECT_TYPE_PLAYER,
OBJECT_TYPE_BOX,
};
void Render();
OBJECT_TYPE GetType();
private:
OBJECT_TYPE type;
protected:
//either a model pointer or an ID to an arraypos filled with models that are to be rendered
//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;
};
}

View File

@ -7,72 +7,15 @@ using namespace Oyster::Physics;
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)
:Object()
{
life = 10;
life = 100;
UniquePointer<ICustomBody> rigidBody = API::Instance().CreateSimpleRigidBody();
rigidBody = API::Instance().CreateSimpleRigidBody();
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()
{
//API::Instance().API::Update();
//API::Instance().API::ApplyForceAt(ref, )
}
void Player::Move()

View File

@ -7,8 +7,6 @@
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
{

View File

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

View File

@ -8,20 +8,18 @@
namespace GameLogic
{
class RefManager
{
public:
RefManager(void);
~RefManager(void);
Object* GetMap(Oyster::Physics::ICustomBody *body);
void AddMapping(Oyster::Physics::ICustomBody *body, Object *obj);
Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
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
};
}

View File

@ -10,8 +10,16 @@
#include "Core/Core.h"
#include "Render\Preparations\Preparations.h"
#include "IGame.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
// 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 ) ) )
@ -58,7 +94,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
__int64 prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
SetStdOutToNewConsole();
// Main message loop
MSG msg = {0};
while(WM_QUIT != msg.message)
@ -194,8 +230,28 @@ HRESULT InitGame()
}
HRESULT Update(float deltaTime)
{
game->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;
}
@ -205,6 +261,7 @@ HRESULT Render(float deltaTime)
if(inputObj->IsKeyPressed(DIK_A))
{
isPressed = 1;
std::cout<<"knon";
}
//Oyster::Graphics::Render::Rendering::Basic::NewFrame();
Oyster::Graphics::Render::Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));