From e58a5c5e7bf915703556013a8323953866f0adb8 Mon Sep 17 00:00:00 2001 From: Wilrik de Loose Date: Tue, 20 May 2008 17:15:44 +0000 Subject: + wiimote init --- matchblox/common/message_input.h | 9 ++++ matchblox/engine/typedefs.h | 38 ++++++++++++- matchblox/lib/WiiYourself!.lib | Bin 0 -> 25718 bytes matchblox/lib/glew32.lib | Bin 0 -> 310996 bytes matchblox/main.cpp | 112 +++++++++++++++++++++++++++++++++++++-- matchblox/matchblox.vcproj | 16 ++++-- 6 files changed, 166 insertions(+), 9 deletions(-) create mode 100644 matchblox/lib/WiiYourself!.lib create mode 100644 matchblox/lib/glew32.lib diff --git a/matchblox/common/message_input.h b/matchblox/common/message_input.h index a54fe9b..f06e610 100644 --- a/matchblox/common/message_input.h +++ b/matchblox/common/message_input.h @@ -30,6 +30,15 @@ struct input_payload_mouse int y; }; +struct input_payload_wiimote +{ + int passive; + int button; + int state; + int x; + int y; +}; + #ifdef __cplusplus } #endif diff --git a/matchblox/engine/typedefs.h b/matchblox/engine/typedefs.h index 7acb776..3821bc6 100644 --- a/matchblox/engine/typedefs.h +++ b/matchblox/engine/typedefs.h @@ -2,9 +2,11 @@ #define TYPEDEFS_H +#include #include -#include +#include +#undef max typedef struct vec3d { @@ -150,7 +152,39 @@ typedef struct geom m_norms, m_texs; std::vector m_triangles; -} Geometry_t; +} Geometry_t; + +typedef struct FrustumParms +{ + double m_dHeadTrackLedDist; //distance between leds on head in millimeters + double m_dRadPerCameraPixel; //radians per camera pixel + double m_dCameraXCenter; //the coordinates of the center of the camera + double m_dCameraYCenter; // + double m_dYAngleCorrection; //the correction added to the verticle angle measured by the camera (in radians) + double m_dCameraYOffset; //the offset in Y direction of the camera relative to the center of the screen (in mm) + double m_dScreenHeightMM; //the height of the screen (in mm) + double m_dScreenAspect; //the aspect ratio of the screen (width/height) + double m_dScreenHeightWorld; //the height of the screen (in world coordinates) + double m_dEyeDistMM; //distance between the eyes (in mm) + double m_dDefHeadDistMM; //default distance between head and display (in mm) +} FrustumParms_t; + +typedef enum EyeOrigin { + STEREO_LEFT_EYE = 0, + STEREO_RIGHT_EYE = 1, + MONO_CENTER = 2 +} EyeOrigin_t; + +typedef struct GameState +{ + FrustumParms_t m_FrustumParms; + bool m_bHeadTrackingEnabled; + bool m_bStereoEnabled; + wiimote *m_pTrackingWiimote; + GLuint m_GreyScaleShaderProgram; //handle to the grayscale shader program + GLint m_GSConvScaleLoc; //handle to the g_ConversionScale variable in the shader + GLfloat m_GSConvScale[3]; //grayscale conversion scale (default 0.299, 0.587, 0.114) +} GameState_t; #endif //TYPEDEFS_H diff --git a/matchblox/lib/WiiYourself!.lib b/matchblox/lib/WiiYourself!.lib new file mode 100644 index 0000000..0af7d02 Binary files /dev/null and b/matchblox/lib/WiiYourself!.lib differ diff --git a/matchblox/lib/glew32.lib b/matchblox/lib/glew32.lib new file mode 100644 index 0000000..4f2e32c Binary files /dev/null and b/matchblox/lib/glew32.lib differ diff --git a/matchblox/main.cpp b/matchblox/main.cpp index d6cc0b4..6d89b6a 100644 --- a/matchblox/main.cpp +++ b/matchblox/main.cpp @@ -6,6 +6,10 @@ #define TRUE !FALSE #endif + +#include +#include +#include #include #include @@ -13,7 +17,9 @@ #include "message_queue.h" #include "message_input.h" +#include "typedefs.h" #include "menu.h" +#include "textfile.h" #include "C_MatchBloxEngine.h" @@ -22,9 +28,102 @@ #define KEY_ESCAPE 27 - +GameState_t g_GameState; C_MatchBloxEngine *g_pEngine; +bool InitWiiMotes() +{ + g_GameState.m_pTrackingWiimote = new wiimote(); + + g_GameState.m_pTrackingWiimote->ChangedCallback = NULL; //no callbacks, we just poll... + g_GameState.m_pTrackingWiimote->CallbackTriggerFlags = NO_CHANGE; + + printf("connecting:\n"); + int retries = 10; + while(!g_GameState.m_pTrackingWiimote->Connect(wiimote::FIRST_AVAILABLE) && retries > 10) + { + Sleep(100); + printf("."); + retries--; + } + + if (g_GameState.m_pTrackingWiimote->IsConnected()) + { + printf("connected\n"); + + g_GameState.m_pTrackingWiimote->SetLEDs(0x0f); + + g_GameState.m_pTrackingWiimote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT); // IR dots + g_GameState.m_pTrackingWiimote->SetRumble(true); + Sleep(500); + g_GameState.m_pTrackingWiimote->SetRumble(false); + + return true; + } + else + { + return false; + } +} + +bool LoadGreyScaleShader() +{ + GLint l_bStatus; + char *vs_text = NULL,*fs_text = NULL; + GLuint vs = glCreateShader(GL_VERTEX_SHADER), + fs = glCreateShader(GL_FRAGMENT_SHADER); + + vs_text = textFileRead("shaders\\greyscale.vert"); + if (vs_text == NULL) + { + return false; + } + fs_text = textFileRead("shaders\\greyscale.frag"); + if (fs_text == NULL) + { + free(vs_text); + return false; + } + + glShaderSource(vs, 1, (const char**)&vs_text,NULL); + glShaderSource(fs, 1, (const char**)&fs_text,NULL); + + free(vs_text); + free(fs_text); + + glCompileShader(vs); +// printShaderInfoLog(vs); + glGetShaderiv(vs, GL_COMPILE_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + glCompileShader(fs); +// printShaderInfoLog(fs); + glGetShaderiv(fs, GL_COMPILE_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + g_GameState.m_GreyScaleShaderProgram = glCreateProgram(); + glAttachShader(g_GameState.m_GreyScaleShaderProgram,fs); + glAttachShader(g_GameState.m_GreyScaleShaderProgram,vs); + + glLinkProgram(g_GameState.m_GreyScaleShaderProgram); +// printProgramInfoLog(g_GameState.m_GreyScaleShaderProgram); + glGetProgramiv(g_GameState.m_GreyScaleShaderProgram, GL_LINK_STATUS, &l_bStatus); + if (l_bStatus == GL_FALSE) + { + return false; + } + + g_GameState.m_GSConvScaleLoc = glGetUniformLocation(g_GameState.m_GreyScaleShaderProgram, "g_ConversionWeights"); + + return true; +} + void init_gl(void) { GLfloat l_fLightpos[4] = {0.0, 1.0, 1.0, 0.0}; @@ -46,6 +145,8 @@ void idle_func(void) //call engine idle func MenuRun(); + g_GameState.m_pTrackingWiimote->RefreshState(); + glutPostRedisplay(); } @@ -54,10 +155,10 @@ void render_scene(void) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); g_pEngine->Render(glutGet(GLUT_ELAPSED_TIME)); - + glDisable(GL_LIGHTING); MenuRender(); - glEnable(GL_LIGHTING); + glEnable(GL_LIGHTING); glutSwapBuffers(); @@ -112,6 +213,9 @@ void process_special_keys(int key, int x, int y) switch (key) { // do sumting + case 0: + default: + break; } @@ -153,7 +257,7 @@ int main(int argc, char **argv) init_gl(); MenuInit(SCREEN_WIDTH, SCREEN_HEIGHT); - + InitWiiMotes(); GameSettings l_set = {10, 2, 2}; g_pEngine = new C_MatchBloxEngine("models", "", l_set); diff --git a/matchblox/matchblox.vcproj b/matchblox/matchblox.vcproj index c4cedaf..86601a1 100644 --- a/matchblox/matchblox.vcproj +++ b/matchblox/matchblox.vcproj @@ -20,6 +20,8 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="1" + UseOfMFC="0" + UseOfATL="0" CharacterSet="1" > + + + + -- cgit v0.12