-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Initial commit of the kinect headtracking code, node-js socket server,
and flash socket client code.
- Loading branch information
0 parents
commit 234a1a7
Showing
25 changed files
with
1,776 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "KCircle.h" | ||
|
||
|
||
KCircle::KCircle(void) | ||
{ | ||
// Initialize to zero-circle | ||
mCenter.mX = 0; | ||
mCenter.mY = 0; | ||
mCenter.mZ = 0; | ||
mCenter.mColor.r = 0; | ||
mCenter.mColor.b = 0; | ||
mCenter.mColor.g = 0; | ||
mRadius = 0; | ||
} | ||
|
||
KCircle::KCircle(KVertex Center, float radius){ | ||
// Control the radius and set it | ||
if( radius < 0 ) | ||
radius = -radius; | ||
|
||
mCenter = Center; | ||
mRadius = radius; | ||
} | ||
|
||
|
||
KCircle::~KCircle(void) | ||
{ | ||
} | ||
|
||
|
||
void KCircle::renderCircle(void) | ||
{ | ||
// Render the circle as a polygon, but only if there is a circle | ||
if(mRadius > 0) { | ||
glLineWidth(2); | ||
glBegin(GL_LINES); | ||
glColor3f(ITEM_LINE_COLOR); | ||
glVertex3f(mCenter.mX, mCenter.mY, mCenter.mZ); | ||
glVertex3f(mCenter.mX, mCenter.mY, -1); | ||
glEnd(); | ||
glLineWidth(1); | ||
|
||
glBegin(GL_POLYGON); | ||
// Define the color | ||
glColor3f( mCenter.mColor.r, | ||
mCenter.mColor.g, | ||
mCenter.mColor.b); | ||
|
||
// Paint the middle | ||
glVertex3f( mCenter.mX, | ||
mCenter.mY, | ||
mCenter.mZ); | ||
|
||
// Paint the outer circle | ||
for( double theta = 0.0; theta < 2*PI+2*PI/CIRCLE_ACCURACY ; theta += 2*PI / CIRCLE_ACCURACY ) { | ||
glVertex3f( mCenter.mX + cos( theta ) * mRadius, | ||
mCenter.mY + sin( theta ) * mRadius, | ||
mCenter.mZ ); | ||
} | ||
glEnd(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include "KVertex.h" | ||
#include "defines.h" | ||
#include <cmath> | ||
|
||
|
||
class KCircle | ||
{ | ||
public: | ||
KCircle(void); | ||
KCircle(KVertex Center, float radius); | ||
~KCircle(void); | ||
|
||
// Paints the Circle | ||
void renderCircle(void); | ||
KVertex mCenter; | ||
float mRadius; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "KGlutInput.h" | ||
|
||
|
||
KGlutInput::KGlutInput(void) | ||
{ | ||
} | ||
|
||
|
||
KGlutInput::~KGlutInput(void) | ||
{ | ||
} | ||
|
||
int KGlutInput::ButtonPressed_x = 0; | ||
int KGlutInput::ButtonPressed_y = 0; | ||
int KGlutInput::Delta_x = 0; | ||
int KGlutInput::Delta_y = 0; | ||
int KGlutInput::OldDelta_x = 0; | ||
int KGlutInput::OldDelta_y = 0; | ||
bool KGlutInput::ButtonPressed = false; | ||
|
||
void KGlutInput::glutMouse(int button, int state, int x , int y){ | ||
if(button==GLUT_LEFT_BUTTON) { | ||
if(state==GLUT_DOWN) { | ||
ButtonPressed = true; | ||
ButtonPressed_x = x; | ||
ButtonPressed_y = y; | ||
} | ||
else { | ||
ButtonPressed = false; | ||
OldDelta_x = Delta_x; | ||
OldDelta_y = Delta_y; | ||
} | ||
} | ||
} | ||
|
||
|
||
void KGlutInput::glutKeyboard(unsigned char key, int x, int y){ | ||
switch(key) { | ||
case 'r': | ||
case 'R': | ||
|
||
case 'c': | ||
case 'C': | ||
KProgram::kinect.calibrateUser(); | ||
break; | ||
case 'a': | ||
case 'A': | ||
KProgram::x2-=0.01; | ||
break; | ||
case 'q': | ||
case 'Q': | ||
KProgram::x2+=0.01; | ||
break; | ||
case 's': | ||
case 'S': | ||
KProgram::y2-=0.01; | ||
break; | ||
case 'w': | ||
case 'W': | ||
KProgram::y2+=0.01; | ||
break; | ||
case 'd': | ||
case 'D': | ||
KProgram::z2-=0.01; | ||
break; | ||
case 'e': | ||
case 'E': | ||
KProgram::z2+=0.01; | ||
break; | ||
} | ||
std::cout << "x: " << KProgram::x2 | ||
<< "\ty: " << KProgram::y2 | ||
<< "\tz: " << KProgram::z2 << std::endl; | ||
|
||
} | ||
|
||
|
||
void KGlutInput::glutMouseMotion(int x, int y){ | ||
if(ButtonPressed) { | ||
Delta_x = x-ButtonPressed_x+OldDelta_x; | ||
Delta_y = ButtonPressed_y-y+OldDelta_y; | ||
} | ||
} | ||
|
||
|
||
int KGlutInput::getMouseDeltaX(){ | ||
return Delta_x; | ||
} | ||
|
||
|
||
int KGlutInput::getMouseDeltaY(){ | ||
return Delta_y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
#include <cstdlib> | ||
#ifdef USE_GLUT | ||
#if (XN_PLATFORM == XN_PLATFORM_MACOSX) | ||
#include <GLUT/glut.h> | ||
#else | ||
#include <GL/glut.h> | ||
#endif | ||
#else | ||
#include "opengles.h" | ||
#endif | ||
|
||
#include "KProgram.h" | ||
|
||
|
||
|
||
class KGlutInput | ||
{ | ||
private: | ||
KGlutInput(void); | ||
~KGlutInput(void); | ||
|
||
public: | ||
static void glutMouse(int button, int state, int x , int y); | ||
static void glutKeyboard(unsigned char key, int x, int y); | ||
static void glutMouseMotion(int x, int y); | ||
static int getMouseDeltaX(); | ||
static int getMouseDeltaY(); | ||
|
||
private: | ||
static int ButtonPressed_x; | ||
static int ButtonPressed_y; | ||
static int Delta_x; | ||
static int Delta_y; | ||
static int OldDelta_x; | ||
static int OldDelta_y; | ||
static bool ButtonPressed; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#include "KGrid.h" | ||
|
||
KGrid::KGrid(int gridlines) | ||
{ | ||
// Control the gridlines | ||
if(gridlines < 0 ) | ||
gridlines = -gridlines; | ||
|
||
// Save the gridline-number | ||
mGridlines = gridlines; | ||
|
||
// Initialize the Vertex-Field | ||
mVertexField = 0; | ||
mVertexFieldSize = 0; | ||
|
||
// Create the Grid | ||
createGrid(); | ||
} | ||
|
||
|
||
KGrid::~KGrid(void) | ||
{ | ||
// Delete the vertices | ||
if(mVertexFieldSize > 0) | ||
{ | ||
delete [] mVertexField; | ||
mVertexFieldSize = 0; | ||
} | ||
} | ||
|
||
|
||
// Renders the grid | ||
void KGrid::renderGrid(float x, float y, float z) | ||
{ | ||
// Begin Painting | ||
|
||
// First get the modelview-matrix | ||
glMatrixMode(GL_MODELVIEW); | ||
glPushMatrix(); | ||
|
||
// Transfer the whole scene backwards | ||
glTranslatef(0,0,-z/2); | ||
|
||
|
||
// Paint the back | ||
// that means pushing the whole scene back | ||
// Remember: The grid is normalized! | ||
// and to the middle | ||
glPushMatrix(); | ||
glTranslatef(-x/2,-y/2,-z/2); | ||
glScalef(x,y,1.0f); | ||
paintGrid(); | ||
glPopMatrix(); | ||
|
||
|
||
// Paint the right and left wall | ||
// that means rotate the whole scene | ||
// place it right | ||
glPushMatrix(); | ||
glRotatef(90,0,1,0); | ||
glScalef(z,y,1.0f); | ||
glTranslatef(-0.5,-0.5,-x/2); | ||
paintGrid(); | ||
glTranslatef(0,0,x); | ||
paintGrid(); | ||
glPopMatrix(); | ||
|
||
|
||
// Paint the floor and ceiling | ||
// that means rotate the whole scene | ||
// place it right | ||
glPushMatrix(); | ||
glRotatef(90,1,0,0); | ||
glScalef(x,z,1.0f); | ||
glTranslatef(-0.5,-0.5,-y/2); | ||
paintGrid(); | ||
glTranslatef(0,0,y); | ||
paintGrid(); | ||
glPopMatrix(); | ||
|
||
// Get back the first matrix | ||
glPopMatrix(); | ||
|
||
} | ||
|
||
|
||
void KGrid::createGrid(void) | ||
{ | ||
// Ensure, that there are are more gridlines | ||
if(mGridlines >= 0){ | ||
|
||
// Create a new Vertex-field | ||
mVertexField = new KVertex [4 * (mGridlines + 2)]; | ||
mVertexFieldSize = 4 * (mGridlines + 2); | ||
|
||
// Run over the field | ||
for(int i = 0 ; i < mVertexFieldSize / 2 ; i = i + 2){ | ||
mVertexField[i].mX = 1.0f * i / (mGridlines + 1) / 2.0f; | ||
mVertexField[i].mY = 0; | ||
mVertexField[i].setColor(GRID_LINE_COLOR); | ||
mVertexField[i+1].mX = 1.0f * i / (mGridlines + 1) / 2.0f; | ||
mVertexField[i+1].mY = 1.0f; | ||
mVertexField[i+1].setColor(GRID_LINE_COLOR); | ||
} | ||
|
||
for(int i = mVertexFieldSize / 2 ; i < mVertexFieldSize ; i = i + 2){ | ||
mVertexField[i].mY = 1.0 * (i - mVertexFieldSize / 2.0f) / (mGridlines + 1) / 2.0f; | ||
mVertexField[i].mX = 0.0f; | ||
mVertexField[i].setColor(GRID_LINE_COLOR); | ||
mVertexField[i+1].mY = 1.0 * (i - mVertexFieldSize / 2.0f) / (mGridlines + 1) / 2.0f; | ||
mVertexField[i+1].mX = 1.0f; | ||
mVertexField[i+1].setColor(GRID_LINE_COLOR); | ||
} | ||
|
||
} | ||
} | ||
|
||
void KGrid::paintGrid(void){ | ||
glBegin(GL_LINES); | ||
// Render each single point | ||
for(int i = 0 ; i < mVertexFieldSize ; i++){ | ||
mVertexField[i].paintVertex(); | ||
} | ||
glEnd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include "defines.h" | ||
#include "KVertex.h" | ||
|
||
|
||
class KGrid | ||
{ | ||
public: | ||
KGrid(int gridlines); | ||
~KGrid(void); | ||
|
||
|
||
// Renders the grid with dimensions x , y , z | ||
void renderGrid(float x, float y, float z); | ||
|
||
|
||
private: | ||
// Saves the number of gridlines | ||
int mGridlines; | ||
|
||
// Saves the vertices | ||
KVertex* mVertexField; | ||
int mVertexFieldSize; | ||
|
||
// Create the grid | ||
void createGrid(void); | ||
void paintGrid(void); | ||
}; | ||
|
Oops, something went wrong.