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
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.
Rotate 3D Box Kinect
Solved! Thanks:)
I would like to do something more elaborate. But I'm not practical to OpenGL. Can I count on yours help?
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
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.
hi
i think you should do:
under linux and opengl and libfreenect
take the turns of your cube into a seperate functions aka:
regards nomad
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement