Skip to content
Browse files

Fixed Eye Calibration

  • Loading branch information...
1 parent adc3b56 commit 00cd62dc819229d20383ad25a1c31c568e8589ac @mdfeist committed Jun 17, 2013
View
20 BlinkAnalysis/AppViewer.cpp
@@ -31,6 +31,8 @@
osgViewer::Viewer* viewer;
osg::Group* rootNode;
+osg::Vec3 lastRay;
+
bool running = false;
bool visible = false;
@@ -70,19 +72,33 @@ void renderEyeVector(osg::Geode* node) {
osg::Matrixf headMatrix;
headMatrix.makeIdentity();
- headMatrix.makeTranslate(head->getPosition());
+ //headMatrix.makeTranslate(head->getPosition());
headMatrix.makeRotate(head->getRotation());
Dikablis::journal_struct journal = Dikablis::getJournal();
int x = journal.field_x;
int y = journal.field_y;
+ /*
+ static int x = 0;
+ static int y = 250;
+ static float animation = 0.0f;
+
+ animation += 0.01f;
+
+ x = sinf(animation)*(250) + 250;
+ */
+
osg::Vec3 ray = client->getRay(x, y);
ray = headMatrix * ray;
- points->push_back( ray * VIEWER_SCALE );
+ ray = (ray - lastRay)/4.f + lastRay;
+
+ lastRay = ray;
+
+ points->push_back( (ray + pos) * VIEWER_SCALE );
colors->push_back(osg::Vec4(1, 0, 0, 1));
}
}
View
12 BlinkAnalysis/ClientHandler.cpp
@@ -45,7 +45,7 @@ ClientHandler::ClientHandler(void)
this->dikablisEyeVectorArray = (float*) malloc(sizeof(float) * ClientHandler::DikablisViewingSize);
- this->headid = 0;
+ this->headid = -1;
}
// Cleans up the ClientHandler
@@ -74,11 +74,13 @@ osg::Vec3 ClientHandler::getRay(int x, int y) {
int i = x + DikablisViewingMargin;
int j = y + DikablisViewingMargin;
- int loc = 3*((j*DikablisViewingWidth+2*DikablisViewingMargin) + i);
+ int loc = 3*((j*(DikablisViewingWidth+2*DikablisViewingMargin)) + i);
- ray.x() = this->dikablisEyeVectorArray[loc + 0];
- ray.y() = this->dikablisEyeVectorArray[loc + 1];
- ray.z() = this->dikablisEyeVectorArray[loc + 2];
+ if (loc >= 0 && loc < DikablisViewingSize) {
+ ray.x() = this->dikablisEyeVectorArray[loc + 0];
+ ray.y() = this->dikablisEyeVectorArray[loc + 1];
+ ray.z() = this->dikablisEyeVectorArray[loc + 2];
+ }
}
return ray;
View
4 BlinkAnalysis/Dikablis.cpp
@@ -96,7 +96,9 @@ void recieved(std::string msg) {
sscanf_s(split[16].c_str(), "%d", &journal.field_y);
}
- dikablisJournal = journal;
+ if (journal.eye_valid) {
+ dikablisJournal = journal;
+ }
// Pass the journal information to the MainForm so it can be displayed
MainFormController::getInstance()->dikablisMessage(journal);
View
21 BlinkAnalysis/EyeCalibration.cpp
@@ -8,6 +8,7 @@
#include <algorithm> // std::sort
#include <iostream>
#include <fstream>
+#include <math.h>
#include <osg/Matrix>
@@ -63,7 +64,7 @@ bool EyeCalibration::addPoint() {
osg::Matrixf headMatrix;
headMatrix.makeIdentity();
- headMatrix.makeTranslate(head->getPosition());
+ //headMatrix.makeTranslate(head->getPosition());
headMatrix.makeRotate(head->getRotation());
if (!headMatrix.invert_4x4(headMatrix))
@@ -73,7 +74,7 @@ bool EyeCalibration::addPoint() {
ray = viewing->getPosition() - head->getPosition();
ray = headMatrix * ray;
ray.normalize();
- ray = ray/ray.y();
+ //ray = ray/ray.y();
Dikablis::journal_struct journal;
journal = Dikablis::getJournal();
@@ -752,9 +753,9 @@ bool EyeCalibration::calibrate() {
}
}
}
+#endif
saveRayMap();
-#endif
ClientHandler* client = AppData::getInstance()->getClient();
@@ -972,6 +973,14 @@ void EyeCalibration::saveRayMap() {
WriteFile(file,&fileHeader,sizeof(fileHeader),&write,NULL);
WriteFile(file,&fileInfo,sizeof(fileInfo),&write,NULL);
+
+ float max = 0.f;
+ for (unsigned int i = 0; i < (viewingWidth+2*viewingMargin)*(viewingHeight+2*viewingMargin); i++) {
+ float value = fabsf(this->eyeVectorArray[i]);
+
+ if (value > max)
+ max = value;
+ }
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
@@ -981,9 +990,9 @@ void EyeCalibration::saveRayMap() {
int pi_height = (((float)j/height)*(viewingHeight+2*viewingMargin));
int pi = 3*(pi_height*(viewingWidth+2*viewingMargin) + pi_width);
- int blue = this->eyeVectorArray[pi + 2];
- int green = this->eyeVectorArray[pi + 1];
- int red = this->eyeVectorArray[pi + 0];
+ int blue = ((this->eyeVectorArray[pi + 2] + max)/(2*max))*255;
+ int green = ((this->eyeVectorArray[pi + 1] + max)/(2*max))*255;
+ int red = ((this->eyeVectorArray[pi + 0] + max)/(2*max))*255;
if (blue < 0)
blue = 0;
View
8 BlinkAnalysis/NatNetClientSetup.cpp
@@ -343,8 +343,14 @@ void __cdecl DataHandler(sFrameOfMocapData* data, void* pUserData)
float x = -data->RigidBodies[i].x;
float z = data->RigidBodies[i].y;
float y = data->RigidBodies[i].z;
+
+ float qx = data->RigidBodies[i].qx;
+ float qy = -data->RigidBodies[i].qz;
+ float qz = -data->RigidBodies[i].qy;
+ float qw = data->RigidBodies[i].qw;
+
body->addFrame(osg::Vec3(x, y, z),
- osg::Vec4(data->RigidBodies[i].qx, -data->RigidBodies[i].qz, -data->RigidBodies[i].qy, data->RigidBodies[i].qw));
+ osg::Vec4(qx, qy, qz, qw));
// Clear all the previous markers that were attached to the Rigid Body
body->clearMarkers();
View
BIN BlinkAnalysis/rayMap.bmp
Binary file not shown.

0 comments on commit 00cd62d

Please sign in to comment.
Something went wrong with that request. Please try again.