From 2b53b94bdc1815fbc73f7ef0e5c2400f42a55508 Mon Sep 17 00:00:00 2001 From: Dennis Peeten Date: Tue, 22 Apr 2008 13:32:09 +0000 Subject: Initial check in MatchBloxEngine --- MatchBloxEngine/MatchBloxEngine.sln | 20 ++ MatchBloxEngine/MatchBloxEngine/C_3DObject.cpp | 28 +++ MatchBloxEngine/MatchBloxEngine/C_3DObject.h | 30 +++ MatchBloxEngine/MatchBloxEngine/C_Block.cpp | 49 ++++ MatchBloxEngine/MatchBloxEngine/C_Block.h | 31 +++ MatchBloxEngine/MatchBloxEngine/C_Hand.cpp | 41 ++++ MatchBloxEngine/MatchBloxEngine/C_Hand.h | 31 +++ MatchBloxEngine/MatchBloxEngine/C_Log.cpp | 24 ++ MatchBloxEngine/MatchBloxEngine/C_Log.h | 19 ++ .../MatchBloxEngine/C_MatchBloxEngine.cpp | 42 ++++ .../MatchBloxEngine/C_MatchBloxEngine.h | 55 +++++ .../MatchBloxEngine/MatchBloxEngine.vcproj | 249 +++++++++++++++++++++ MatchBloxEngine/MatchBloxEngine/MessageQueue.h | 19 ++ MatchBloxEngine/MatchBloxEngine/main.cpp | 129 +++++++++++ 14 files changed, 767 insertions(+) create mode 100644 MatchBloxEngine/MatchBloxEngine.sln create mode 100644 MatchBloxEngine/MatchBloxEngine/C_3DObject.cpp create mode 100644 MatchBloxEngine/MatchBloxEngine/C_3DObject.h create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Block.cpp create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Block.h create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Hand.cpp create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Hand.h create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Log.cpp create mode 100644 MatchBloxEngine/MatchBloxEngine/C_Log.h create mode 100644 MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp create mode 100644 MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h create mode 100644 MatchBloxEngine/MatchBloxEngine/MatchBloxEngine.vcproj create mode 100644 MatchBloxEngine/MatchBloxEngine/MessageQueue.h create mode 100644 MatchBloxEngine/MatchBloxEngine/main.cpp diff --git a/MatchBloxEngine/MatchBloxEngine.sln b/MatchBloxEngine/MatchBloxEngine.sln new file mode 100644 index 0000000..a924ae9 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MatchBloxEngine", "MatchBloxEngine\MatchBloxEngine.vcproj", "{76B80F87-6EFD-4439-9D32-86FA7BD83035}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {76B80F87-6EFD-4439-9D32-86FA7BD83035}.Debug|Win32.ActiveCfg = Debug|Win32 + {76B80F87-6EFD-4439-9D32-86FA7BD83035}.Debug|Win32.Build.0 = Debug|Win32 + {76B80F87-6EFD-4439-9D32-86FA7BD83035}.Release|Win32.ActiveCfg = Release|Win32 + {76B80F87-6EFD-4439-9D32-86FA7BD83035}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/MatchBloxEngine/MatchBloxEngine/C_3DObject.cpp b/MatchBloxEngine/MatchBloxEngine/C_3DObject.cpp new file mode 100644 index 0000000..a7482c7 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_3DObject.cpp @@ -0,0 +1,28 @@ +#include +#include "C_3DObject.h" + + +C_3DObject::C_3DObject(char* f_strFileName) +{ + //init position rotation and scale + m_d3Pos[0] = m_d3Pos[1] = m_d3Pos[2] = 0.0; + m_d3Rot[0] = m_d3Rot[1] = m_d3Rot[2] = 0.0; + m_d3Scale[0] = m_d3Scale[1] = m_d3Scale[2] = 1.0; + + //load 3d model + //Load(f_strFileName); +} + +void C_3DObject::TransRotateScale() +{ + glRotated(m_d3Rot[2], 0.0, 0.0, 1.0); + glRotated(m_d3Rot[0], 1.0, 0.0, 0.0); + glRotated(m_d3Rot[1], 0.0, 1.0, 0.0); + glTranslated(m_d3Pos[0], m_d3Pos[1], m_d3Pos[2]); + glScaled(m_d3Scale[0], m_d3Scale[1], m_d3Scale[2]); +} + +void C_3DObject::Draw() +{ + glutSolidCube(1.0); +} \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_3DObject.h b/MatchBloxEngine/MatchBloxEngine/C_3DObject.h new file mode 100644 index 0000000..9f194cc --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_3DObject.h @@ -0,0 +1,30 @@ +#ifndef C_3DOBJECT_HEADER_FILE + +#define C_3DOBJECT_HEADER_FILE + +class C_3DObject +{ +public: + C_3DObject(char* f_strFileName); + ~C_3DObject(); + + inline void SetPos(double f_dX, double f_dY, double f_dZ) { m_d3Pos[0] = f_dX; m_d3Pos[1] = f_dY; m_d3Pos[2] = f_dZ; } + inline void SetRot(double f_dX, double f_dY, double f_dZ) { m_d3Rot[0] = f_dX; m_d3Rot[1] = f_dY; m_d3Rot[2] = f_dZ; } + inline void SetScale(double f_dX, double f_dY, double f_dZ) { m_d3Scale[0] = f_dX; m_d3Scale[1] = f_dY; m_d3Scale[2] = f_dZ; } + + inline double* GetPos() { return m_d3Pos; } + inline double* GetRot() { return m_d3Rot; } + inline double* GetScale() { return m_d3Scale; } + + void TransRotateScale(); + virtual void Draw(); + +protected: + double m_d3Pos[3], + m_d3Rot[3], + m_d3Scale[3]; + + +}; + +#endif //C_3DOBJECT_HEADER_FILE \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_Block.cpp b/MatchBloxEngine/MatchBloxEngine/C_Block.cpp new file mode 100644 index 0000000..46d7621 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Block.cpp @@ -0,0 +1,49 @@ +#include +#include "C_Block.h" + +#define FADE_DURATION 500 + +C_Block::C_Block(char* f_strFileName) +: C_3DObject(f_strFileName), m_CurrState(IDLE), m_uiAnimStart(0) +{ +} + + +void C_Block::Draw(unsigned int f_iElapsedTime) +{ + unsigned int l_uiDeltaTime = f_iElapsedTime - m_uiAnimStart; + double l_Scale = 0.0; + + if (l_uiDeltaTime > g_BlockAnimDurations[(int)m_CurrState]) + { + m_CurrState = IDLE; + } + + glPushMatrix(); + TransRotateScale(); + + switch (m_CurrState) + { + case FADE_IN: + l_Scale = (double)l_uiDeltaTime / (double)g_BlockAnimDurations[FADE_IN]; + glScaled(l_Scale, l_Scale, l_Scale); + C_3DObject::Draw(); + break; + + case FADE_OUT: + l_Scale = 1.0 - ((double)l_uiDeltaTime / (double)g_BlockAnimDurations[FADE_OUT]); + glScaled(l_Scale, l_Scale, l_Scale); + C_3DObject::Draw(); + break; + + case COLLIDE: + break; + + case IDLE: + default: + C_3DObject::Draw(); + break; + } + + glPopMatrix(); +} \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_Block.h b/MatchBloxEngine/MatchBloxEngine/C_Block.h new file mode 100644 index 0000000..e76a676 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Block.h @@ -0,0 +1,31 @@ +#ifndef C_BLOCK_HEADER_FILE + +#define C_BLOCK_HEADER_FILE + +#include "C_3DObject.h" + +typedef enum BlockAnimState +{ + IDLE = 0, + FADE_IN = 1, + FADE_OUT = 2, + COLLIDE = 3 +}; + +unsigned int g_BlockAnimDurations[4] = {0, 500, 500, 500}; + +class C_Block : public C_3DObject +{ +public: + C_Block(char* f_strFileName); + ~C_Block(); + + void Draw(unsigned int f_iElapsedTime); + inline void SetState(BlockAnimState f_State, unsigned int f_uiElapsedTime) { m_CurrState = f_State; m_uiAnimStart = f_uiElapsedTime; } + +private: + BlockAnimState m_CurrState; + unsigned int m_uiAnimStart; +}; + +#endif //C_BLOCK_HEADER_FILE \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_Hand.cpp b/MatchBloxEngine/MatchBloxEngine/C_Hand.cpp new file mode 100644 index 0000000..54c1837 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Hand.cpp @@ -0,0 +1,41 @@ +#include +#include "C_Hand.h" + +#define FADE_DURATION 500 + +C_Hand::C_Hand(char* f_strFileName) +: C_3DObject(f_strFileName), m_CurrState(IDLE), m_uiAnimStart(0) +{ +} + + +void C_Hand::Draw(unsigned int f_iElapsedTime) +{ + unsigned int l_uiDeltaTime = f_iElapsedTime - m_uiAnimStart; + + if (l_uiDeltaTime > g_HandAnimDurations[(int)m_CurrState]) + { + m_CurrState = IDLE; + } + + glPushMatrix(); + TransRotateScale(); + + switch (m_CurrState) + { + case GRAB: + C_3DObject::Draw(); + break; + + case RELEASE: + C_3DObject::Draw(); + break; + + case IDLE: + default: + C_3DObject::Draw(); + break; + } + + glPopMatrix(); +} \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_Hand.h b/MatchBloxEngine/MatchBloxEngine/C_Hand.h new file mode 100644 index 0000000..706cf5f --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Hand.h @@ -0,0 +1,31 @@ +#ifndef C_HAND_HEADER_FILE + +#define C_HAND_HEADER_FILE + +#include "C_3DObject.h" + +typedef enum HandAnimState +{ + IDLE = 0, + GRAB = 1, + RELEASE = 2, +// COLLIDE = 3 +}; + +unsigned int g_HandAnimDurations[3] = {0, 100, 100}; + +class C_Hand : public C_3DObject +{ +public: + C_Hand(char* f_strFileName); + ~C_Hand(); + + void Draw(unsigned int f_iElapsedTime); + inline void SetState(HandAnimState f_State, unsigned int f_uiElapsedTime) { m_CurrState = f_State; m_uiAnimStart = f_uiElapsedTime; } + +private: + HandAnimState m_CurrState; + unsigned int m_uiAnimStart; +}; + +#endif //C_HAND_HEADER_FILE \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_Log.cpp b/MatchBloxEngine/MatchBloxEngine/C_Log.cpp new file mode 100644 index 0000000..d9a1154 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Log.cpp @@ -0,0 +1,24 @@ +#include "C_Log.h" + +C_Log::C_Log(char *f_strFileName) +{ +} + +C_Log::~C_Log() +{ +} + +bool C_Log::LogNewSession(int f_iUserID, int f_iGameID) +{ + return true; +} + +bool C_Log::LogSessionTurn(int f_iUserID, int f_iGameID, int f_iBlockNr, int HolePos, unsigned int f_uiTime) +{ + return true; +} + +bool C_Log::LogSessionTotals(int f_iUserID, int f_iGameID, unsigned int f_uiTotalTime) +{ + return true; +} diff --git a/MatchBloxEngine/MatchBloxEngine/C_Log.h b/MatchBloxEngine/MatchBloxEngine/C_Log.h new file mode 100644 index 0000000..a131cd5 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_Log.h @@ -0,0 +1,19 @@ +#ifndef C_LOG_HEADER_FILE + +#define C_LOG_HEADER_FILE + +class C_Log +{ +public: + C_Log(char *f_strFileName); + ~C_Log(); + + bool LogNewSession(int f_iUserID, int f_iGameID); + bool LogSessionTurn(int f_iUserID, int f_iGameID, int f_iBlockNr, int HolePos, unsigned int f_uiTime); + bool LogSessionTotals(int f_iUserID, int f_iGameID, unsigned int f_uiTotalTime); + +private: +// FILE *m_pLogFile; +}; + +#endif //C_LOG_HEADER_FILE \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp new file mode 100644 index 0000000..ed40038 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.cpp @@ -0,0 +1,42 @@ +#include "C_MatchBloxEngine.h" + +C_MatchBloxEngine::C_MatchBloxEngine(char *f_strModelPath, char *f_strLogFile) +{ +} + +C_MatchBloxEngine::~C_MatchBloxEngine() +{ +} + +GameResult C_MatchBloxEngine::GameStep(msgQueue &f_Queue) +{ +} + +void C_MatchBloxEngine::Draw(unsigned int f_uiElapsedTime) +{ +} + +bool C_MatchBloxEngine::NewGame(int f_iUserID, int f_iGameId) +{ + return false; +} + +bool C_MatchBloxEngine::StartGame() +{ + return false; +} + +bool C_MatchBloxEngine::Pause() +{ + return false; +} + +bool C_MatchBloxEngine::Resume() +{ + return false; +} + +bool C_MatchBloxEngine::Abort() +{ + return false; +} \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h new file mode 100644 index 0000000..f733bcc --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h @@ -0,0 +1,55 @@ +#ifndef C_MATCHBLOXENGINE_HEADER_FILE + +#define C_MATCHBLOXENGINE_HEADER_FILE + +#include "MessageQueue.h" + +class C_3DObject; +class C_Block; +class C_Hand; +class C_Log; + +typedef enum GameResult +{ + GR_FINISHED, + GR_BUSY, + GR_ERROR +} GameResult; + +enum EngineState +{ + ES_INITIALISED, + ES_ERROR, + ES_GET_READY, //game initialised, waiting for start signal from player + ES_PLAYING_GRAB_BLOCK, //no block in hand -> grab floating block + ES_PLAYING_PUT_BLOCK, //block in hand -> put block in box + ES_PAUSED, + ES_FINISHED +}; + +class C_MatchBloxEngine +{ + C_MatchBloxEngine(char *f_strModelPath, char *f_strLogFile); + ~C_MatchBloxEngine(); + +public: + GameResult GameStep(msgQueue &f_Queue); + void Draw(unsigned int f_uiElapsedTime); + + bool NewGame(int f_iUserID, int f_iGameId); + bool StartGame(); + bool Pause(); + bool Resume(); + bool Abort(); + +private: + C_Block *m_pBlock[4]; + C_Hand *m_pHand; + C_3DObject *m_pHole[4], + *m_pBox; + C_Log *m_pLog; + + EngineState m_State; +}; + +#endif //C_MATCHBLOXENGINE_HEADER_FILE \ No newline at end of file diff --git a/MatchBloxEngine/MatchBloxEngine/MatchBloxEngine.vcproj b/MatchBloxEngine/MatchBloxEngine/MatchBloxEngine.vcproj new file mode 100644 index 0000000..5bfdb0b --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/MatchBloxEngine.vcproj @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MatchBloxEngine/MatchBloxEngine/MessageQueue.h b/MatchBloxEngine/MatchBloxEngine/MessageQueue.h new file mode 100644 index 0000000..0edc388 --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/MessageQueue.h @@ -0,0 +1,19 @@ +#include + +typedef enum msgType +{ + MOUSE_MOVE, + MOUSE_PRESS, + KEY_PRESS, + SPECIAL_KEY, + WII_CURSOR_MOVE, + WII_BUTTON_PRESS +}; + +typedef struct message +{ + msgType m_MessageType; + int parm1, parm2, parm3, parm4; +} msgStruct; + +typedef std::queue msgQueue; diff --git a/MatchBloxEngine/MatchBloxEngine/main.cpp b/MatchBloxEngine/MatchBloxEngine/main.cpp new file mode 100644 index 0000000..df9e82d --- /dev/null +++ b/MatchBloxEngine/MatchBloxEngine/main.cpp @@ -0,0 +1,129 @@ +#include +#include + + +#include "MessageQueue.h" + +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 + +msgQueue g_Queue; + +void init_gl(void) +{ + glClearColor(0.2, 1, 0.2, 1); + glClearDepth(1000.0); +} // init_gl + +void idle_func(void) +{ + //call engine idle func + + glutPostRedisplay(); +} + +void render_scene(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + + glutSwapBuffers(); + +} // render_scene + + + +void process_normal_keys(unsigned char key, int x, int y) +{ + // escape + if (key == 27) + { + exit(0); + } + else + { + msgStruct l_msg; + l_msg.m_MessageType = KEY_PRESS; + l_msg.parm1 = key; + l_msg.parm2 = x; + l_msg.parm3 = y; + + g_Queue.push(l_msg); + } +} // process_normal_keys + + + +void process_special_keys(int key, int x, int y) +{ + switch (key) + { + // do sumting + } + msgStruct l_msg; + l_msg.m_MessageType = SPECIAL_KEY; + l_msg.parm1 = key; + l_msg.parm2 = x; + l_msg.parm3 = y; + + g_Queue.push(l_msg); + +} // process_special_keys + + + +void process_mouse(int button, int state, int x, int y) +{ + msgStruct l_msg; + l_msg.m_MessageType = MOUSE_PRESS; + l_msg.parm1 = button; + l_msg.parm2 = state; + l_msg.parm3 = x; + l_msg.parm4 = y; + + g_Queue.push(l_msg); + + +} // process_mouse + + + +void process_passive_mouse(int x, int y) +{ + //process_mouse(-1, -1, x, y); + msgStruct l_msg; + l_msg.m_MessageType = MOUSE_MOVE; + l_msg.parm1 = x; + l_msg.parm2 = y; + l_msg.parm3 = 0; + l_msg.parm4 = 0; + + g_Queue.push(l_msg); + +} // process_passive_mouse + + + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); + glutCreateWindow("Menu demo"); + glutDisplayFunc(render_scene); + glutIdleFunc(render_scene); + glutKeyboardFunc(process_normal_keys); + glutSpecialFunc(process_special_keys); + glutMouseFunc(process_mouse); + glutPassiveMotionFunc(process_passive_mouse); + + init_gl(); + //MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); + + glutMainLoop(); + + return 0; + +} // main + + -- cgit v0.12