Commit 9887b6bc by Adrian Hoppe

offset

parent 2004eaf1
......@@ -6,7 +6,7 @@
Camera::Camera() : Camera(vec3(10.0f, 5.0f, 0.0f))
Camera::Camera() : Camera(vec3(2.0f, 0.0f, 0.0f))
{
}
......
......@@ -16,7 +16,7 @@ private:
glm::vec3 position;
glm::vec3 up;
float speed = 0.3f;
float speed = 0.1f;
float mouseSpeed = 0.005f;
float horizontalAngle = (float) -M_PI/2;
......
......@@ -15,6 +15,7 @@
#include <glm/vec3.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "glm/gtc/matrix_transform.hpp"
#include <Kinect.h>
#include "Camera.h"
......@@ -57,8 +58,15 @@ std::vector<unsigned char> colors;
IKinectSensor* sensor; // Kinect sensor
IMultiSourceFrameReader* reader; // Kinect data source
ICoordinateMapper* mapper; // Converts between depth, color, and 3d coordinates
float KinectOriginOffsetX = ((92 + 73) / 2.0f) / 1000.0f;
float KinectOriginOffsetY = 21 / 1000.0f;
float KinectSizeX = 0.249;
float KinectSizeY = 0.066;
float KinectSizeZ = 0.067;
SteamTracking* steamTracking = nullptr;
int controllerID = 3;
glm::mat4x4* currentControlerPos = nullptr;
glm::mat4x4 controlerToKinect;
Camera mainCam;
......@@ -69,33 +77,64 @@ static bool captureFrame = false;
int lastX, lastY;
void drawArrow() {
void DrawCoordinateSystem() {
//TETAEDRON BY HAND
glBegin(GL_TRIANGLES);
glBegin(GL_LINES);
//front triangle
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.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);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.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);
glEnd();
}
void DrawKinect() {
glBegin(GL_QUADS);
//links 82, 5 mm ist origin(siehe bild kinect mesures), kinect v2 : 24, 9 cm x 6, 6 cm x 6, 7cm
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
//front
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.0f);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.0f);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
//back
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
//sides
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.0f);
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.0f);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
//top/bottom
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
glVertex3f(0.0f - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, KinectSizeY - KinectOriginOffsetY, 0.0f);
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.0f);
glVertex3f(0.0f - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, -KinectSizeZ);
glVertex3f(KinectSizeX - KinectOriginOffsetX, 0.0f - KinectOriginOffsetY, 0.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();
}
......@@ -288,8 +327,8 @@ void mainRenderLoop() {
//get controler pos
delete currentControlerPos;
currentControlerPos = steamTracking->getTransformationForDevice(1);
currentControlerPos = steamTracking->getTransformationForDevice(controllerID);
getKinectData();
//add points to point cloud
......@@ -313,51 +352,50 @@ void mainRenderLoop() {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//draw Grid
glLineWidth(1.f);
drawElementArray(gridData, GL_LINES);
//draw stored Point cloud
drawElementArray(exportData, GL_POINTS);
{ // Controller Space
glPushMatrix();
if (currentControlerPos) { //applay controler Transformation
glMultMatrixf(glm::value_ptr(*currentControlerPos));
}
glDisableClientState(GL_COLOR_ARRAY);
DrawCoordinateSystem();
glPushMatrix();
//draw current Frame
if (currentControlerPos) { //applay controler Transformation
glMultMatrixf(glm::value_ptr(controlerToKinect));
glMultMatrixf(glm::value_ptr(*currentControlerPos));
}
{// draw controller
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
glPointSize(1.f);
drawElementArray(framePoints, GL_POINTS);
glBindBuffer(GL_ARRAY_BUFFER, controllerData.vboID);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, controllerData.normals);
glNormalPointer(GL_FLOAT, 0, NULL);
// draw hud arrow
//glTranslatef(0.0f, 1.5f, 0.0f);
float scale = 0.1f ;
scale = 1.0f;
glScalef(scale, scale, scale);
// glRotatef(-90, 0.0, 1.0, 0.0);
glDrawElements(GL_TRIANGLES, controllerData.size, GL_UNSIGNED_SHORT, 0);
}
glDisableClientState(GL_COLOR_ARRAY);
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
{//Kinect Space
glPushMatrix();
glMultMatrixf(glm::value_ptr(controlerToKinect));
DrawCoordinateSystem();
glBindBuffer(GL_ARRAY_BUFFER, controllerData.vboID);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, controllerData.vboID);
glNormalPointer(GL_FLOAT, 0, NULL);
DrawKinect();
glDrawElements(GL_TRIANGLES, controllerData.size, GL_UNSIGNED_SHORT, 0);
//glDrawArrays(GL_TRIANGLES, 0, controllerData.size);
glEnableClientState(GL_COLOR_ARRAY);
//draw Frame Point cloud
glPointSize(1.f);
drawElementArray(framePoints, GL_POINTS);
//drawArrow();
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
//glutSolidTeapot(1);
glPopMatrix();
glPopMatrix();
}
glPopMatrix();
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
......@@ -407,6 +445,9 @@ void captureNextFrame(vr::VREvent_t event)
}
}
float degreeToRadioan(float degree) {
return degree*M_PI / 180.0;
}
int main(int argc, char* argv[]) {
std::cout << "Starting Kinect VR Point Cloud creator\n";
......@@ -451,7 +492,26 @@ int main(int argc, char* argv[]) {
//C:\Program Files (x86)\Steam\steamapps\common\SteamVR\resources\rendermodels\vr_controller_vive_1_5
//HKEY_CURRENT_USER/Software/Valve/SteamPath.
controlerToKinect = glm::translate(glm::mat4x4(), (glm::vec3(-4.0f, 4.0f, 12.0f)*0.01f));
controlerToKinect = glm::translate(glm::mat4x4(), (glm::vec3(-4.0f, -7.5f, 13.0f)*0.01f));
float dx = KinectOriginOffsetX - KinectSizeX/ 2;
float dy = KinectSizeY / 2 + 0.008; // dicke Halterung;
float dz = 0.0450f; //TODO - offset nach hinten;
controlerToKinect = glm::translate(glm::mat4x4(), (glm::vec3(0.0f, 0.0f, 0.24f)));
controlerToKinect = glm::rotate(controlerToKinect, degreeToRadioan(135.0f), glm::vec3(1.0f, 0.0f, 0.0f));
controlerToKinect = glm::rotate(controlerToKinect, degreeToRadioan(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));
controlerToKinect = glm::translate(controlerToKinect, (glm::vec3(dx, -dy, dz)));
std::cout << "Kinect to center: " << dx <<" "<< dy << " " << dz;
// x kinect mitte =
//
......@@ -463,6 +523,7 @@ int main(int argc, char* argv[]) {
loadAssImp("C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\resources\\rendermodels\\vr_controller_vive_1_5\\vr_controller_vive_1_5.obj", indices, out_vertices, out_uvs, out_normals);
glGenBuffers(1, &controllerData.vboID);
glBindBuffer(GL_ARRAY_BUFFER, controllerData.vboID);
glBufferData(GL_ARRAY_BUFFER, out_vertices.size() * sizeof(glm::vec3), &out_vertices[0], GL_STATIC_DRAW);
......@@ -567,103 +628,6 @@ void setupGrid()
}
}
void setupArrow() {
static GLfloat g_vertex_buffer_data[] = {
-1.0f,-1.0f,-1.0f, // triangle 1 : begin
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f, // triangle 1 : end
1.0f, 1.0f,-1.0f, // triangle 2 : begin
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f, // triangle 2 : end
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
static const GLfloat g_color_buffer_data[] = {
0.583f, 0.771f, 0.014f,
0.609f, 0.115f, 0.436f,
0.327f, 0.483f, 0.844f,
0.822f, 0.569f, 0.201f,
0.435f, 0.602f, 0.223f,
0.310f, 0.747f, 0.185f,
0.597f, 0.770f, 0.761f,
0.559f, 0.436f, 0.730f,
0.359f, 0.583f, 0.152f,
0.483f, 0.596f, 0.789f,
0.559f, 0.861f, 0.639f,
0.195f, 0.548f, 0.859f,
0.014f, 0.184f, 0.576f,
0.771f, 0.328f, 0.970f,
0.406f, 0.615f, 0.116f,
0.676f, 0.977f, 0.133f,
0.971f, 0.572f, 0.833f,
0.140f, 0.616f, 0.489f,
0.997f, 0.513f, 0.064f,
0.945f, 0.719f, 0.592f,
0.543f, 0.021f, 0.978f,
0.279f, 0.317f, 0.505f,
0.167f, 0.620f, 0.077f,
0.347f, 0.857f, 0.137f,
0.055f, 0.953f, 0.042f,
0.714f, 0.505f, 0.345f,
0.783f, 0.290f, 0.734f,
0.722f, 0.645f, 0.174f,
0.302f, 0.455f, 0.848f,
0.225f, 0.587f, 0.040f,
0.517f, 0.713f, 0.338f,
0.053f, 0.959f, 0.120f,
0.393f, 0.621f, 0.362f,
0.673f, 0.211f, 0.457f,
0.820f, 0.883f, 0.371f,
0.982f, 0.099f, 0.879f
};
std::vector<unsigned char> gridcolors;
for (int i = 0; i < 108; i++)
{
gridcolors.push_back((unsigned char)(g_color_buffer_data[i]*255));
}
glGenBuffers(1, &arrowData.vboID);
glBindBuffer(GL_ARRAY_BUFFER, gridData.vboID);
glBufferData(GL_ARRAY_BUFFER, 108* sizeof(float), g_vertex_buffer_data, GL_STATIC_DRAW);
glGenBuffers(1, &gridData.cboID);
glBindBuffer(GL_ARRAY_BUFFER, gridData.cboID);
glBufferData(GL_ARRAY_BUFFER, gridcolors.size() * sizeof(unsigned char), &gridcolors[0], GL_STATIC_DRAW);
arrowData.size = 108;
}
void close() {
delete steamTracking;
}
......
[InternetShortcut]
[InternetShortcut]
URL=https://social.msdn.microsoft.com/Forums/sqlserver/ja-JP/05a6d2b3-9096-4236-b77a-691c5f047066/kinect-for-windows-v2-?forum=windowsgeneraldevelopmentissuesja
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