Commit 872479cc by Kai Westerkamp

asdf

parent 31eb724a
...@@ -17,9 +17,9 @@ std::string SteamTracking::getDeviceTypeAsString(vr::ETrackedDeviceClass device_ ...@@ -17,9 +17,9 @@ std::string SteamTracking::getDeviceTypeAsString(vr::ETrackedDeviceClass device_
return type; return type;
} }
glm::mat3x4 SteamTracking::convertMatrix(vr::HmdMatrix34_t in) glm::mat3x4* SteamTracking::convertMatrix(vr::HmdMatrix34_t in)
{ {
return glm::mat3x4(in.m[0][0], in.m[0][1], in.m[0][2], in.m[0][3], return new glm::mat3x4(in.m[0][0], in.m[0][1], in.m[0][2], in.m[0][3],
in.m[1][0], in.m[1][1], in.m[1][2], in.m[1][3], in.m[1][0], in.m[1][1], in.m[1][2], in.m[1][3],
in.m[2][0], in.m[2][1], in.m[2][2], in.m[2][3] ); in.m[2][0], in.m[2][1], in.m[2][2], in.m[2][3] );
} }
...@@ -93,10 +93,10 @@ void SteamTracking::printMatrix(const vr::HmdMatrix34_t &htm) ...@@ -93,10 +93,10 @@ void SteamTracking::printMatrix(const vr::HmdMatrix34_t &htm)
} }
} }
glm::mat3x4 SteamTracking::getTransformationForDevice(int nDevice) glm::mat3x4* SteamTracking::getTransformationForDevice(int nDevice)
{ {
if (!vr_system_) { if (!vr_system_) {
return glm::mat3x4(); return new glm::mat3x4();
} }
vr_system_->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseRawAndUncalibrated, 0, tracked_device_poses_, vr::k_unMaxTrackedDeviceCount); vr_system_->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseRawAndUncalibrated, 0, tracked_device_poses_, vr::k_unMaxTrackedDeviceCount);
...@@ -104,7 +104,7 @@ glm::mat3x4 SteamTracking::getTransformationForDevice(int nDevice) ...@@ -104,7 +104,7 @@ glm::mat3x4 SteamTracking::getTransformationForDevice(int nDevice)
if (!tracked_device_poses_[nDevice].bPoseIsValid) if (!tracked_device_poses_[nDevice].bPoseIsValid)
{ {
if (debug) std::cout << " Device " << nDevice << "Pois is Invalid"; if (debug) std::cout << " Device " << nDevice << "Pois is Invalid";
return glm::mat3x4(); return new glm::mat3x4();
} }
vr::ETrackedDeviceClass device_class = vr_system_->GetTrackedDeviceClass(nDevice); vr::ETrackedDeviceClass device_class = vr_system_->GetTrackedDeviceClass(nDevice);
...@@ -112,7 +112,7 @@ glm::mat3x4 SteamTracking::getTransformationForDevice(int nDevice) ...@@ -112,7 +112,7 @@ glm::mat3x4 SteamTracking::getTransformationForDevice(int nDevice)
if (device_class == vr::TrackedDeviceClass_Invalid) if (device_class == vr::TrackedDeviceClass_Invalid)
{ {
if (debug) std::cout << " Device " << nDevice << "ist Invalid"; if (debug) std::cout << " Device " << nDevice << "ist Invalid";
return glm::mat3x4(); return new glm::mat3x4();
} }
vr::HmdMatrix34_t htm = tracked_device_poses_[nDevice].mDeviceToAbsoluteTracking; vr::HmdMatrix34_t htm = tracked_device_poses_[nDevice].mDeviceToAbsoluteTracking;
......
...@@ -15,7 +15,7 @@ private: ...@@ -15,7 +15,7 @@ private:
std::string getDeviceTypeAsString(vr::ETrackedDeviceClass device_class); std::string getDeviceTypeAsString(vr::ETrackedDeviceClass device_class);
glm::mat3x4 convertMatrix(vr::HmdMatrix34_t in); glm::mat3x4* convertMatrix(vr::HmdMatrix34_t in);
void printMatrix(const vr::HmdMatrix34_t &htm); void printMatrix(const vr::HmdMatrix34_t &htm);
...@@ -26,7 +26,7 @@ public: ...@@ -26,7 +26,7 @@ public:
void printVRDevices(); void printVRDevices();
glm::mat3x4 getTransformationForDevice(int nDevice); glm::mat3x4* getTransformationForDevice(int nDevice);
}; };
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
GLuint vboId; GLuint vboId;
GLuint cboId; GLuint cboId;
GLuint vboIdArrow;
GLuint cboIdArrow;
float arrowPoints[] = { 1, 0 , 0, 0, 1, 0, 0, 0, 1
};
// Intermediate Buffers // Intermediate Buffers
unsigned char rgbimage[colorwidth*colorheight*4]; // Stores RGB color image unsigned char rgbimage[colorwidth*colorheight*4]; // Stores RGB color image
ColorSpacePoint depth2rgb[width*height]; // Maps depth pixels to rgb pixels ColorSpacePoint depth2rgb[width*height]; // Maps depth pixels to rgb pixels
...@@ -41,8 +47,42 @@ IMultiSourceFrameReader* reader; // Kinect data source ...@@ -41,8 +47,42 @@ IMultiSourceFrameReader* reader; // Kinect data source
ICoordinateMapper* mapper; // Converts between depth, color, and 3d coordinates ICoordinateMapper* mapper; // Converts between depth, color, and 3d coordinates
SteamTracking* steamTracking = nullptr; SteamTracking* steamTracking = nullptr;
glm::mat3x4* currentControlerPos = nullptr;
static bool writeFile = false; static bool writeFile = false;
static bool captureFrame = false;
void drawArrow() {
//TETAEDRON BY HAND
glBegin(GL_TRIANGLES);
//front triangle
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
//right side triangle
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, -1.0f, -1.0f);
//left side triangle
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, -1.0f, -1.0f);
//bottom triangle
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(0.0f, -1.0f, -1.0f);
glEnd();
}
bool initKinect() { bool initKinect() {
if (FAILED(GetDefaultKinectSensor(&sensor))) { if (FAILED(GetDefaultKinectSensor(&sensor))) {
...@@ -132,6 +172,8 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) { ...@@ -132,6 +172,8 @@ void getRgbData(IMultiSourceFrame* frame, bool writFrameToFile) {
void getKinectData(bool writeFrameInVector) { void getKinectData(bool writeFrameInVector) {
IMultiSourceFrame* frame = NULL; IMultiSourceFrame* frame = NULL;
if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) { if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) {
delete currentControlerPos;
currentControlerPos = steamTracking->getTransformationForDevice(0);
if (writeFrameInVector) { if (writeFrameInVector) {
snapshotPoints.clear(); snapshotPoints.clear();
...@@ -151,10 +193,9 @@ void getKinectData(bool writeFrameInVector) { ...@@ -151,10 +193,9 @@ void getKinectData(bool writeFrameInVector) {
colors.reserve(colors.capacity() + width*height); colors.reserve(colors.capacity() + width*height);
for(int i = 0; i < width*height; i++) { for(int i = 0; i < width*height; i++) {
glm::mat3x4 transform = steamTracking->getTransformationForDevice(0);
points.push_back(transform * framePositions[i]); points.push_back(*currentControlerPos * framePositions[i]);
colors.push_back(frameColors[i]); colors.push_back(snapshotColors[i]);
} }
...@@ -203,23 +244,27 @@ void writePointCloud() { ...@@ -203,23 +244,27 @@ void writePointCloud() {
void rotateCamera() { void rotateCamera() {
static double angle = 0.; static double angle = 0.;
static double radius = 3.; static double radius = 4.;
double x = radius*sin(angle); double x = radius*sin(angle);
double z = radius*(1-cos(angle)) - radius/2; double z = radius*(1-cos(angle)) - radius/2;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //gluLookAt(x,0,z,0,0,radius/2,0,1,0);
gluLookAt(x,0,z,0,0,radius/2,0,1,0); angle += 0.002;
//angle += 0.002;
} }
void drawKinectData() { void drawKinectData() {
getKinectData(writeFile); getKinectData(captureFrame);
captureFrame = false;
if (writeFile) { if (writeFile) {
writePointCloud(); writePointCloud();
writeFile = false; writeFile = false;
} }
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
rotateCamera(); rotateCamera();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...@@ -235,6 +280,15 @@ void drawKinectData() { ...@@ -235,6 +280,15 @@ void drawKinectData() {
glPointSize(1.f); glPointSize(1.f);
glDrawArrays(GL_POINTS, 0, width*height); glDrawArrays(GL_POINTS, 0, width*height);
glPushMatrix();
float scale = 1.0 / 10;
glScalef(scale, scale, scale);
//drawArrow();
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glutSolidTeapot(1);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
...@@ -244,6 +298,9 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -244,6 +298,9 @@ void keyPressed(unsigned char key, int x, int y)
{ {
switch (key) { switch (key) {
case 'a': case 'a':
captureFrame = true;
break;
case 's':
writeFile = true; writeFile = true;
break; break;
default: default:
...@@ -254,6 +311,7 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -254,6 +311,7 @@ void keyPressed(unsigned char key, int x, int y)
instantly */ instantly */
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::cout << "Starting Kinect VR Point Cloud creator"; std::cout << "Starting Kinect VR Point Cloud creator";
if (!init(argc, argv)) return 1; if (!init(argc, argv)) return 1;
...@@ -282,6 +340,7 @@ int main(int argc, char* argv[]) { ...@@ -282,6 +340,7 @@ int main(int argc, char* argv[]) {
glBindBuffer(GL_ARRAY_BUFFER, cboId); glBindBuffer(GL_ARRAY_BUFFER, cboId);
glBufferData(GL_ARRAY_BUFFER, dataSize, 0, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, dataSize, 0, GL_DYNAMIC_DRAW);
// Camera setup // Camera setup
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment