Commit dd34cf23 by wester

camera 2 and normals

parent 5668225e
Pipeline #272 passed with stage
in 19 seconds
...@@ -28,6 +28,7 @@ CameraSpacePoint depth2xyz[width*height]; // Maps depth pixels to 3d coordina ...@@ -28,6 +28,7 @@ CameraSpacePoint depth2xyz[width*height]; // Maps depth pixels to 3d coordina
//buffers of the current frame //buffers of the current frame
glm::vec3 framePositions[width*height]; glm::vec3 framePositions[width*height];
glm::vec3 frameNormals[width*height];
unsigned char frameColors[width*height * 3]; unsigned char frameColors[width*height * 3];
bool frameValidPoints[width*height]; bool frameValidPoints[width*height];
...@@ -63,7 +64,7 @@ std::vector<glm::vec3> controllerPositions; ...@@ -63,7 +64,7 @@ std::vector<glm::vec3> controllerPositions;
bool toggleCam = false;
Camera mainCam; Camera mainCam;
static bool trackControllerPos = true; static bool trackControllerPos = true;
...@@ -165,12 +166,34 @@ void getDepthData(IMultiSourceFrame* frame) { ...@@ -165,12 +166,34 @@ void getDepthData(IMultiSourceFrame* frame) {
unsigned int sz; unsigned int sz;
unsigned short* buf; unsigned short* buf;
depthframe->AccessUnderlyingBuffer(&sz, &buf); depthframe->AccessUnderlyingBuffer(&sz, &buf);
const unsigned short* curr = (const unsigned short*)buf;
// Write vertex coordinates // Write vertex coordinates
mapper->MapDepthFrameToCameraSpace(width*height, buf, width*height, depth2xyz); mapper->MapDepthFrameToCameraSpace(width*height, buf, width*height, depth2xyz);
for (unsigned int y = 0; y < height; y++)
{
for (unsigned int x = 0; x < width; x++)
{
unsigned int i = x + y* width;
framePositions[i] = glm::vec3(depth2xyz[i].X, depth2xyz[i].Y, depth2xyz[i].Z);
if (x > 0 && y > 0 && x < width - 1 && y < height - 1) {
float dzdx = ( curr[x + 1 + width* y] - curr[x - 1 + width* y]) / 2.0;
float dzdy = ( curr[x + width* (y+1)] - curr[x + width* (y - 1)]) / 2.0;
glm::vec3 d(-dzdx, -dzdy, 1.0f);
frameNormals[i] = normalize(d);
}
else {
frameNormals[i] = glm::vec3(0.0, 0.0, 1.0);
}
}
}
for (unsigned int i = 0; i < sz; i++) { for (unsigned int i = 0; i < sz; i++) {
framePositions[i] = glm::vec3(depth2xyz[i].X, depth2xyz[i].Y, depth2xyz[i].Z);
} }
// Fill in depth2rgb map // Fill in depth2rgb map
...@@ -206,19 +229,29 @@ void getRgbData(IMultiSourceFrame* frame) { ...@@ -206,19 +229,29 @@ void getRgbData(IMultiSourceFrame* frame) {
for (int i = 0; i < width*height; i++) { for (int i = 0; i < width*height; i++) {
ColorSpacePoint p = depth2rgb[i]; ColorSpacePoint p = depth2rgb[i];
// Check if color pixel coordinates are in bounds // Check if color pixel coordinates are in bounds
if (p.X < 0 || p.Y < 0 || p.X > colorwidth || p.Y > colorheight) { if (p.X < 1 || p.Y < 1 || p.X > colorwidth-1 || p.Y > colorheight-1) {
*fdest++ = 255; *fdest++ = 255;
*fdest++ = 0; *fdest++ = 0;
*fdest++ = 0; *fdest++ = 0;
*fvalid++ = false; *fvalid++ = false;
} }
else { else {
if (depth2xyz[i].Z > maxTrackingKinect || depth2xyz[i].Z < minTrackingKinect) { if (depth2xyz[i].Z > maxTrackingKinect || depth2xyz[i].Z < minTrackingKinect) {
*fdest++ = 0; *fdest++ = 0;
*fdest++ = 255; *fdest++ = 255;
*fdest++ = 0; *fdest++ = 0;
*fvalid++ = false; *fvalid++ = false;
continue;
}
float angle = dot(frameNormals[i], glm::vec3(0.0, 0.0, 1.0));
if (angle < 0.1) {
*fdest++ = 0;
*fdest++ = 0;
*fdest++ = 255;
*fvalid++ = false;
} }
else { else {
int idx = (int)p.X + colorwidth*(int)p.Y; int idx = (int)p.X + colorwidth*(int)p.Y;
...@@ -406,7 +439,15 @@ void mainRenderLoop() { ...@@ -406,7 +439,15 @@ void mainRenderLoop() {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
//rotateCamera(); //todo //rotateCamera(); //todo
mainCam.applyMatrix(); if (toggleCam && trackControllerPos) {
glMultMatrixf(glm::value_ptr(*currentControlerPos));
glMultMatrixf(glm::value_ptr(controlerToKinect));
glRotatef(180.0, 0.0, 0.0, 1.0);
}
else {
mainCam.applyMatrix();
}
//glTranslatef(0.0, 5, 0.0); //glTranslatef(0.0, 5, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...@@ -493,6 +534,9 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -493,6 +534,9 @@ void keyPressed(unsigned char key, int x, int y)
colors.clear(); colors.clear();
exportData.size = 0; exportData.size = 0;
break; break;
case 'q':
toggleCam = !toggleCam;
break;
case 27: // Escape key case 27: // Escape key
exit(0); exit(0);
break; break;
......
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