• Advertisement
Sign in to follow this  

Rotate 3D Box Kinect

This topic is 2408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 B)
{

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

#ifdef USE_GLUT
glBegin(GL_QUADS);

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.

Share this post


Link to post
Share on other sites
Advertisement
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 B)
{

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

#ifdef USE_GLUT
glBegin(GL_QUADS);

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.

Share this post


Link to post
Share on other sites
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();
}


regards nomad

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement