summaryrefslogtreecommitdiffstats
path: root/headtrack_stereo_demo/src/glutcallbacks.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'headtrack_stereo_demo/src/glutcallbacks.cpp')
-rw-r--r--headtrack_stereo_demo/src/glutcallbacks.cpp187
1 files changed, 187 insertions, 0 deletions
diff --git a/headtrack_stereo_demo/src/glutcallbacks.cpp b/headtrack_stereo_demo/src/glutcallbacks.cpp
new file mode 100644
index 0000000..9b582f8
--- /dev/null
+++ b/headtrack_stereo_demo/src/glutcallbacks.cpp
@@ -0,0 +1,187 @@
+#include <wiimote.h>
+#include <GL\glew.h>
+#include <GL\glut.h>
+
+#include "typedefs.h"
+#include "stereoheadtrackfrustum.h"
+#include "scenerenderer.h"
+
+extern GameState_t g_GameState;
+
+void ExitProgram()
+{
+ printf("Finished!\n");
+
+
+ //we prolly should do some cleanup
+ if (g_GameState.m_pTrackingWiimote != NULL)
+ {
+ g_GameState.m_pTrackingWiimote->Disconnect();
+ delete g_GameState.m_pTrackingWiimote;
+ }
+
+ exit(0);
+}
+
+void Keyboard(unsigned char f_cKey, int f_iX, int f_iY)
+{
+ switch(f_cKey)
+ {
+ case 'q':
+ case 'Q':
+ case 27 :
+ ExitProgram();
+ break;
+
+ case 's':
+ case 'S': //enable /disable stereo vision
+ g_GameState.m_bStereoEnabled = !g_GameState.m_bStereoEnabled;
+
+ if (g_GameState.m_bStereoEnabled)
+ {
+ //enable greyscale shader
+ glUseProgram(g_GameState.m_GreyScaleShaderProgram);
+ }
+ else
+ {
+ //disable greyscale shader
+ glUseProgram(0);
+ }
+ break;
+
+ case 'h':
+ case 'H': //enable disable head tracking
+ if (g_GameState.m_pTrackingWiimote != NULL && g_GameState.m_pTrackingWiimote->IsConnected())
+ {
+ g_GameState.m_bHeadTrackingEnabled = !g_GameState.m_bHeadTrackingEnabled;
+ }
+ break;
+
+ case ' ':
+ ////set y angle correction to current y angle of the the center of the two ir dots
+ //if (g_Wiimote.IsConnected())
+ //{
+ // wiimote_state::ir::dot l_Dot[2]; //shorthand to the ir dots
+ // //check if we see at least 2 IR dots
+ // if (FindIRDots(&g_Wiimote.IR, l_Dot))
+ // {
+ // //calculate the distance of the head (in mm)
+ // double l_dHeadDistInMM = CalcHeadDistInMM(l_Dot, &g_GameState.m_HeadTrackParms), //the distance between the head and camera (in mm)
+ // l_dEyeYCam = (double)(l_Dot[0].RawY + l_Dot[1].RawY) / 2.0;
+ //
+ // // of the eye relative to the camera
+ // g_GameState.m_HeadTrackParms.m_dYAngleCorrection = g_GameState.m_HeadTrackParms.m_dRadPerCameraPixel * (l_dEyeYCam - g_GameState.m_HeadTrackParms.m_dCameraYCenter);
+ // }
+ //}
+ break;
+ }
+}
+
+void Display(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ double l_d3EyePosInMM[3];
+ bool l_bEyeLocated;
+
+ if (g_GameState.m_bStereoEnabled)
+ {
+ for (int CurrentEye=0; CurrentEye<2; CurrentEye++) //STEREO_LEFT_EYE = 0, STEREO_RIGHT_EYE = 1
+ {
+ l_bEyeLocated = false;
+ if (g_GameState.m_bHeadTrackingEnabled)
+ {
+ l_bEyeLocated = CalcEyePosInMM(g_GameState.m_pTrackingWiimote,
+ (EyeOrigin_t)CurrentEye,
+ g_GameState.m_FrustumParms,
+ l_d3EyePosInMM);
+ }
+ if(!l_bEyeLocated)
+ {
+ //set default eye coordinates
+ l_d3EyePosInMM[0] = g_GameState.m_FrustumParms.m_dEyeDistMM * ((double)CurrentEye - 0.5);
+ l_d3EyePosInMM[1] = 0.0;
+ l_d3EyePosInMM[2] = g_GameState.m_FrustumParms.m_dDefHeadDistMM;
+ }
+
+ //set colormask
+ if (CurrentEye == STEREO_LEFT_EYE)
+ {
+ glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
+ }
+ else
+ {
+ glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+
+ //clear depth buffers
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ //set frustum
+ SetFrustum(g_GameState.m_FrustumParms, l_d3EyePosInMM);
+
+ RenderScene();
+ }
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+ else // !g_GameState.m_bStereoEnabled
+ {
+ l_bEyeLocated = false;
+ if (g_GameState.m_bHeadTrackingEnabled)
+ {
+ l_bEyeLocated = CalcEyePosInMM(g_GameState.m_pTrackingWiimote,
+ MONO_CENTER,
+ g_GameState.m_FrustumParms,
+ l_d3EyePosInMM);
+ }
+ if(!l_bEyeLocated)
+ {
+ //set default eye coordinates
+ l_d3EyePosInMM[0] = 0.0;
+ l_d3EyePosInMM[1] = 0.0;
+ l_d3EyePosInMM[2] = g_GameState.m_FrustumParms.m_dDefHeadDistMM;
+ }
+
+ //clear depth buffer
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ //set frustum
+ SetFrustum(g_GameState.m_FrustumParms, l_d3EyePosInMM);
+
+ RenderScene();
+ }
+
+ glutSwapBuffers();
+
+} // Display
+
+
+void Idle(void)
+{
+ if (g_GameState.m_pTrackingWiimote != NULL && g_GameState.m_pTrackingWiimote->IsConnected())
+ {
+ g_GameState.m_pTrackingWiimote->RefreshState();
+ }
+
+ glutPostRedisplay();
+}
+
+void Reshape(int f_iWidth, int f_iHeight)
+{
+ //set the new viewport dimension
+ glViewport(0, 0, f_iWidth, f_iHeight);
+
+ //should we set a new projection matrix?
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ double l_dHalfHeight = 0.5 * g_GameState.m_FrustumParms.m_dScreenHeightWorld,
+ l_dHalfWidth = l_dHalfHeight * g_GameState.m_FrustumParms.m_dScreenAspect,
+ l_zNear = 2.0 * g_GameState.m_FrustumParms.m_dScreenHeightWorld;
+
+ glFrustum(-l_dHalfWidth, l_dHalfWidth, -l_dHalfHeight, l_dHalfHeight, l_zNear, l_zNear + 1000.0);
+ glTranslated(0.0, 0.0, -l_zNear);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+} \ No newline at end of file