• Create Account

## Rotate 3D Box Kinect

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1zephyr87  Members

100
Like
0Likes
Like

Posted 02 February 2011 - 08:09 AM

Hi! I'm writing a code for to rotate a 3D Cube using Kinect.
I have already solved the problem of drawing to cube in a window and the recognition of the hand, but I can not rotate my cube.
I also have a point with three coordinates X, Y, Z (Z fixed to 0) that move along a circle. Should I use this reference for to rotate.
Everything must be done when it is drawn my cube and then executed in loop.
Here is my code

void DrawCube(const XnPoint3D& ptCenter, const XnPoint3D& ptMaxs, double r, double g, double
{

glColor4f(r,g,b,1.0f); //Scelta del colore

#ifdef USE_GLUT

glColor3f(1.0f, 0.0f, 0.0f);
// FRONT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// BACK
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);
// LEFT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
// RIGHT
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);
// TOP
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
// BOTTOM
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
//Ruoto
glRotatef(ptMaxs.X, 1.0f, 0.0f, 0.0f);
glRotatef(ptMaxs.Y, 0.0f, 1.0f, 0.0f);
glEnd();

#else
....

Thanks for the help.

### #2zephyr87  Members

100
Like
0Likes
Like

Posted 02 February 2011 - 08:12 AM

Solved! Thanks:)
I would like to do something more elaborate. But I'm not practical to OpenGL. Can I count on yours help?

Hi! I'm writing a code for to rotate a 3D Cube using Kinect.
I have already solved the problem of drawing to cube in a window and the recognition of the hand, but I can not rotate my cube.
I also have a point with three coordinates X, Y, Z (Z fixed to 0) that move along a circle. Should I use this reference for to rotate.
Everything must be done when it is drawn my cube and then executed in loop.
Here is my code

void DrawCube(const XnPoint3D& ptCenter, const XnPoint3D& ptMaxs, double r, double g, double
{

glColor4f(r,g,b,1.0f); //Scelta del colore

#ifdef USE_GLUT

glColor3f(1.0f, 0.0f, 0.0f);
// FRONT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// BACK
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);
// LEFT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
// RIGHT
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 0.0f, 1.0f);
// TOP
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
// BOTTOM
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
//Ruoto
glRotatef(ptMaxs.X, 1.0f, 0.0f, 0.0f);
glRotatef(ptMaxs.Y, 0.0f, 1.0f, 0.0f);
glEnd();

#else
....

Thanks for the help.

120
Like
0Likes
Like

Posted 20 June 2011 - 06:26 AM

hi
i think you should do:
under linux and opengl and libfreenect

take the turns of your cube into a seperate functions aka:

// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Save the matrix state and do the rotations
glPushMatrix();
// Move object back and do in place rotation
glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glRotatef(zRot, 0.0f, 0.0f, 1.0f);

// Draw something --> this your cube drawing
gltDrawUnitAxes();

// Restore the matrix state
glPopMatrix();

// Buffer swap
glutSwapBuffers();
}