diff options
author | Wilrik de Loose <wilrik@wilrik.nl> | 2008-05-20 17:15:44 (GMT) |
---|---|---|
committer | Wilrik de Loose <wilrik@wilrik.nl> | 2008-05-20 17:15:44 (GMT) |
commit | e58a5c5e7bf915703556013a8323953866f0adb8 (patch) | |
tree | 10a9a50217ec92a3270c74c7bf3d917c8d62ac93 /matchblox | |
parent | c7c995631d14d5c65d538422159b782752e9357c (diff) | |
download | 2iv55-e58a5c5e7bf915703556013a8323953866f0adb8.zip 2iv55-e58a5c5e7bf915703556013a8323953866f0adb8.tar.gz 2iv55-e58a5c5e7bf915703556013a8323953866f0adb8.tar.bz2 |
+ wiimote init
Diffstat (limited to 'matchblox')
-rw-r--r-- | matchblox/common/message_input.h | 9 | ||||
-rw-r--r-- | matchblox/engine/typedefs.h | 38 | ||||
-rw-r--r-- | matchblox/lib/WiiYourself!.lib | bin | 0 -> 25718 bytes | |||
-rw-r--r-- | matchblox/lib/glew32.lib | bin | 0 -> 310996 bytes | |||
-rw-r--r-- | matchblox/main.cpp | 112 | ||||
-rw-r--r-- | matchblox/matchblox.vcproj | 16 |
6 files changed, 166 insertions, 9 deletions
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 <wiimote.h> #include <vector> -#include <limits> +#include <limits>
+#undef max typedef struct vec3d { @@ -150,7 +152,39 @@ typedef struct geom m_norms, m_texs; std::vector<Triangle_t> 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 Binary files differnew file mode 100644 index 0000000..0af7d02 --- /dev/null +++ b/matchblox/lib/WiiYourself!.lib diff --git a/matchblox/lib/glew32.lib b/matchblox/lib/glew32.lib Binary files differnew file mode 100644 index 0000000..4f2e32c --- /dev/null +++ b/matchblox/lib/glew32.lib 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 <wiimote.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
#include <iostream>
#include <math.h>
@@ -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"
>
<Tool
@@ -40,11 +42,11 @@ <Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="include;common;menu;engine"
+ AdditionalIncludeDirectories="include;common;menu;engine;lib"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
- RuntimeLibrary="3"
+ RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
@@ -61,7 +63,7 @@ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="glut32.lib"
+ AdditionalDependencies="glut32.lib glew32.lib wiiyourself!.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="lib"
GenerateDebugInformation="true"
@@ -229,6 +231,10 @@ RelativePath=".\common\message_queue.c"
>
</File>
+ <File
+ RelativePath=".\common\textfile.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -288,6 +294,10 @@ >
</File>
<File
+ RelativePath=".\common\textfile.h"
+ >
+ </File>
+ <File
RelativePath=".\engine\typedefs.h"
>
</File>
|