Leap Motion development (2) OpenGL drawing hand position

Main函数代码 实现后待插入
文件名及文件路径在此写入 
并且在文件处ReadMe.txt里键入本篇文章的链接

Next, some points that need attention in the code are explained.

1. Problems with code configuration

The program includes the header files of GLutils and ExampleConnection, and the main functions are implemented in Main.cpp.
When configuring the environment, you need to include glew and glut, but there is always a link error (should be a lib problem) during configuration. Changing the x64 and x86 architectures of related files is invalid. Changing other glew libraries and including files still report this In the end, I changed to the glew in the OpenGL example folder provided by the teacher so that no error will be reported, but the window is black after the actual operation. Change the architecture to Debug Win32 and solve it.

2. Function Description

GLUT is used to realize the drawing and callback of windows and hand nodes. Draw the teapot in it and get the data of the hand joints. If the number of frame->nHands is greater than 0, draw the hand nodes of all hands. The nodes of each hand include arm node 2, palm node 1, and finger joints 5 4 , a total of 23 nodes.

3. About the callback function of GLUT

The callback functions used in the program include:

glutIdleFunc()  // 闲时回调函数,本代码中基本用不到
glutReShapeFunc()   //  允许窗口的改变,若无本回调函数,窗口无法移动、改变
glutKeyboardFunc()  // 键盘回调函数

And the most important callback function:

glutDisplayFunc(displayFunc)

The drawing of the main body is completed in this callback function. If you do not add a statement in the callback function displayFunc() glutPostRedisplay();, it will only be drawn once, and if you add it, the displayFunc() will be executed in a loop.

4. Coordinate conversion from IR170 to program

The coordinate system adopted by IR170 is the same as that of OpenGL, and the coordinates are 1:1 with the real space, and the unit is mm. For example, the joint point coordinates obtained by IR170 are (100, 100, 100), which means that the spatial position of the joint point is in (10cm, 10cm, 10cm) of the space where the IR170 is located.
In practical applications, the spatial range that IR170 can detect is about (-700, 0, -700) ~ (700, 700, 700), but the detection accuracy is actually lower at the edge.
OpenGL/Stereo IR 170 coordinate system
In actual application, the following figure is used for interaction: Please add a picture description
then the coordinates of IR170 become: Please add a picture description
then compared with the program coordinate system, the local space coordinates (x, y, z) detected by IR170 are marked as (x, -z,y). Additionally, the code uses

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(0, 0, -800); //"Camera" viewpoint
// Painting...
glPopMatrix();

Use GLTranslatef to move the model to the position (0, 0, -800) (positive outside the screen), then the model is placed at the Z axis -800, and the observation plane is equivalent to z=1 (set in gluPerspective()) , the closer the hand is to IR170, the smaller the palm.position.y, the smaller the displacement of the model's hand in the z-axis in the virtual space is palm.position.y, the farther away from the observation plane (z=1), the smaller the model . In this way, the closer the hand is to the IR170, the smaller the model's hand.
To achieve the effect that the closer the hand is to the IR170, the larger the model's hand, the local space coordinates (x, y, z) detected by the IR170 should be marked as (x, -z, 700-y) in the program coordinates.

Unresolved issues:

How to draw graphics at a specified position in space? done?
Doesn't the window scale affect the scale of the graph?
Is it better to have a bigger hand closer to the IR170, or a bigger hand farther away from the IR170?
How to get the bounding box of the model?
How to judge the relationship between the position of the hand and the position of the model? The palm position enters the bounding box of the model and the grabstrengh of the hand is >0.5?

Guess you like

Origin blog.csdn.net/qq_39006214/article/details/122313628